25

I'm attempting my first NuGet package, and I'm running into some trouble. I have a fairly simple project, and a very simple .nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <description>$description$</description>
  </metadata>
</package>

When I run NuGet pack with this command line:

NuGet.exe pack mylibrary.csproj -Verbosity detailed -Properties Configuration=Debug

I get this error:

NuGet.CommandLineException: Unable to find '@(_OutputPathItem->'%(FullPath)mylibrary.dll')'. Make sure the project has been built.
   at NuGet.Commands.ProjectFactory.BuildProject()
   at NuGet.Commands.ProjectFactory.CreateBuilder(String basePath)
   at NuGet.Commands.PackCommand.BuildFromProjectFile(String path)
   at NuGet.Commands.PackCommand.BuildPackage(String path)
   at NuGet.Commands.PackCommand.ExecuteCommand()
   at NuGet.Commands.Command.Execute()
   at NuGet.Program.Main(String[] args)

The output files are definitely in the bin\Debug folder, but NuGet is apparently not finding them.

This apparently only happens when the .csproj file's ToolsVersion is set to 3.5 or lower. Setting ToolsVersion to 4.0 resolves the problem.

It seems that MSBuild 3.5 returns the unexpanded property value when calling _project.GetPropertyValue("TargetPath") (ProjectFactory.cs ~296), where MSBuild 4.0 returns the expanded property value.

Mark
  • 11,257
  • 11
  • 61
  • 97

3 Answers3

58

We had the same problem. adding

-Prop Platform=AnyCPU

to the command line made it work for us.

llewellyn falco
  • 2,281
  • 16
  • 13
  • 3
    Is there any way to make this work from the nuspec, without needing to specify this from the command line? – Richard Rout Jul 08 '15 at 20:26
  • We use an HP port replicator with our laptops that sets a system environment variable `PLATFORM` to `BNB`. See [Why is my Platform environment variable defined as 'BNB'?](http://stackoverflow.com/questions/2507856/why-is-my-platform-environment-variable-defined-as-bnb). – Chris Oldwood Jun 07 '16 at 10:36
  • 2
    In the latest version of (2.7), it seems like -Prop is now called -Properties. For me a working example would be: nuget pack my.csproj -Properties "Platform=AnyCpu;version=1.0;configuration=Debug" – Emil G Dec 12 '16 at 08:41
  • 3
    One more syntax to share: `-Prop Platform=x86 -Prop Configuration=Release` – Vimes Jun 15 '17 at 17:37
1

This apparently only happens when the .csproj file's ToolsVersion is set to 3.5 or lower. Setting ToolsVersion to 4.0 resolves the problem.

I have created an issue for the NuGet project team here: https://nuget.codeplex.com/workitem/4012

Mark
  • 11,257
  • 11
  • 61
  • 97
0

This could also have the same error if the .NET Framework version is set to 4.0 for the assembly.

StingyJack
  • 19,041
  • 10
  • 63
  • 122