[英]automatically generate nuget package with symbols on build
I have a C# project (.net 6.0) from which I want to automatically create a nuget whenever I (re-)build it.我有一个 C# 项目(.net 6.0),我想在我(重新)构建它时自动创建一个 nuget。
To automatically run
dotnet pack
when you rundotnet build
, add the following line to your project file within<PropertyGroup>
:要在运行dotnet build
时自动运行dotnet pack
,请将以下行添加到<PropertyGroup>
内的项目文件中:<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
I tried it and it works, but, no symbols ( .pdb
files) are added.我试过了,它可以工作,但是没有添加任何符号( .pdb
文件)。 How can I do this?我怎样才能做到这一点?
The command dotnet pack --include-symbols
can be used for that, but how do I tell the .csproj
file to use that command instead of dotnet pack
?命令dotnet pack --include-symbols
可以用于此,但我如何告诉.csproj
文件使用该命令而不是dotnet pack
?
dotnet pack --include-symbols
will generate two nuget packages, one ending with .nupkg
and one with .symbols.nupkg
. dotnet pack --include-symbols
将生成两个 nuget 包,一个以.nupkg
结尾,一个以.symbols.nupkg
。 The former does not contain the .pdb
, the latter does.前者不包含.pdb
,后者包含。 I want just one file generated (the .nupkg
one without .symbols
prefix) which contains both .dll
and .pdb
.我只想要一个包含.dll
和.pdb
的文件(没有.symbols
前缀的.nupkg
文件)。
I tried the following:我尝试了以下方法:
GeneratePackageOnBuild
property删除GeneratePackageOnBuild
属性<Target Name="BuildNuget" AfterTargets="AfterBuild"><Exec Command="dotnet pack --include-symbols"/></Target>
将目标添加到项目: <Target Name="BuildNuget" AfterTargets="AfterBuild"><Exec Command="dotnet pack --include-symbols"/></Target>
But now when I run dotnet build
, I run into an infinite loop: (Unfortunately it's German, but you can see it just repeats.)但是现在当我运行dotnet build
时,我遇到了一个无限循环:(不幸的是它是德语,但你可以看到它只是重复。)
Wiederherzustellende Projekte werden ermittelt... Alle Projekte sind für die Wiederherstellung auf dem neuesten Stand. MyProject-> C:\Users\...\MyProject\bin\Debug\net6.0-windows\MyProject.dll Microsoft (R)-Build-Engine, Version 17.0.0+c9eb9dd64 für .NET Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. Wiederherzustellende Projekte werden ermittelt... Alle Projekte sind für die Wiederherstellung auf dem neuesten Stand. MyProject-> C:\Users\...\MyProject\bin\Debug\net6.0-windows\MyProject.dll Microsoft (R)-Build-Engine, Version 17.0.0+c9eb9dd64 für .NET Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. Wiederherzustellende Projekte werden ermittelt... Alle Projekte sind für die Wiederherstellung auf dem neuesten Stand. MyProject-> C:\Users\...\MyProject\bin\Debug\net6.0-windows\MyProject.dll Microsoft (R)-Build-Engine, Version 17.0.0+c9eb9dd64 für .NET Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. Wiederherzustellende Projekte werden ermittelt...
The dotnet pack command builds the project and creates NuGet packages. dotnet pack 命令构建项目并创建 NuGet 包。
So if I have dotnet pack
as a command after build, I will just get into an infinite build stack.因此,如果我在构建后将dotnet pack
作为命令,我将进入一个无限的构建堆栈。 On the same page the options for nuget pack
are listed.在同一页面上列出了nuget pack
的选项。 One of them is --no-build
.其中之一是--no-build
。
Changing the target to将目标更改为
<Target Name="BuildNuget" AfterTargets="AfterBuild">
<Exec Command="dotnet pack --no-build --include-symbols"/>
</Target>
solves the issue.解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.