是否有某种方法可以使用在发布模式下编译的代码来制作 NuGet 包?或者是否有某种原因我应该只发布(在本例中为本地可用)在调试模式下编译的包?
每次我从项目目录(下面有 nuspec 文件)调用
nuget pack
时,在我仅在发布模式下编译的代码上,它都会抱怨在调试文件夹中找不到 DLL ("\bin\Debug\SomeProject.dll"
)。如果我在调试模式下编译它,这些文件就在那里,并且它会按应有的方式打包它们。
<?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>
如果您正在使用构建后事件,并且想要创建包,无论是使用调试还是发布配置,您都可以像这样设置构建后事件命令行:
"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
要让 NuGet 在运行
nuget pack
时自动使用发布模式,请执行以下操作:
.csproj
文件。找到以下行:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Debug
替换为 Release
。这里的答案很好,但我在 .NET Standard 项目中遇到了很多问题。我有一个项目只打算发布发布二进制文件,但它不尊重我的默认构建输出路径。
我将其添加到我的 CSProj 中,然后我就可以使用接受的答案here。
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
在这里插话。 我的构建配置文件会将 DLL 构建为
bin\<arch>\Debug|Release
。
我可以通过运行 nuget
命令来指向我的文件夹,如下所示:
请注意我如何使用 -p
选项。
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...
如果您遇到以下错误
Nuget.exe : Error NU5049: The `pack` command for SDK-style projects is not supported,
use `dotnet pack` or `msbuild -t:pack` to pack this project instead.
You can override this behavior by setting the 'NUGET_ENABLE_LEGACY_CSPROJ_PACK'
environment variable to 'true'.
以下对我有用
dotnet msbuild .\YourProject.csproj -p:Configuration=Release -t:pack