Unable to BuildPackage from VS2012 (20X?) exited with code 1

Topics: General
Dec 10, 2012 at 4:40 PM

Hello,

I would like to enable building packages automatically during our build process but am running an error when doing so:

  • <BuildPackage>true</BuildPackage> in our CSPROJ global <PropertyGroup/>.

Error    1    An item with the same key has already been added.    My Project

Error    2    The command ""C:\Source\Me\project-structure\.nuget\nuget.exe" pack "C:\source\Me\project-structure\My Project\My Project.csproj" -p Configuration=Debug -o "C:\source\Me\my-project\My Project\bin\Debug" -symbols" exited with code 1.    My Project

When I run the same type thing from the command line: nuget.exe pack ".\My Project.csproj" the NUPKG is generated just fine.

This is a solution with some tests which depend on the NuGet-ified package, so plausible guess is that the project is building twice, so the NuGet targets are processing twice?

Would be great if we could get our build CI/CD pipeline flowing seamlessly. Is there NuGet a workaround for this? Or how might we workaround it otherwise?

Thanks...

Dec 10, 2012 at 5:02 PM
Edited Dec 10, 2012 at 5:02 PM

Well, I'm not sure this is what you want, but it's possible to IgnoreExitCode in the BuildPackage Target: I have line 93 and 96 of the NuGet.targets:

 

    <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
        <Exec Command="$(BuildCommand)"
              Condition=" '$(OS)' != 'Windows_NT' " IgnoreExitCode="true" />
             
        <Exec Command="$(BuildCommand)"
              LogStandardErrorAsError="true"
              Condition=" '$(OS)' == 'Windows_NT' " IgnoreExitCode="true" />
    </Target>

Of course if it fails then potentially you can't tell whether there's a false positive or false negative.

Thoughts? Anyone else encountered this hooking up CI processes?

Thanks...

Feb 21, 2014 at 12:50 AM
This problem is caused by TFS changing the $(TargetDir) location to something other than what it normally is on your desktop. When "nuget pack" is given your csproj file, it will try to find the generated assembly by producing a $(TargetDir) that does not match what TFS was using. As a consequence, you will get a "file not found" (an error that appears earlier in the log, but you did not include in your post). At the same time, the "nuget pack" will give an "exited with code 1."

To solve this problem you must modify your nuget.targets file. The <BuildCommand> definition needs to have an additional "OutDir" property added:
-Properties "Configuration=$(Configuration);Platform=$(Platform);OutDir=$(PackageOutputDir)"
That setting will work for both your local build and on TFS.