# CMake ignores WIN32\_EXECUTABLE TRUE for C# target

**URL:** https://discourse.cmake.org/t/cmake-ignores-win32-executable-true-for-c-target/8001
**Category:** Usage
**Tags:** os:windows
**Created:** [April 27, 2023, 2:36pm UTC](https://discourse.cmake.org/t/cmake-ignores-win32-executable-true-for-c-target/8001 "2023-04-27T14:36:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yzakharchuk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yzakharchuk/32/3391_2.png) [@yzakharchuk](https://discourse.cmake.org/u/yzakharchuk)
#### Post date: [April 27, 2023, 2:36pm UTC](https://discourse.cmake.org/t/cmake-ignores-win32-executable-true-for-c-target/8001/1 "2023-04-27T14:36:40Z")

</div>

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
> 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**
>
> ```auto
> namespace WinFormsApp1
> {
> public partial class Form1 : System.Windows.Forms.Form
> {
> public Form1()
> {
> InitializeComponent();
> }
> }
> }
> 
> ```

> **Form1.Designer.cs**
>
> ```auto
> 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**
>
> ```auto
> 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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 1, 2023, 3:14pm UTC](https://discourse.cmake.org/t/cmake-ignores-win32-executable-true-for-c-target/8001/2 "2023-05-01T15:14:43Z")

</div>

Seems like a hole in the C# support to me. Could you please search for and file [a new issue](https://gitlab.kitware.com/cmake/cmake/-/issues) if one doesn’t already exist?
