I have an existing C# project which is targetted for .net48 and .netstandard2.0. It works fine when I compile it separately. I had to work on moving this project to CMake based project and I am encountering issues of the project containing references to compile tag with .NET Framework. This results in problems where finally, when the build starts for the generated csproj file from CMake, I get into errors mentioning some of the referenced packages are unavailable for .net40. Example CMakeLists.txt file:
cmake_minimum_required(VERSION 3.29)
project(MyProjectDNC CSharp)
# Add your C# source files
file(GLOB_RECURSE CS_FILES "*.cs")
add_library(MyProjectDNC SHARED ${CS_FILES})
set_target_properties(MyProjectDNC PROPERTIES
DOTNET_TARGET_FRAMEWORK "netstandard2.0"
)
set_target_properties(MyProjectDNC PROPERTIES
COMPILE_DEFINITIONS "TRACE;;NETSTANDARD;NETSTANDARD2_0"
)
set_property(TARGET MyProjectD
PROPERTY VS_PACKAGE_REFERENCES "abc.xyz_23.2.*;Microsoft.Windows.Compatibility_2.0.1;pqr.lmn_23.2.*;Newtonsoft.Json_13.0.1;System.Configuration.ConfigurationManager_4.7.0;System.Threading.Channels_7.0.0"
)
Generated csproj file contains the targetframework part correct:
<ProjectName>MyProject </ProjectName>
<TargetFramework>netstandard2.0</TargetFramework>
But it contains following strange lines:
<Compile Include="C:\Users\abc\source\repos\MyController\src\MyProject\MyProjectDNC\out\build\x64-Debug\CMakeFiles\3.29.3\CompilerIdCSharp\obj\x64\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs">
<Link>out\build\x64-Debug\CMakeFiles\3.29.3\CompilerIdCSharp\obj\x64\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs</Link>
</Compile>
<Compile Include="C:\Users\abc\source\repos\MyController\src\MyProject\MyProjectDNC\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>
Following are the error seen in building the complete project:
C:\Users\abc\source\repos\MyController\src\MyProject\MyProjectDNC\out\build\x64-Debug\MyProjectDNC.csproj : 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)
C:\Users\abc\source\repos\MyController\src\MyProject\MyProjectDNC\out\build\x64-Debug\MyProjectDNC.csproj : error NU1202: Package pqr.lmn 23.2.347.1 is not compatible with net40 (.NETFramework,Version=v4.0). Package pqr.lmn 23.2.347.1 supports: net48 (.NETFramework,Version=v4.8)
Any help on this is much appreciated.