VS: DOTNET_SDK: Cannot generate a single dot net binary which contains the dotnet core runtime inside the exe
CMAKE does not run dotnet publish to generate a single binary file which contains the dotnet runtime, and its not possible to use custom command to call dotnet publish after the build is finished.
cmake_minimum_required(VERSION 3.25.1)
project(myproj LANGUAGES CSharp)
# https://stackoverflow.com/questions/2074144/generate-c-sharp-project-using-cmake
include(CSharpUtilities)
set(CMAKE_CSharp_FLAGS "/platform:anycpu")
file(GLOB SOURCES *.cs)
add_executable( myapp${SOURCES})
set(CMAKE_VS_NUGET_PACKAGE_RESTORE true)
set_target_properties(myapp PROPERTIES
DOTNET_SDK "Microsoft.NET.Sdk"
DOTNET_TARGET_FRAMEWORK "net6.0"
VS_GLOBAL_Configurations "Debug;Release;RelWithDebInfo;MinSizeRel"
VS_GLOBAL_Version "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}.${VERSION_BUILD}" FILE_CONTENTS "${FILE_CONTENTS}"
VS_GLOBAL_ImplicitUsings enable
VS_GLOBAL_PublishSingleFile true
VS_GLOBAL_SelfContained true
VS_GLOBAL_RuntimeIdentifier win-x86
VS_GLOBAL_IncludeNativeLibrariesForSelfExtract true)
set_property(TARGET myappPROPERTY VS_PACKAGE_REFERENCES
"NUnit_3.13.3")
install( TARGETS myapp
COMPONENT default
DESTINATION . )