3

Visual Studio makes creating NuGet packages easier these days by automating the process of creating the .nuspec file. It means that version dependencies etc. are automatically created and you can simply set up the textual values here:

enter image description here

So, most of the work is already done by the time the NuGet package is built. However, there are external assemblies that I need to add to the .nuspec file before it is built. I know I can add external files in the files collection of the outputted .nuspec file (in obj\Release):

enter image description here

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? 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...

Christian Findlay
  • 6,770
  • 5
  • 51
  • 103
  • Do you already reference these files in your project file? The idea is that the unspecified creation is extensible via MSBuild code in the csproj file – Martin Ullrich Mar 30 '19 at 22:37
  • No. They are the output of other assemblies that depend on this project. I would prefer to extend with MSBuild code, but I guess this is the question that I'm asking really. I ended up writing a powershell script to perform the whole clean and build process. It's pretty nasty because I'm not good with powershell, but it does the job. https://github.com/MelbourneDeveloper/Device.Net/blob/master/Build/Build.ps1 . I'm still looking for better ideas though. – Christian Findlay Mar 30 '19 at 23:09

1 Answers1

3

You could use Pack element in csproj file: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#including-content-in-a-package

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:

package content

This way you can add whatever you like to your library.

Peska
  • 3,980
  • 3
  • 23
  • 40