You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restore fails when .NET Framework Project depends on C++ CLI project #10511
After upgrading to Visual Studio 16.8 (which integrates NuGet 5.8.1), restore is failing when .NET Framework project is referencing a C++ CLI Project via ProjectReferences. Also setting a TargetFramework Version in C++ Project has no impact.
C++ Project is always treated as Target Framework 'Native' which seems not to be compatible to any .NET Framework Project.
NuGet product used (NuGet.exe | Visual Studio | MSBuild.exe | dotnet.exe):
Visual Studio Version 16.8.4.
MSBuild 16.8.3.61104
NuGet 5.8.1
Worked before? If so, with which NuGet version:
Worked before with Visual Studio 16.7.X and NuGet 5.7.0.
Repro steps and/or sample project
Create a new .NET Framework Project.
Create a new C++ CLI Project.
Edit .NET Framework Project and add a ProjectReference to C++ CLI Project (should have same TargetFramework as .NET Framework Project).
Edit C++ CLI Project and add a PackageReference (e.g. Newtonsoft.Json).
Open Visual Studio 2019 Development Shell.
Call 'msbuild /t:restore' on .NET Framework Project.
Verbose Logs
Checking compatibility for NativeProjectExample with .NETFramework,Version=v4.8.
<PATH>DotNetExample.csproj : error NU1201: Project NativeProjectExample is not compatible with net48 (.NETFramework,Version=v4.8). Project NativeProjectExample supports: native (native,Version=v0.0)
changed the title [-]Restore fails when .NET Framework Project reference Native project[/-][+]Restore fails when .NET Framework Project depends on Native project[/+]on Feb 1, 2021
Even when it's not supported, PackageReference is working with native projects. At least calling nuget restore with NuGet Client 5.8.4 on native project is restoring the PackageReferences as expected.
Problem just comes up when there is a ProjectReference between a .NET and Native Project and restore is called on the .NET project.
This just comes up with NuGet Client 5.8.4 whereas same scenario is working with NuGet Client 5.7.0.
So there must be a change added to NuGet between these version that defines the incompatibility between .NET and Native Projects.
Therefore, I would appreciate if you can share some information about this change.
Even when it's not supported, PackageReference is working with native projects. At least calling nuget restore with NuGet Client 5.8.4 on native project is restoring the PackageReferences as expected.
Due to the nature of MSBuild, the tooling cannot block every unsupported scenario.
PackageReference is 2 parts, one is restore the other side is build. Even if the restore side might seem to work, the build side is not implemented right now.
Problem just comes up when there is a ProjectReference between a .NET and Native Project and restore is called on the .NET project.
In the scenario described, the .NET project is not PackageReference. The error suggests that the project is PackageReference.
I'd expect restore to fail with vcxproj because a package such as newtonsoft.json does not support native.
This just comes up with NuGet Client 5.8.4 whereas same scenario is working with NuGet Client 5.7.0.
Can you please upload a project? Following the instructions I just get a failure when vcxproj is restore (which is expected).
So there must be a change added to NuGet between these version that defines the incompatibility between .NET and Native Projects.
Note that even if the behavior did change, this is still an unsupported scenario and we might not be able to change the new behavior.
but you were able to reproduce it - you are getting exactly same NU1201 error as mentioned: Errors in C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\DotNetProject.csproj NU1201: Project CppProject is not compatible with net48 (.NETFramework,Version=v4.8). Project CppProject supports: native (native,Version=v0.0)
This error doesn't come up when you do a restore with nuget version < 5.8.X.
changed the title [-]Restore fails when .NET Framework Project depends on Native project[/-][+]Restore fails when .NET Framework Project depends on C++ CLI project[/+]on Feb 12, 2021
@nkolev92
Sorry, I've uploaded the wrong Test Project (TargetFramework property was missing in C++ project).
Please can you retry it again with following sample: NuGetExample.zip
Result with NuGet 5.7.0: Checking compatibility for boost 1.71.0.0 with .NETFramework,Version=v4.8.
Result with NuGet 5.8.X: Checking compatibility for CppProject 1.0.0 with .NETFramework,Version=v4.8. NU1201: Project CppProject is not compatible with net48 (.NETFramework,Version=v4.8). Project CppProject supports: native (native,Version=v0.0)
Unfortunately, this is exactly where we get in the unsupported scenario.
Prior to 5.8 (and .NET Core 5.0), NuGet and the dotnet SDK were incorrectly handling the TargetFramework inference.
They were using TargetFrameworks instead of TargetFrameworkMoniker. For vcxproj, NuGet just assumes native. The TargetFrameworks property took precedence, which was incorrect.
When frameworks of the net5.0-windows were introduced in .NET 5, NuGet and the SDK needed to fix this longstanding inconsistency.
You can read more about these issues: #9756 and #8388.
You can add another hack on top of your current behavior by adding <AssetTargetFallback>$(AssetTargetFallback);native</AssetTargetFallback>.
Unfortunately at this point, we can't commit to making any changes. NuGet does not have support for vcxproj projects & AssetTargetFallback is the big hammer to workaround 2 things being incompatible.
Activity
[-]Restore fails when .NET Framework Project reference Native project[/-][+]Restore fails when .NET Framework Project depends on Native project[/+]nkolev92 commentedon Feb 5, 2021
Hey @snthomae
PackageReference is not supported for native projects. Tracked here: #8874.
Note that the NuGet team does not have absolute control here, so issues like that are best filled on developer community.
snthomae commentedon Feb 5, 2021
Hey @nkolev92,
thank you for the reply.
Even when it's not supported, PackageReference is working with native projects. At least calling nuget restore with NuGet Client 5.8.4 on native project is restoring the PackageReferences as expected.
Problem just comes up when there is a ProjectReference between a .NET and Native Project and restore is called on the .NET project.
This just comes up with NuGet Client 5.8.4 whereas same scenario is working with NuGet Client 5.7.0.
So there must be a change added to NuGet between these version that defines the incompatibility between .NET and Native Projects.
Therefore, I would appreciate if you can share some information about this change.
nkolev92 commentedon Feb 5, 2021
Due to the nature of MSBuild, the tooling cannot block every unsupported scenario.
PackageReference is 2 parts, one is restore the other side is build. Even if the restore side might seem to work, the build side is not implemented right now.
In the scenario described, the .NET project is not PackageReference. The error suggests that the project is PackageReference.
I'd expect restore to fail with vcxproj because a package such as newtonsoft.json does not support native.
Can you please upload a project? Following the instructions I just get a failure when vcxproj is restore (which is expected).
Note that even if the behavior did change, this is still an unsupported scenario and we might not be able to change the new behavior.
snthomae commentedon Feb 11, 2021
Hi @nkolev92 ,
sorry for delayed answer.
Please find Test Project attached.
NuGetExample.zip
nkolev92 commentedon Feb 11, 2021
Hey @snthomae
Trying it out with NuGet.exe I wasn't able to repro it (note that NuGet.exe carries the same bits).
cc @zivkan who's the handling incoming issues this week.
snthomae commentedon Feb 12, 2021
Hey @nkolev92
but you were able to reproduce it - you are getting exactly same NU1201 error as mentioned:
Errors in C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\DotNetProject.csproj NU1201: Project CppProject is not compatible with net48 (.NETFramework,Version=v4.8). Project CppProject supports: native (native,Version=v0.0)This error doesn't come up when you do a restore with nuget version < 5.8.X.
nkolev92 commentedon Feb 12, 2021
@snthomae
If you look at my logs again you will see that I ran the same thing with 5.7.0 and got the same result.
The indentation is messed up but search for
nuget-5.7.0.exe.[-]Restore fails when .NET Framework Project depends on Native project[/-][+]Restore fails when .NET Framework Project depends on C++ CLI project[/+]snthomae commentedon Feb 12, 2021
@nkolev92
Sorry, I've uploaded the wrong Test Project (TargetFramework property was missing in C++ project).
Please can you retry it again with following sample:
NuGetExample.zip
Result with NuGet 5.7.0:
Checking compatibility for boost 1.71.0.0 with .NETFramework,Version=v4.8.Result with NuGet 5.8.X:
Checking compatibility for CppProject 1.0.0 with .NETFramework,Version=v4.8. NU1201: Project CppProject is not compatible with net48 (.NETFramework,Version=v4.8). Project CppProject supports: native (native,Version=v0.0)nkolev92 commentedon Feb 12, 2021
Thanks for clarifying. I can repro the behavior.
Unfortunately, this is exactly where we get in the unsupported scenario.
Prior to 5.8 (and .NET Core 5.0), NuGet and the dotnet SDK were incorrectly handling the TargetFramework inference.
They were using
TargetFrameworksinstead ofTargetFrameworkMoniker. For vcxproj, NuGet just assumes native. TheTargetFrameworksproperty took precedence, which was incorrect.When frameworks of the net5.0-windows were introduced in .NET 5, NuGet and the SDK needed to fix this longstanding inconsistency.
You can read more about these issues: #9756 and #8388.
You can add another hack on top of your current behavior by adding
<AssetTargetFallback>$(AssetTargetFallback);native</AssetTargetFallback>.Unfortunately at this point, we can't commit to making any changes. NuGet does not have support for vcxproj projects & AssetTargetFallback is the big hammer to workaround 2 things being incompatible.
jarig commentedon Apr 15, 2022
@lorenz-haenggi-jarowa can you please share your condition or remove in the Directory.Build.Props?