Incompatibility between install and VS_PACKAGE_REFERENCES
I have a C++/CLI project which consumes some .NET libraries provided by Nuget packages fetched with VS_PACKAGE_REFERENCES
. (I had to have an intermediate C# project in there, too, otherwise they weren't picked up, but my understanding is that that's because of an unimplemented feature on Microsoft's end.) When doing the Nuget restore as part of the build, this trips up over the install target, giving the specific error message
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.targets(186,5): error : Your project does not reference ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
If the error happens, it fails to fetch new packages for any of the projects in the solution, not just INSTALL
.
The same error initially also happened with ZERO_CHECK
and ALL_BUILD
, but setting CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION
globally (instead of DOTNET_TARGET_FRAMEWORK_VERSION
as target properties on the things that actually used .NET) resolved that. This is mentioned as a possible problem and solution on https://cmake.org/cmake/help/latest/variable/CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION.html#variable:CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION.
I can work around this by manually adding the property to the created project file after CMake has generated it (either in a text editor or through its property pages), but obviously that's not something you're supposed to do with CMake-generated build systems.
If VS_PACKAGE_REFERENCES
isn't used anywhere, I don't believe Nuget attempts to restore packages for any of the projects in the solution, and the install target works fine.