Packing NuGet projects compiled in release mode?

Nuget

Nuget Problem Overview


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>

Nuget Solutions


Solution 1 - Nuget

You can solve it like this:

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

(reference)

Solution 2 - Nuget

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)

Solution 3 - Nuget

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.

Solution 4 - Nuget

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>

Solution 5 - Nuget

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...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpatridgeView Question on Stackoverflow
Solution 1 - NugetGiorgiView Answer on Stackoverflow
Solution 2 - NugetEnderWigginView Answer on Stackoverflow
Solution 3 - NugetSamView Answer on Stackoverflow
Solution 4 - NugetkayleeFrye_onDeckView Answer on Stackoverflow
Solution 5 - NugetRaziqueView Answer on Stackoverflow