Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ directory.build.targets
test-storage/
*.vhdx
*.tar
*.etl
*.etl
*.lscache
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ find_package(NUGET REQUIRED)
find_package(VERSION REQUIRED)
find_package(MC REQUIRED)
find_package(Appx REQUIRED)
find_package(CSharp REQUIRED)
Comment thread
florelis marked this conversation as resolved.

# Download nuget packages
restore_nuget_packages()
Expand Down Expand Up @@ -272,6 +273,11 @@ if (${TARGET_PLATFORM} STREQUAL "x64")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /CETCOMPAT")
endif()

set(CMAKE_CSharp_FLAGS "${CMAKE_CSharp_FLAGS} /langversion:latest /debug:full")
set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
set(CMAKE_DOTNET_TARGET_FRAMEWORK "net8.0-windows${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
set(WSL_NUGET_TARGET_FRAMEWORK "net8.0-windows10.0.19041.0")
Comment on lines +278 to +279
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_DOTNET_TARGET_FRAMEWORK is set from CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION (e.g., 10.0.26100.0), but the NuGet lib folder uses WSL_NUGET_TARGET_FRAMEWORK = net8.0-windows10.0.19041.0. This can produce a managed wslcsdkcs.dll built for a higher Windows TFM being packaged under a lower TFM, which can mislead asset selection and break consumers on older Windows versions once the projection uses newer APIs. Align the built TFM with the package TFM (or vice versa), or set the DOTNET_TARGET_FRAMEWORK for wslcsdkcs explicitly to match WSL_NUGET_TARGET_FRAMEWORK.

Suggested change
set(CMAKE_DOTNET_TARGET_FRAMEWORK "net8.0-windows${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
set(WSL_NUGET_TARGET_FRAMEWORK "net8.0-windows10.0.19041.0")
set(WSL_NUGET_TARGET_FRAMEWORK "net8.0-windows10.0.19041.0")
set(CMAKE_DOTNET_TARGET_FRAMEWORK "${WSL_NUGET_TARGET_FRAMEWORK}")

Copilot uses AI. Check for mistakes.

# Common link libraries
link_directories(${WSLDEPS_SOURCE_DIR}/lib/)
set(COMMON_LINK_LIBRARIES
Expand Down Expand Up @@ -490,6 +496,7 @@ add_subdirectory(src/windows/wslrelay)
add_subdirectory(src/windows/wslinstall)
add_subdirectory(src/windows/wslc)
add_subdirectory(src/windows/WslcSDK)
add_subdirectory(src/windows/WslcSDK/csharp)

if (WSL_BUILD_WSL_SETTINGS)
Comment on lines +499 to 501
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/windows/WslcSDK/csharp is added unconditionally, which means a C#/.NET toolchain is now required even when WSL_BUILD_WSL_SETTINGS is false. If the intent is only to build/package the C# projection in specific scenarios, consider guarding this add_subdirectory(...) (and the find_package(CSharp REQUIRED)) behind an option/flag so core/native-only builds don’t start failing on machines without the C# build tools installed.

Suggested change
add_subdirectory(src/windows/WslcSDK/csharp)
if (WSL_BUILD_WSL_SETTINGS)
if (WSL_BUILD_WSL_SETTINGS)
add_subdirectory(src/windows/WslcSDK/csharp)

Copilot uses AI. Check for mistakes.
add_subdirectory(src/windows/libwsl)
Expand Down
13 changes: 13 additions & 0 deletions cmake/FindCSharp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function(configure_csharp_target TARGET)
set(TARGET_PLATFORM_MIN_VERSION "10.0.19041.0")

set_target_properties(
${TARGET} PROPERTIES
VS_GLOBAL_TargetPlatformVersion "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}"
VS_GLOBAL_TargetPlatformMinVersion "${TARGET_PLATFORM_MIN_VERSION}"
VS_GLOBAL_WindowsSdkPackageVersion "${WINDOWS_SDK_DOTNET_VERSION}"
VS_GLOBAL_AppendRuntimeIdentifierToOutputPath false
VS_GLOBAL_GenerateAssemblyInfo false
VS_GLOBAL_TargetLatestRuntimePatch false
)
endfunction()
11 changes: 8 additions & 3 deletions nuget/Microsoft.WSL.Containers.nuspec.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
<language>en-us</language>
<license type="expression">MIT</license>
<readme>docs\README.MD</readme>
<dependencies>
<group targetFramework="${WSL_NUGET_TARGET_FRAMEWORK}" />
</dependencies>
</metadata>
<files>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\src\windows\WslcSDK\wslcsdk.h" target="include"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\Release\wslcsdkcs.dll" target="lib\${WSL_NUGET_TARGET_FRAMEWORK}"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\Release\wslcsdk.lib" target="runtimes\win-x64"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\Release\wslcsdk.dll" target="runtimes\win-x64"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\Release\wslcsdk.dll" target="runtimes\win-x64\native"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\arm64\Release\wslcsdk.lib" target="runtimes\win-arm64"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\arm64\Release\wslcsdk.dll" target="runtimes\win-arm64"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\**"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\arm64\Release\wslcsdk.dll" target="runtimes\win-arm64\native"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\**" exclude="**\net\**"/>
<file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\build\net\**" target="build\${WSL_NUGET_TARGET_FRAMEWORK}"/>
</files>
</package>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(WSLCSDK_Platform)' == ''">
Comment thread
florelis marked this conversation as resolved.
<WSLCSDK_Platform>$(Platform)</WSLCSDK_Platform>
<PropertyGroup>
<WslcPlatform Condition="'$(WslcPlatform)' == ''">$(Platform)</WslcPlatform>
<_wslcIsInvalidPlatform Condition="'$(WslcPlatform)' != 'x64' and '$(WslcPlatform)' != 'arm64'">true</_wslcIsInvalidPlatform>
</PropertyGroup>
Comment on lines +3 to 6
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WslcPlatform defaults to $(Platform) but VS commonly sets $(Platform) to ARM64 (uppercase). Since the package folder is runtimes\win-arm64, the current comparison/path will treat ARM64 as invalid and also generate incorrect paths. Consider normalizing/mapping platform values (e.g., lowercase + map ARM64->arm64) before validation and before constructing runtimes\win-... paths.

Copilot uses AI. Check for mistakes.

<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>
Expand All @@ -16,11 +18,17 @@
%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalLibraryDirectories>
$(MSBuildThisFileDirectory)..\..\runtimes\win-$(Platform);
$(MSBuildThisFileDirectory)..\..\runtimes\win-$(WslcPlatform);
%(AdditionalLibraryDirectories)
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Microsoft.WSL.Containers.common.targets" />
<ItemGroup>
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-$(WslcPlatform)\native\wslcsdk.dll" />
</ItemGroup>
Comment thread
florelis marked this conversation as resolved.

<Target Name="WslcValidatePlatform" BeforeTargets="PrepareForBuild" Condition="'$(_wslcIsInvalidPlatform)' == 'true'">
<Error Text="wslcsdk.dll could not be copied because platform '$(WslcPlatform)' is not supported. Only x64 and arm64 platforms are supported." />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should mention the resolution: "Set WslcPlatform to a supported value."

[GH did not offer me the "suggest a change" button 🐸]

</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(WSLCSDK_Platform)' == ''">
<WSLCSDK_Platform Condition="$(RuntimeIdentifier.EndsWith('-x64'))">x64</WSLCSDK_Platform>
<WSLCSDK_Platform Condition="$(RuntimeIdentifier.EndsWith('-arm64'))">arm64</WSLCSDK_Platform>
</PropertyGroup>
<!-- If we have a RuntimeIdentifier, the DLL is referenced automatically.
If it is missing, we fall back to PlatformTarget to reference it manually. -->
<Choose>
<When Condition="'$(RuntimeIdentifier)' != ''">
<PropertyGroup>
<_wslcPlatform Condition="$(RuntimeIdentifier.EndsWith('-x64'))">x64</_wslcPlatform>
<_wslcPlatform Condition="$(RuntimeIdentifier.EndsWith('-arm64'))">arm64</_wslcPlatform>
<_wslcInvalidPlatformProperty Condition="'$(_wslcPlatform)' == ''">RuntimeIdentifier</_wslcInvalidPlatformProperty>
<_wslcInvalidPlatform Condition="'$(_wslcPlatform)' == ''">$(RuntimeIdentifier)</_wslcInvalidPlatform>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<_wslcPlatform Condition="'$(PlatformTarget)' == 'x64'">x64</_wslcPlatform>
<_wslcPlatform Condition="'$(PlatformTarget)' == 'arm64'">arm64</_wslcPlatform>
<_wslcInvalidPlatformProperty Condition="'$(_wslcPlatform)' == ''">PlatformTarget</_wslcInvalidPlatformProperty>
<_wslcInvalidPlatform Condition="'$(_wslcPlatform)' == ''">$(PlatformTarget)</_wslcInvalidPlatform>
</PropertyGroup>

<PropertyGroup Condition="'$(WSLCSDK_Platform)' == ''">
<WSLCSDK_Platform Condition="'$(Platform)' != 'AnyCPU'">$(Platform)</WSLCSDK_Platform>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Microsoft.WSL.Containers.common.targets" />
<ItemGroup Condition="'$(_wslcPlatform)' != ''">
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-$(_wslcPlatform)\native\wslcsdk.dll" />
</ItemGroup>
</Otherwise>
</Choose>

<Target Name="WslcValidatePlatform" BeforeTargets="PrepareForBuild" Condition="'$(_wslcInvalidPlatform)' != ''">
<Error Text="wslcsdk.dll could not be copied because the $(_wslcInvalidPlatformProperty) '$(_wslcInvalidPlatform)' is not supported. Only x64 and arm64 platforms are supported." />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ add_library(Microsoft.WSL.Containers::SDK SHARED IMPORTED GLOBAL)
set_target_properties(Microsoft.WSL.Containers::SDK PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_wslcsdk_include_dir}"
IMPORTED_IMPLIB "${_wslcsdk_lib_dir}/wslcsdk.lib"
IMPORTED_LOCATION "${_wslcsdk_lib_dir}/wslcsdk.dll"
IMPORTED_LOCATION "${_wslcsdk_lib_dir}/native/wslcsdk.dll"
)

# Clean up temporary variables
Expand Down
13 changes: 13 additions & 0 deletions src/windows/WslcSDK/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enable_language(CSharp)

add_library(wslcsdkcs SHARED "Projection.cs")
configure_csharp_target(wslcsdkcs)

set_target_properties(
wslcsdkcs PROPERTIES
FOLDER windows
LINKER_LANGUAGE CSharp
VS_GLOBAL_PlatformTarget "AnyCPU"
)

add_dependencies(wslcsdkcs wslcsdk)
8 changes: 8 additions & 0 deletions src/windows/WslcSDK/csharp/Projection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Microsoft.WSL.Containers
{
// This is only a placeholder so that we can compile a DLL.
// The actual implementation of the projection will be added later.
internal class Projection
{
}
}
36 changes: 3 additions & 33 deletions src/windows/wslsettings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(TargetApp wslsettings)

project(${TargetApp} LANGUAGES CSharp)
enable_language(CSharp)

# needed for csharp_set_xaml_cs_properties
include(CSharpUtilities)
Expand Down Expand Up @@ -183,21 +183,16 @@ csharp_set_xaml_cs_properties(
Views/Settings/ShellPage.xaml.cs
)

configure_csharp_target(${TargetApp})

set_property(
SOURCE App.xaml
PROPERTY VS_XAML_TYPE
"ApplicationDefinition"
)

# Set the C# language version (defaults to 3.0).
set(
CMAKE_CSharp_FLAGS
"/langversion:latest"
)

target_compile_options(
${TargetApp}
PRIVATE "/debug:full"
PRIVATE "/unsafe"
)

Expand All @@ -218,23 +213,6 @@ Microsoft.Xaml.Behaviors.WinUI.Managed_${XAML_BEHAVIORS_VERSION};\
WinUIEx_${WINUIEX_VERSION}"
)

set(
TARGET_PLATFORM_VERSION
"10.0.26100.0"
)
set(
WINDOWS_TARGET_PLATFORM_VERSION
"windows${TARGET_PLATFORM_VERSION}"
)
set(
TARGET_PLATFORM_MIN_VERSION
"10.0.19041.0"
)
set(
WINDOWS_TARGET_PLATFORM_MIN_VERSION
"windows${TARGET_PLATFORM_MIN_VERSION}"
)

set_target_properties(
${TargetApp} PROPERTIES
# ----- Dotnet, Windows App SDK and WinUI stuff starts here -----
Expand All @@ -252,16 +230,8 @@ set_target_properties(
VS_GLOBAL_Platform "${TARGET_PLATFORM}"
VS_GLOBAL_Platforms "${TARGET_PLATFORM}"
VS_GLOBAL_PlatformTarget "${TARGET_PLATFORM}"
VS_GLOBAL_TargetPlatformVersion "${TARGET_PLATFORM_VERSION}"
VS_GLOBAL_TargetPlatformMinVersion "${TARGET_PLATFORM_MIN_VERSION}"
VS_GLOBAL_WindowsSdkPackageVersion "${WINDOWS_SDK_DOTNET_VERSION}"
VS_GLOBAL_ImplicitUsings enable
VS_GLOBAL_Nullable enable
VS_GLOBAL_AppendRuntimeIdentifierToOutputPath false
VS_GLOBAL_GenerateAssemblyInfo false
VS_GLOBAL_TargetLatestRuntimePatch false
DOTNET_SDK "Microsoft.NET.Sdk"
DOTNET_TARGET_FRAMEWORK "net8.0-${WINDOWS_TARGET_PLATFORM_VERSION}"
)

configure_file(
Expand Down