2

If I understand Scott Hanselman's post here correctly then I should be able to reference a .net standard library from a framework 4.7.2 solution.

I want to use Nuget to install such a reference.

I am using Azure DevOps Artifacts for the Nuget package. When I push my .net standard solution I can see that the package does create and that the Nuget install command is

Install-Package SBD.Standard -version 2.0.0-CI-etc

However when I try this at the PM console for my framework 4.7.2 project I get

Could not install package 'SBD.Standard 2.0.0-etc'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework

moreover I do not see SBD.Standard as an avialable package in the relevant feed from within VS2019 -> Manage nuget packages for solution.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • studying https://learn.microsoft.com/en-us/dotnet/standard/net-standard?WT.mc_id=-blog-scottha – Kirsten Feb 08 '20 at 01:56
  • https://weblog.west-wind.com/posts/2019/Feb/19/Using-NET-Standard-with-Full-Framework-NET – Kirsten Feb 08 '20 at 02:37
  • https://stackoverflow.com/questions/46788323/installing-a-netstandard-2-0-nuget-package-into-a-vs2015-net-4-6-1-project?rq=1 – Kirsten Feb 08 '20 at 02:53
  • https://stackoverflow.com/questions/60178092/could-not-load-file-or-assembly-microsoft-data-sqlclient – Kirsten Feb 12 '20 at 17:22

2 Answers2

0

I think I need packages.config

I was able to create a new 4.7.2 project and add the nuget package that used .net standard 2.0 (but not 2.1)

When I tried to add the nuget package I got a dialog asking me to select the Nuget package manager format

dialog

so I chose Packages.config and that worked.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • Thanks for your posting here and sharing the resolution in the forum as it would be helpful to anyone who encounters similar issues. – Leo Liu Feb 10 '20 at 06:51
  • I am not sure I have it right. I solved my problem but am not sure whether this was it after all. SInce PackageReference is more recent it should work. – Kirsten Feb 10 '20 at 17:49
  • I have give an answer for the reason for the solution, hope this helps you clear the reason for this issue. – Leo Liu Feb 12 '20 at 10:51
  • 1
    Actually, I found it is important to use PackageReference. https://stackoverflow.com/questions/60199981/reference-hell-accessing-netstandard-with-framework-vs2019-preview – Kirsten Feb 13 '20 at 03:26
0

I am not sure I have it right. I solved my problem but am not sure whether this was it after all. SInce PackageReference is more recent it should work.

Some additional explanations for this issue.

There is an issue for NuGet restore when you using new SDK-based project type or PackageReference in the .net framework:

https://github.com/NuGet/Home/issues/5461

https://github.com/dotnet/sdk/issues/1755

When we use packages.config projects or non-SDK based project type, NuGet do not check compatibility during install/restore.

So, to resolve this issue, we need make sure the referenced project is an old style csproj or use packages.config.

That the reason why the packages.config works for you.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • In your link to issue 5461 there is a standard app referencing a framework library. I have it the other way around. A framework app referencing a standard library. – Kirsten Feb 12 '20 at 17:27