打包以发布模式编译的NuGet项目?

问题描述 投票:0回答:6

是否有某种方法可以使用在发布模式下编译的代码来制作 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>
nuget
6个回答
234
投票

你可以这样解决:

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

参考


18
投票

如果您正在使用构建后事件,并且想要创建包,无论是使用调试还是发布配置,您都可以像这样设置构建后事件命令行:

"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)

13
投票

要让 NuGet 在运行

nuget pack
时自动使用发布模式,请执行以下操作:

  1. 在文本编辑器中打开您的
    .csproj
    文件。
  2. 找到以下行:

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    
  3. 在此行中,将
    Debug
    替换为
    Release
  4. 保存更改。

2
投票

这里的答案很好,但我在 .NET Standard 项目中遇到了很多问题。我有一个项目只打算发布发布二进制文件,但它不尊重我的默认构建输出路径。

我将其添加到我的 CSProj 中,然后我就可以使用接受的答案here

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
      <OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>

0
投票

在这里插话。 我的构建配置文件会将 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...

0
投票

如果您遇到以下错误

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
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.