2

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?

gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • Actually, what I want to ask is how can I add .NET Framework support to a package that only supports .NET Core. – Omer Huseyin GUL Jun 12 '22 at 22:08
  • Target .net standard – Daniel A. White Jun 12 '22 at 22:23
  • You could also compile it multiple times. Then include both assemblies in the package – Daniel A. White Jun 12 '22 at 22:25
  • Add .NET Framework to targets. Possibly add some conditional compilation directives. – Guru Stron Jun 12 '22 at 22:25
  • 1
    [some docs](https://learn.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file) to start. – Guru Stron Jun 12 '22 at 22:27
  • Instead of using `` in your csproj, you need to update it to `` and as others have said, include a `netstandard2.0` target alongside .net 6. There are tremendous benefits to multi-target compilation, especially when targeting later .net versions like .net 6, due to so many core libraries having native sdk support. As a result, you need fewer nuget packages if you do some conditional compilation and your .net 6 target version WILL see better performance overall. – David L Jun 12 '22 at 23:30

1 Answers1

2

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://learn.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.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • It sounds like this would work; however, when I click project properties, under Target Framework, the only choices in the dropdown are .NET 5, .NET 6, and various versions of .NET Core. I also tried changing the target OS to Windows, that did not help. So how do I change the target framework to Standard? I should add, I do have .net 4.7x, 4.8x installed... – Jay Imerman Nov 29 '22 at 14:04
  • @JayImerman edit the csproj file directly. – gunr2171 Nov 29 '22 at 14:05