I have a Visual Studio solution with multiple projects. There is one single csproj for every version of .NET Framework (+ .NET Core) I want to support, and I want to keep it that way. They all generate one DLL each. All DLLs are named the same but are slightly different.
I've recently started generating NuGet packages out of these DLLs using a nuspec file and the command nuget pack
. So far, I've generated one NuGet package for each DLL.
Would it be possible to generate one single NuGet package, that contains all the DLLs, and when a user installs the package, installs the right DLL?
I tried the following in my nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
...
<dependencies>
<group targetFramework=".NETCoreApp3.1" />
<group targetFramework=".NETFramework4.0" />
</dependencies>
</metadata>
<files>
<file src="bin\Company.Product.dll" target="lib\net40" />
<file src="..\CompanyProductCore\bin\Company.Product.dll" target="lib\netcoreapp3.1" />
</files>
</package>
When I look in the generated NuGet package, there are the two expected subfolders in the lib folder, and they each contain a DLL which looks right.
However, when I test the package and try to install it in another Visual Studio solution on a .NET Core App project, I get the warning:
Package X was restored using '.NETFramework,Version=v4.6.1...4.6.2...4.7...4.7.1...4.7.2...4.8 instead of the project target framework '.NetCoreApp,Version=3.1'. This package may not be fully compatible with your project.
which is something that did not appear when I packed it separately. So it would seem that it didn't detect that there was a .NET Core-specific DLL given.
Is what I want to do possible, and if so, how?