Packing NuGet projects compiled in release mode?
NugetNuget 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
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:
-
Open your
.csproj
file in a text editor. -
Find the following line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-
In this line, replace
Debug
withRelease
. -
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...