CMake to generate C# project and compile it
Hi All,
I am using CMake for C# project. I am compiling with target framework as netstandard2.0.
Following is the issue I am encountering when compiling the project using CMake.
Severity Code Description Project File Line Suppression State Details
Error NU1202 Package abc.xyz 23.2.347.1 is not compatible with net40 (.NETFramework,Version=v4.0). Package abc.xyz 23.2.347.1 supports: net48 (.NETFramework,Version=v4.8)
What could be the reason for this when I am targetting for .netstandard2.0? This nuget package abc.xyz is also supported on the .netstandard2.0, then what is exactly the problem ?
What could be the reason for this when I am targetting for .netstandard2.0? This nuget package abc.xyz is also supported on the .netstandard2.0, then what is exactly the problem ?
18 Replies
what package
This package for now renamed to "abc.xyz" has both support of .netframework 4.8 and .netstandard2.0
unnecessary hiding detail only makes harder for someone to help
The package is internal to our company, so it cant be shared. Its a nuget package internally used in company.
The issue is occurring for many other packages as well which support .netstandard2.0 . It seems some issue with csproj file generated that its going to find some other non required version like net40 for the package targets. Not sure where its getting this net40 from
Wha are you using CMake and not MSBuild?
Does the error happen when you compile normally with VS /
dotnet
/ msbuild? Or is it something cmake-specific?I have a mix of C++ and C# projects in my solution which I wanted to build cross platform Linux and Windows. This is the reason to use CMake.
If I use msbuild directly , it works fine. I have used WSL for C++ compilation as well for Linux using MSBuild. However, not been able to make it work with CMake. CMake could give me a single way to have the files listed and projects created automatically during runtime and able to build it cross platform. CMake also triggers msbuild while building and when its at the first step of determining projects to restore, we get this error. It seems the msbuild that gets triggered through CMake is using the Csproj file for finding the dependencies. Not sure why its looking for .NET4.0 version of those dependencies when the target framework specified is .Netstandard2.0.
Right, so the issue is something to do with cmake, not msbuild. You haven't shared any of the details of how you've configured cmake, so it's impossible for us to help
This is the CMakeLists.txt file
I have attached the CMakeLists.txt and CMakeSettings.json file
Why are you trying to set the package references from cmake?
How do I set the nuget package references otherwise when I want to build the C# project using CMake?
Can you see the generated csproj?
yes I see the generated csproj successfully but the build is failing because of the above errors I mentioned
Can you post the generated csproj?
The csproj generated has following entry. Not sure how and where this entry is getting added from
<Compile Include="C:\Users\xxxx\source\repos\abcde\xyzc\src\MRC\MRCDNC\out\build\x64-Debug\obj\x64\Debug.NETFramework,Version=v4.0.AssemblyAttributes.cs">
<Link>out\build\x64-Debug\obj\x64\Debug.NETFramework,Version=v4.0.AssemblyAttributes.cs</Link>
</Compile>
Right, I think that shows that this is firmly in the realms of CMake -- nothing to do with any of the .NET tooling.
You should probably ask CMake, e.g. on https://discourse.cmake.org