C# UWP app support
Hello I am trying to build dummy C# project with UWP support.
CMakeLists.txt
cmake_minimum_required(VERSION 3.14.4)
project(uwp LANGUAGES CXX CSharp)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(uwp WIN32 App.xaml App.xaml.cs)
set_target_properties(uwp PROPERTIES VS_WINRT_COMPONENT TRUE)
set_target_properties(uwp PROPERTIES VS_USER_PROPS "${PROJECT_SOURCE_DIR}/main.props")
set_target_properties(uwp PROPERTIES VS_GLOBAL_PROJECT_TYPES "{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")
set_property(SOURCE "App.xaml" PROPERTY VS_XAML_TYPE "ApplicationDefinition")
build command is:
cmake . -G "Visual Studio 16 2019" -A Win32 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_CONFIGURATION_TYPES="Debug;Release"
However it generates invalid csproj file. I tried to make this csproj working somehow so I want to show what changes are required (issues):
- csproj file have definition:
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
- csproj file changed
WindowsTargetPlatformVersion
->TargetPlatformVersion
, and same forWindowsTargetPlatformMinVersion
- new output type is added
<OutputType>AppContainerExe</OutputType>
- C# targets (
VS10_CSharp_TARGETS
) were replaced by Xaml targets.<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
- ZERO_CHECK and ALL_BUILD projecs have "Windows Store 10.0" instead of "Universal app" type. (everything works, so we may ignore it)
I was unable to set (1-4) variables using property sheets. But I was able to set some other variables using workarounds:
- via cmake variable VS_GLOBAL_PROJECT_TYPES "{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
- via property sheet (main.props):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.8</Version>
</PackageReference>
</ItemGroup>
</Project>
After those changes I was able to get something build-able. MSVS still not able to compile project because it tries to join absolute paths (looks like MSVS issue, not CMake)
I am not familiar with CMake sources. It looks like MS guys call UWP = UAP. Also it is possible that "Windows Store" != "UAP". So I am not sure what will be condition to add that xml elements to csproj (to solve issues 1-3). Related to issue 4. Can we hardcode .targets similar to WindowsCE for uwp cs projects? or can we make it configurable somehow?
I am open to any suggestions related to how I can implement CMake C# uwp app using workarounds :D. Please let me know if you need sample project/files.