0

I want create nuget package and publish to our package repository. But this package must install on projects with diferrent target framework. There are .Net Framework and Core 2.0 projects where this package need to be installed.

Should there be several projects for different target frameworks or one single project may be configured for different target frameworks?

I am using Visual Studio 15.5.0 (if this fact is important)

Dimitry
  • 217
  • 4
  • 15
  • 2
    create .net standard 2.0 package – Yahya Hussein Jan 19 '18 at 14:45
  • As @YahyaHussein said, this is precisely what .NET Standard is for. Take a look at my answer to a different question [here](https://stackoverflow.com/a/47359253/1143474) for lots of links and details. – Jamie Taylor Jan 19 '18 at 14:47
  • here you can find a detailed answer mentioning how to determine package version https://stackoverflow.com/questions/33177632/which-net-versions-should-be-supported-by-nuget-packages-to-maximize-their-avai/48242746#48242746 – Yahya Hussein Jan 19 '18 at 14:48
  • @YahyaHussein, I have created .net standard 2.0 package, but when I try to install it for the project on .Net Framework I have next error: "Could not install package 'TestNuget 1.0.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author" – Dimitry Jan 19 '18 at 15:20
  • @Dimitry take a look at the [.NET Standard compatibility table](https://github.com/dotnet/standard/blob/master/docs/versions.md). The versions of .NET Standard are labelled across the top of the table, and the versions of .NET that they support are shown in the columns. .NET Standard 2.0 is only supported on .NET Framework 4.6.1 and above. I would recommend upping the version of .NET Framework that your project is targetting, if possible. – Jamie Taylor Jan 19 '18 at 15:25
  • please take a look at the answer I mentioned in comments, to use .Net standard 2.0 you have to upgrade your projects to .net framework 4.6.1 – Yahya Hussein Jan 19 '18 at 15:29
  • @JamieTaylor, this works. Bu what if i want support net framework 4.5, 4.5.1, 4.5.2 etc? I have dowloaded project EPPlus and there I see this: https://snag.gy/cYesu3.jpg. I need something like this – Dimitry Jan 19 '18 at 16:46
  • As others have stated, this cannot be done because .NET Standard does not support those versions of .NET Framework. It's possible that you could create two separate NuGet packages (one for .NET Core and one for .NET Framework), but that would be two separate code bases to manage. You will need to upgrade to .NET Framework 4.6.1 if you want to use .NET Standard 2.0 – Jamie Taylor Jan 19 '18 at 18:05
  • @JamieTaylor, but how author of EPPlus did this? There is one single project in solution. – Dimitry Jan 20 '18 at 10:24
  • It was quite easy. It is needed to add appropriate property in cproj file: https://snag.gy/qQnz5e.jpg – Dimitry Jan 20 '18 at 10:53

0 Answers0