2

I am using the csproj property <GeneratePackageOnBuild> to generate a NuGet package from my netstandard2.0 C# project.

I would like to make 2 modifications to the generated package

  1. Change the id to rename the package
  2. Add an additional .dll to the .nupkg

The only way I could figure out to accomplish that was to add a custom .nuspec file to my project, and add <NuspecFile> to the .csproj.

This works fine, but I'm missing some features from the auto-generated NuGet package, like repository binding to my git commit. It also feels less resilient to change.

Is there any way I can modify the SDK build process to get the auto-generated NuGet package, but with my 2 changes?

Kevin Kostrzewa
  • 193
  • 1
  • 9
  • 1
    [Here's an explanation](https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-an-icon-image-file) of how to add a file to your package through msbuild – Pieterjan Mar 17 '23 at 18:33
  • 1
    And you can add your own target to alter your nuspec file `` or smth like that – Pieterjan Mar 17 '23 at 18:37
  • The .dll I want to add is generated by a `ProjectReference`'d project. I tried adding `IncludeAssets` after I removed my .nuspec, but the .dll isn't added to the generated .nupkg. You've given me some good stuff to try, though, so thanks very much. – Kevin Kostrzewa Mar 17 '23 at 19:07
  • And, if this doesn't work, I can always lean on adding a custom target to xslt the auto generated .nuspec file – Kevin Kostrzewa Mar 17 '23 at 19:07

1 Answers1

2

Thanks to @Pieterjan, I found the right answer.

Including referenced project DLLs in nuget package [.Net Core RC3 *.csproj file]

pointed me to

https://github.com/nuget/home/issues/3891#issuecomment-377319939

so I was able to

  1. Rename the PackageId property in a <Target Name="MyProj_RenamePackageId" BeforeTargets="GenerateNuspec"
  2. Follow the steps of issue 3891 above to add the referenced project .dll to the produced .nupkg
Kevin Kostrzewa
  • 193
  • 1
  • 9