1
votes

I've been googling around a while, but failed to find a proper answer.

My project contains two libraries:

LibA - .NET standard 2.0

LibB - .NET Framework 4.7, which contains some nuget package

I'm referencing (via Project ref) LibB from LibA (i.e. my goal is to use LibB from LibA). Everything works well if LibB uses packages.config file, but nuget restore fails once I turn to package references in LibB csproj. It gives NU1201, saying that

Project LibB is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project LibB supports: net47 (.NETFramework,Version=v4.7)

Is there any known workaround or this is a VS bug or it just works as designed (I've heard packages.config way skips compatibility check during restore).

1
The error message suggests that LibA is referencing LibB which is not supported. A .NET Standard 2.0 project cannot reference a .NET Framework project. A .NET Standard 2.0 project can reference a NuGet package that only supports .NET Framework, or a library assembly (not a project) due to a compatibility mode.Matt Ward
Also it seems that it should be possible for a .NET Standard 2.0 project to reference a .NET Framework 4.6.1 project but no version higher than 4.6.1 - github.com/dotnet/sdk/issues/1755Matt Ward
@MattWard Why you say I cannot reference this way? It's allowed and supported youtube.com/watch?v=vg6nR7hS2lI&feature=youtu.be&t=173 Changing target from 4.7 to 4.6.1 (and also to earlier versions) gives no difference. It's only a matter of packages.config vs packages referencesMisza
@MattWard So you say I should never reference Framework library via project reference? Why it's allowed by IDE then and what the difference is? As long as I use packages.config my project runs perfectly fine.Misza
I get the same behaviour as you with Visual Studio 2017. I would file this on github.com/nuget/home/issues and see what the NuGet team say. At the same time if you have a .NET Standard 2.0 project on its own it can install a NuGet package which targets .NET Framework only, you do get a warning about this.Matt Ward

1 Answers

1
votes

Nuget restore fails (NU1201) for .NET Standard referencing .NET Framework

Yes, it just works as designed. 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 restore.

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

Hope this helps.