Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a Nuget package as part of my CI process and when building locally?

I know that this question has been asked before, but the answers that I have found have not worked for me for some reason.

Please let me describe my problem.

I'm using Visual Studio 2012 and TFS 2012

In my organization, we have several applications and some of them expose shared DLL's and we want to publish them as Nuget packages in a private Nuget server

So in one of the projects I added the following code to the csproj file

  <Target Name="AfterBuild">
    <Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration=&quot;$(Configuration)&quot;;Platform=&quot;$(Platform)&quot;" />
  </Target>

At the same level than my project file I have the nuspec file representing my Nuget metadata and it looks like:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Super dooper cool framework</releaseNotes>
    <copyright>$copyright$</copyright>
    <tags>Some My Company framework</tags>
  </metadata>
</package>

This works really nice locally, every time I build my project it creates a Nuget package for me the way I want it.

But on the build server it doesn't work, I've tried several combinations and I keep receiving the same error:

     "D:\Builds\23\someCompany\somebuilddefinition\Sources\.nuget\nuget.exe" pack "D:\Builds\23\someCompany\somebuilddefinition\Sources\NugetLibrary\NugetLibrary.csproj" -Exclude "*.nlp" -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration="Release";Platform="AnyCPU"
     Attempting to build package from 'NugetLibrary.csproj'.
     NuGet.CommandLineException: Unable to find 'D:\Builds\23\someCompany\somebuilddefinition\Sources\NugetLibrary\bin\Release\NugetLibrary.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)

And that's understandable because on the build server, the output path is overridden and it's pointing to:

D:\Builds\23\someCompany\somebuilddefinition\Binaries

So I have tried several combinations, but I cannot find a way to force Nuget to use my custom path to find the DLL's generated by the build process.

These are the combinations I have tried so far:

(Basically I've played with the following Nuget properties: OutputDirectory, BasePath and Properties)

BTW the $(OutDir) MSBuild property points to the correct folder on the build server

<Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -Properties Configuration=&quot;$(Configuration)&quot;;Platform=&quot;$(Platform)&quot;" />

<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath &quot;$(OutDir)&quot; -OutputDirectory &quot;$(OutDir)&quot;" />

<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -OutputDirectory &quot;$(OutDir)&quot;" />

<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath &quot;$(OutDir)&quot; -OutputDirectory &quot;$(OutDir)&quot;" />

<Exec ContinueOnError="false" WorkingDirectory="$(ProjectDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes -BasePath &quot;$(OutDir)&quot; -OutputDirectory &quot;$(OutDir)&quot; -Properties Configuration=&quot;$(Configuration)&quot;;Platform=&quot;$(Platform)&quot;" />

<Exec ContinueOnError="false" WorkingDirectory="$(OutDir)" Command="&quot;$(SolutionDir).nuget\nuget.exe&quot; pack &quot;$(ProjectPath)&quot; -Exclude &quot;*.nlp&quot; -IncludeReferencedProjects -NonInteractive -Verbosity detailed -NoDefaultExcludes" />

And I keep receiving the same error:

     NuGet.CommandLineException: Unable to find 'D:\Builds\23\somecompany\somebuildserver\Sources\NugetLibrary\bin\Release\NugetLibrary.dll'. Make sure the project has been built.

So is Nuget just ignoring the BasePath property? Why? What am I missing?

like image 813
Jupaol Avatar asked May 22 '13 22:05

Jupaol


2 Answers

It looks like you might be running into http://nuget.codeplex.com/workitem/1486. Based on the comments on the issue, it looks like adding -Properties OutDir=$(OutDir) to your pack command might fix it.

like image 126
Jesse Sweetland Avatar answered Nov 01 '22 12:11

Jesse Sweetland


You may want to give my personal project http://nuproj.codeplex.com/ a try. It allows creating NuGet packages via MSBuild.

like image 44
Immo Landwerth Avatar answered Nov 01 '22 11:11

Immo Landwerth