Nuget Package: Project Reference Mutli Runtime Targeting
Hey Folks,
I have a nuget package that wraps an exe, which I need to run on both linux and windows. I was trying to set it up so when I build my nuget package it compiles the other project reference and generates two executables. Altought what I have works it seems a bit hacky. I was wondering if there was a cleaner way of going about this
6 Replies
i think this is the incorrect way of going about this
what you want is a build task, not to put a .NET application in your nuget package. the build task lets you integrate whatever C# code you want into the build, and all you need to distribute for it is one DLL, not an entire .NET runtime per platform
there is an example of writing a build task here https://learn.microsoft.com/en-us/visualstudio/msbuild/tutorial-custom-task-code-generation?view=vs-2022
I have written msbuild tasks before but we use the same CLI tools locally as well. So this gives us the best of both worlds. A simlar example is GitVersion.Tool which is pretty popular.
whatever the solution is, including two self-contained builds in your nuget package is not the correct one
i would strongly prefer figuring out how to use it as a library, and if that doesn't work out for some reason, then i would just bundle the CLI application as a portable framework-dependent build (not self-contained)
then you can run it as
dotnet MyCli.dll
, which will work on any platform, and it will not make your NuGet package huge
this is what GitVersion.MsBuild appears to doThey bundle 4 versions inside their package haha. I can skip the self contained, that is a good point.
Each of the targets has one, I am unsure why they need so many.
Anyway thanks for the pointers 🙂