I’m creating this post today because I’m wondering how to generate a netcoreapp3.1 project with CMake. I have seen some examples online (for net framework 4.7.2) mentionning this
set(CMAKE_DOTNET_TARGET_FRAMEWORK “netcoreapp3.1”)
but it did not work. The TargetFramework does not appear on my csproj file and when I compile, it complains that some packages I am using are not compatible with net40 and that they’re supporting net45, netcoreapp2.1, netcoreapp3.1 and netstandard2.0.
Here is the full CMake file (I have only one, it’s a very small project)
cmake_minimum_required(VERSION 3.17)
project(AutoMaxLairUI LANGUAGES CSharp)
# Include CMake utilities for CSharp, for WinForm and WPF application support.
include(CSharpUtilities)
# Define the executable, including any .cs files.
add_executable(AutoMaxLairUI
Form1.cs
Form1.Designer.cs
Form1.resx
Program.cs
README.txt
)
# Set the .NET Framework version for the executable.
# set_property(TARGET AutoMaxLairUI PROPERTY DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
# set_property(TARGET AutoMaxLairUI PROPERTY DOTNET_TARGET_FRAMEWORK "netcoreapp3.1")
# set(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set(CMAKE_DOTNET_TARGET_FRAMEWORK "netcoreapp3.1")
# Set the executable to be 32-bit.
set_property(TARGET AutoMaxLairUI PROPERTY WIN32_EXECUTABLE TRUE)
# Set the C# language version (defaults to 3.0).
set(CMAKE_CSharp_FLAGS "/langversion:latest")
# Set the source file properties for Windows Forms use.
csharp_set_windows_forms_properties(
Form1.cs
Form1.Designer.cs
Form1.resx
Program.cs
)
# Add in the .NET reference libraries.
set_property(TARGET AutoMaxLairUI PROPERTY VS_DOTNET_REFERENCES
"Microsoft.CSharp"
"System"
"System.Core"
"System.Data"
"System.Drawing"
"System.Windows.Forms"
)
set_property(TARGET AutoMaxLairUI PROPERTY VS_PACKAGE_REFERENCES
"AForge.Video_2.2.5"
"AForge.Video.DirectShow_2.2.5"
"IronPython_2.7.11"
"Tommy_2.0.0"
)