Skip to content

Add .NET DLL for SDK projection to NuGet package#40182

Open
florelis wants to merge 3 commits intomicrosoft:feature/wsl-for-appsfrom
florelis:csNuget
Open

Add .NET DLL for SDK projection to NuGet package#40182
florelis wants to merge 3 commits intomicrosoft:feature/wsl-for-appsfrom
florelis:csNuget

Conversation

@florelis
Copy link
Copy Markdown
Member

Summary of the Pull Request

  • Updates the build process to create a new DLL, wslcsdkcs.dll, that will include the SDK projection for C#.
  • Updates the SDK NuGet's .targets files to include the new DLL and make better use of NuGet folder conventions.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • Added a new local CMake package for C# targets, which allows setting shared properties like the target framework. This was extracted from the existing wslsettings target and reused for the new wslcsdkcs.
  • Updated the .NET .targets to use a proper TFM (net8.0 instead of net), to check $(PlatformTarget) as a fallback when $(RuntimeIdentifier) is not set.
  • Moved the native binaries in the NuGet from runtimes\win-<arch>\ to runtimes\win-<arch>\native\, where MSBuild knows to automatically reference and copy them for .NET projects using $(RuntimeIdentifier)

Validation Steps Performed

Manually created C# projects and confirmed that the right files were being referenced and copied. More proper validation will come later in the form of sample apps.

@florelis florelis requested a review from a team as a code owner April 14, 2026 22:48
Copilot AI review requested due to automatic review settings April 14, 2026 22:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for shipping a C# projection DLL (wslcsdkcs.dll) in the Microsoft.WSL.Containers NuGet package, and updates build/targets logic so consumers get correct native asset layout and copy behavior.

Changes:

  • Introduces a CMake helper (configure_csharp_target) and a new C# CMake target for wslcsdkcs.
  • Updates NuGet package layout to place native binaries under runtimes/win-<arch>/native/ and adds new MSBuild targets for net8.0.
  • Updates CMake package config and NuGet spec to reference the new locations and include the new managed DLL.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/windows/wslsettings/CMakeLists.txt Switches to shared C# target configuration helper and removes duplicated per-target settings.
src/windows/WslcSDK/csharp/Projection.cs Adds placeholder C# source for the new projection DLL.
src/windows/WslcSDK/csharp/CMakeLists.txt Adds new C# shared library target wslcsdkcs.
nuget/Microsoft.WSL.Containers/cmake/Microsoft.WSL.ContainersConfig.cmake Updates imported DLL path to native/ subfolder.
nuget/Microsoft.WSL.Containers/build/net8.0/Microsoft.WSL.Containers.targets Adds net8-specific copy logic (RID/PlatformTarget fallback) and erroring.
nuget/Microsoft.WSL.Containers/build/net/Microsoft.WSL.Containers.targets Removes old net targets file.
nuget/Microsoft.WSL.Containers/build/native/Microsoft.WSL.Containers.targets Updates native targets and attempts DLL copy via MSBuild items.
nuget/Microsoft.WSL.Containers/build/Microsoft.WSL.Containers.common.targets Removes common targets file previously used for copying/erroring.
nuget/Microsoft.WSL.Containers.nuspec.in Adds wslcsdkcs.dll and moves native DLLs under native/.
cmake/findCSharp.cmake Adds configure_csharp_target() helper (C# flags + Windows SDK MSBuild properties).
CMakeLists.txt Adds find_package(CSharp) and adds the new C# subdirectory build.
.gitignore Normalizes *.etl entry and adds *.lscache.

Comment thread src/windows/wslsettings/CMakeLists.txt Outdated
Comment thread cmake/findCSharp.cmake Outdated
Comment thread cmake/findCSharp.cmake Outdated
Comment thread CMakeLists.txt
Comment thread nuget/Microsoft.WSL.Containers.nuspec.in Outdated
Comment thread nuget/Microsoft.WSL.Containers.nuspec.in Outdated
Comment thread nuget/Microsoft.WSL.Containers/build/net8.0/Microsoft.WSL.Containers.targets Outdated
Copy link
Copy Markdown
Member

@JohnMcPMS JohnMcPMS left a comment

Choose a reason for hiding this comment

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

I approve, but I am not a cmake expert so I would want one of the primary maintainers to make sure that part is good.

Copilot AI review requested due to automatic review settings April 16, 2026 03:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Comment on lines +3 to 6
<PropertyGroup>
<WslcPlatform Condition="'$(WslcPlatform)' == ''">$(Platform)</WslcPlatform>
<_wslcIsInvalidPlatform Condition="'$(WslcPlatform)' != 'x64' and '$(WslcPlatform)' != 'arm64'">true</_wslcIsInvalidPlatform>
</PropertyGroup>
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.
Comment thread CMakeLists.txt
Comment on lines +278 to +279
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")
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.
Comment thread CMakeLists.txt
Comment on lines +499 to 501
add_subdirectory(src/windows/WslcSDK/csharp)

if (WSL_BUILD_WSL_SETTINGS)
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants