2

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?

5
  • Ah, why do you come up with your own names for the target frameworks and still expect it to work? Try using the strings given in the documentation. Commented Mar 20, 2020 at 11:27
  • Why not use dotnet pack, and let the command auto-generate the correct nuspec automatically? Commented Mar 20, 2020 at 16:52
  • TomTom I didn't know I was supposed to write it differently, I must have misinterpreted some example I saw somewhere. As mentioned in the answer given by weichchm I tried to change it but it didn't help. Commented Mar 23, 2020 at 6:35
  • zivkan dotnet pack does seem like a good choice for .NET Core projects, but not necessarily .NET Framework projects, if I understood it correctly. But I'll try to see if I can get it to work. Commented Mar 23, 2020 at 6:53
  • zivkan I tried it and my .NET Core project successfully ran the command, but my .NET Framework 4.0 project gives me the error message that the Target "pack" doesn't exist in the project, and I'm unable to find what such a target tag should contain. Commented Mar 23, 2020 at 7:06

1 Answer 1

1

Your target frameworks should be net40 and netcoreapp3.1.

<dependencies>
      <group targetFramework="netcoreapp3.1" />
      <group targetFramework="net40" />
</dependencies>

https://learn.microsoft.com/en-us/dotnet/standard/frameworks

Sign up to request clarification or add additional context in comments.

10 Comments

Thank you! This was probably an issue, so I changed it, but changing this had no effect on the original problem.
@Helena Interestingly I tried your nuspec file and installed the generated nuget package into a .net core 3.1 app, and it worked. If you view the content of the nuspec file inside the generated nupkg file, does it contain multiple targets?
It does, but for some reason that nuspec file has them on the original format that I posted in my question. <dependencies> <group targetFramework=".NETCoreApp3.1" /> <group targetFramework=".NETFramework4.0" /> </dependencies>
@Helena Mine is also like what you posted (which is new to me as well), but it works for me, weird.
Very interesting. Thanks for testing. If I unpack the NuGet package with 7-zip and add a reference to the DLL that is present in the lib folder directly, instead of adding the package with NuGet package manager, I get no erors.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.