Skip to content

Restore fails when .NET Framework Project depends on C++ CLI project #10511

Closed

Description

@snthomae

Details about Problem

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

  1. Create a new .NET Framework Project.
  2. Create a new C++ CLI Project.
  3. Edit .NET Framework Project and add a ProjectReference to C++ CLI Project (should have same TargetFramework as .NET Framework Project).
  4. Edit C++ CLI Project and add a PackageReference (e.g. Newtonsoft.Json).
  5. Open Visual Studio 2019 Development Shell.
  6. 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)

Activity

  1. 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
  2. nkolev92 commented on Feb 5, 2021

    @nkolev92
    Member

    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.

  3. added
    Resolution:ByDesign
    Resolution:NotABug
    WaitingForCustomer
    on Feb 5, 2021
  4. snthomae commented on Feb 5, 2021

    @snthomae
    Author

    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.

  5. nkolev92 commented on Feb 5, 2021

    @nkolev92
    Member

    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.

  6. snthomae commented on Feb 11, 2021

    @snthomae
    Author

    Hi @nkolev92 ,

    sorry for delayed answer.
    Please find Test Project attached.

    NuGetExample.zip

  7. nkolev92 commented on Feb 11, 2021

    @nkolev92
    Member

    Hey @snthomae

    Trying it out with NuGet.exe I wasn't able to repro it (note that NuGet.exe carries the same bits).

    C:\Users\Roki2\Downloads\NuGetExample [master]> C:\Programs\NuGet\nuget-5.8.0.exe restore                                                                                                                                                    MSBuild auto-detection: using msbuild version '16.9.0.63002' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin'.
    Restoring packages for C:\Users\Roki2\Downloads\NuGetExample\CppProject\CppProject.vcxproj...
    Restoring packages for 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)
    Committing restore...
    Installing boost 1.71.0.0.
    Generating MSBuild file C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\obj\DotNetProject.csproj.nuget.g.props.
    Generating MSBuild file C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\obj\DotNetProject.csproj.nuget.g.targets.
    Writing assets file to disk. Path: C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\obj\project.assets.json
    Failed to restore C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\DotNetProject.csproj (in 269 ms).
    Committing restore...
    Generating MSBuild file C:\Users\Roki2\Downloads\NuGetExample\CppProject\obj\CppProject.vcxproj.nuget.g.props.
    Generating MSBuild file C:\Users\Roki2\Downloads\NuGetExample\CppProject\obj\CppProject.vcxproj.nuget.g.targets.
    Writing assets file to disk. Path: C:\Users\Roki2\Downloads\NuGetExample\CppProject\obj\project.assets.json
    Restored C:\Users\Roki2\Downloads\NuGetExample\CppProject\CppProject.vcxproj (in 19.44 sec).
    
    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)
    
    NuGet Config files used:
        C:\Users\Roki2\Downloads\NuGetExample\NuGet.Config
        C:\Users\Roki2\AppData\Roaming\NuGet\NuGet.Config
        C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
        C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
        C:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config
    
    Feeds used:
        C:\Users\Roki2\Downloads\NuGetExample\.nuget
    
    Installed:
        1 package(s) to C:\Users\Roki2\Downloads\NuGetExample\CppProject\CppProject.vcxproj
    C:\Users\Roki2\Downloads\NuGetExample [master +3 ~0 -0 !]>                                                                                                                                                                                   C:\Users\Roki2\Downloads\NuGetExample [master +3 ~0 -0 !]> C:\Programs\NuGet\nuget-5.7.0.exe restore                                                                                                                                         MSBuild auto-detection: using msbuild version '16.9.0.63002' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin'.
    Committing restore...
    Assets file has not changed. Skipping assets file writing. Path: C:\Users\Roki2\Downloads\NuGetExample\CppProject\obj\project.assets.json
    Restored C:\Users\Roki2\Downloads\NuGetExample\CppProject\CppProject.vcxproj (in 54 ms).
    Restoring packages for 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)
    Committing restore...
    Generating MSBuild file C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\obj\DotNetProject.csproj.nuget.g.props.
    Assets file has not changed. Skipping assets file writing. Path: C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\obj\project.assets.json
    Failed to restore C:\Users\Roki2\Downloads\NuGetExample\DotNetProject\DotNetProject.csproj (in 274 ms).
    
    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)
    
    NuGet Config files used:
        C:\Users\Roki2\Downloads\NuGetExample\NuGet.Config
        C:\Users\Roki2\AppData\Roaming\NuGet\NuGet.Config
        C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
        C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
        C:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config
    
    Feeds used:
        C:\Users\Roki2\Downloads\NuGetExample\.nuget
    1 of 2 projects are up-to-date for restore.
    C:\Users\Roki2\Downloads\NuGetExample [master +3 ~0 -0 !]> 

    cc @zivkan who's the handling incoming issues this week.

  8. snthomae commented on Feb 12, 2021

    @snthomae
    Author

    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.

  9. nkolev92 commented on Feb 12, 2021

    @nkolev92
    Member

    @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.

  10. 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
  11. snthomae commented on Feb 12, 2021

    @snthomae
    Author

    @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)

  12. nkolev92 commented on Feb 12, 2021

    @nkolev92
    Member

    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 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.

  13. removed
    Resolution:NotABug
    WaitingForCustomer
    on Feb 12, 2021
  14. jarig commented on Apr 15, 2022

    @jarig

    @lorenz-haenggi-jarowa can you please share your condition or remove in the Directory.Build.Props?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions