128

Is there some way to make a NuGet package using code compiled in release mode? Or is there some reason I should only publish (make available locally, in this case) packages compiled in debug mode?

Every time I call nuget pack from my project directory, where I have the nuspec file below, on code I have only compiled in release mode, it complains about not finding the DLL in the debug folder ("\bin\Debug\SomeProject.dll"). If I compile it in debug mode, those files are there and it packs them up as it should.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <authors>$author$</authors>
        <owners>$author$</owners>
        <iconUrl>http://somewhere/project.png</iconUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$description$</description>
    </metadata>
</package>
patridge
  • 26,385
  • 18
  • 89
  • 135

5 Answers5

233

You can solve it like this:

NuGet.exe pack Foo.csproj -Prop Configuration=Release

(reference)

Pang
  • 9,564
  • 146
  • 81
  • 122
Giorgi
  • 30,270
  • 13
  • 89
  • 125
  • 11
    For anyone who wants the short story from the link (good read, though), there was a change from v1.3 to v1.4 that goes from a default of Release to a default pulled from a project setting that can only be modified in the project file directly (no VS GUI option). To avoid the command-line property tweak for all future `nuget pack` calls, edit the project file XML in your favorite text editor. – patridge Jun 30 '11 at 22:07
  • 4
    Is there a way to package up both a Release and Debug version in one package and then have my project auto-use the Debug one vs. the Release one depending on if I'm in Debug vs. Release Solution configuration? – J.D. Jul 11 '11 at 01:51
  • @JD: As far as I know it is not possible but I was thinking contributing that to nuget. Can you explain in which scenario would you need this feature? When will it be helpful? – Giorgi Jul 11 '11 at 07:09
  • 2
    If you simply want debug symbols for your package, you could either include your PDB files in the *.nuspec (e.g., ``) or [publish a symbols package](http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-symbol-package) alongside your DLL package. – patridge Jul 14 '11 at 18:20
  • 1
    @J.D. I also want to package both Debug and Release,and I have found this: https://stackoverflow.com/questions/37673692/how-to-create-a-nuget-package-with-both-release-and-debug-dlls-using-nuget-pack – Peter-Yu Sep 09 '19 at 08:17
19

If you are using a post-build event and you want to create a package whether using Debug or Release configuration you can setup the post-build event commandline like so:

"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
EnderWiggin
  • 525
  • 6
  • 7
13

To have NuGet automatically use Release mode when you run nuget pack, do the following:

  1. Open your .csproj file in a text editor.
  2. Find the following line:

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    
  3. In this line, replace Debug with Release.
  4. Save changes.
Sam
  • 40,644
  • 36
  • 176
  • 219
2

The answers here are good, but I was having a lot of problems with this for a .NET Standard project. I had a project that was only going to publish Release binaries, but it wasn't respecting my default build output path.

I added this to my CSProj which then enabled me to use the accepted answer here.

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
      <OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
Pang
  • 9,564
  • 146
  • 81
  • 122
kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80
0

Chiming in here. My build profile would build the DLLs to bin\<arch>\Debug|Release. I was able to point to my folders by running the nuget command as follows: Notice how I used the -p option.

PS > nuget pack -p Configuration="x64\Release"

Attempting to build package from ...
...

Found packages.config. Using packages listed as dependencies
...
- Add a dependency group for .NETFramework4.7.2 to the nuspec
Successfully created package...
Razique
  • 131
  • 4