Home > Enterprise >  How do I support both .Net 6 and .Net Framwork 4.7.2 with my nuget package
How do I support both .Net 6 and .Net Framwork 4.7.2 with my nuget package

Time:06-13

I'm creating a class library project that is packaged to Nuget.org (Nuget Github). Right now when I create the nuget package the only runtime it supports is .Net 6.

I need it to also support .Net Framework 4.7.2 as well for use in a WinForms application.

How do I fix this?

CodePudding user response:

Change your class library to target .Net Standard. Ideally .Net Standard 2.0 as that's the highest version of .Net Standard that .Net Framework 4.7.2 supports.

https://docs.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0

You don't say right now how you create the nuget package, but if it's with dotnet pack then the resulting nupkg file should have the correct target runtime once you switch your project file over. If you have a nuspec file then just adjust the folder where files are copied to.

CodePudding user response:

You have to dispose the client with "using" statement:

    using var webClient = new WebClient();
    var data = webClient.DownloadData(url);
    if (data.Length == 0)
       throw new Exception($"Invalid file in {url}");

CodePudding user response:

You can't use legacy .Net Framework code from .Net Core (which is what 6 is). Either use a different NuGet package, or just code your own. Looking at the code in that library, it's barely worth the name "library", it's just a few WMI queries which you can do yourself.

  • Related