I’m trying to create .NET 6.0 WinForms application with CMake. I use the WIN32_EXECUTABLE
property to hide a console during execution, but it doesn’t work and I have to change Output Type
from Exe
to WinExe
manually from Visual Studio or directly in .csproj. Using VS_GLOBAL_OutputType "WinExe"
has no effect, but in this case CMake inserts OutputType
into .csproj twice with different values.
CMakeLists.txt
cmake_minimum_required(VERSION 3.24)
project(test_project LANGUAGES CSharp)
include(CSharpUtilities)
set(CMAKE_CSharp_FLAGS "/langversion:9")
set(CMAKE_DOTNET_TARGET_FRAMEWORK "net6.0-windows")
set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
set(project_properties
Form1.Designer.cs
)
add_executable(test_app
Program.cs
Form1.cs
${project_properties}
)
csharp_set_windows_forms_properties(
${project_properties}
)
set_target_properties(test_app PROPERTIES
WIN32_EXECUTABLE TRUE
VS_GLOBAL_UseWindowsForms "true"
)
Form1.cs
namespace WinFormsApp1
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
}
}
Form1.Designer.cs
namespace WinFormsApp1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}
Program.cs
using System;
using System.Windows.Forms;
namespace WinFormsApp1
{
internal static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}
CMake version: 3.24.3
Visual Studio version: 17.5.4