简体   繁体   English

如何在Visual Studio中的NuGet包之前修改.nuspec文件

[英]How to modify .nuspec file before NuGet pack in Visual Studio

Visual Studio makes creating NuGet packages easier these days by automating the process of creating the .nuspec file. 最近,Visual Studio通过自动创建.nuspec文件的过程,使创建NuGet包变得更加容易。 It means that version dependencies etc. are automatically created and you can simply set up the textual values here: 这意味着将自动创建版本依赖性等,您可以在此处简单地设置文本值:

在此处输入图片说明

So, most of the work is already done by the time the NuGet package is built. 因此,在构建NuGet包时,大多数工作已经完成。 However, there are external assemblies that I need to add to the .nuspec file before it is built. 但是,在构建.nuspec文件之前,我需要添加一些外部程序集。 I know I can add external files in the files collection of the outputted .nuspec file (in obj\\Release): 我知道我可以在输出的.nuspec文件的文件集合中添加外部文件(在obj \\ Release中):

在此处输入图片说明

My question is, what build event or otherwise should I use to edit the .nuspec after it is created, but before the pack command is called by msbuild or Visual Studio? 我的问题是,在创建.nuspec之后但在msbuild或Visual Studio调用pack命令之前,应该使用什么生成事件来编辑.nuspec? Or, should I just run a separate build process afterwards? 或者,此后我应该只运行一个单独的构建过程吗?

Note: a bonus would be to find a tool which I can call that will add the files collection. 注意:一个额外的好处是找到一个我可以调用的工具,它将添加文件集合。 Without that, I'm guessing I will need to write powershell code to add the files... 没有这个,我想我将需要编写powershell代码来添加文件...

You could use Pack element in csproj file: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#including-content-in-a-package 您可以在csproj文件中使用Pack元素: https : csproj

Add something like this to your project: 在您的项目中添加以下内容:

<ItemGroup>
  <Content Pack="True"
           PackagePath="lib\netcoreapp2.2"
           Include="C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All\2.1.2\Microsoft.AI.DependencyCollector.dll" />
</ItemGroup>

This will add a Microsoft.AI.DependencyCollector.dll library to your package: 这会将Microsoft.AI.DependencyCollector.dll库添加到您的包中:

包装内容

This way you can add whatever you like to your library. 这样,您可以将自己喜欢的任何内容添加到库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM