mjrousos / CppCliMigrationSample

Simple demonstration of C++/CLI on .NET Core
16 stars 10 forks source link

Microsoft.NuGet.Targets error #4

Open JLopez99 opened 3 years ago

JLopez99 commented 3 years ago

Using Visual Studio 2019 (16.10.3) I get this error:


  Using "ResolveNuGetPackageAssets" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.Build.Tasks.dll".
  Task "ResolveNuGetPackageAssets"
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.targets(198,5): error : Your project does not reference ".NETCoreApp,Version=v3.1" framework. Add a reference to ".NETCoreApp,Version=v3.1" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
  Done executing task "ResolveNuGetPackageAssets" -- FAILED.
Done building target "ResolveNuGetPackageAssets" in project "CppCliInterop.vcxproj" -- FAILED.```
jparsaie-qc commented 2 months ago

Seeing something similar for net9.0:

C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : Your project does not reference ".NETCoreApp,Version=v9.0" framework. Add a ref
erence to ".NETCoreApp,Version=v9.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore. [C:\Development\NativeCallManaged\Managed\build\Interop.vcxproj]

Something feels broken here @mjrousos.

CMakeLists:

# Configure the Interop Target
# ----------------------------------------
# ----------------------------------------

add_library(Interop SHARED Source/Interop.cpp)

# Enable C++/CLR support for mixed-mode. 

# See: https://learn.microsoft.com/en-us/dotnet/core/porting/cpp-cli
target_compile_options(Interop PRIVATE /clr:netcore)

# Link with the managed target.
target_link_libraries(Interop Managed)

# Make sure to use the latest .NET
set_target_properties(Interop PROPERTIES DOTNET_TARGET_FRAMEWORK "net9.0") 
jparsaie-qc commented 2 months ago

A bit more precision, the build is successful if it's the only target produced by CMake. But there seems to be some kind of collision going on in the \build\obj directory between the C++/CLI target and the C# managed target. It might be more of a build system issue with CMake itself, perhaps, or maybe MSBuild.