Skip to content

Add MSBuild and CMake build integration for WSLC container images#14551

Open
shuaiyuanxx wants to merge 7 commits intomasterfrom
user/shawn/buildUX
Open

Add MSBuild and CMake build integration for WSLC container images#14551
shuaiyuanxx wants to merge 7 commits intomasterfrom
user/shawn/buildUX

Conversation

@shuaiyuanxx
Copy link
Copy Markdown

@shuaiyuanxx shuaiyuanxx commented Mar 27, 2026

Summary of the Pull Request

Add build-system integration to the Microsoft.WSL.Containers NuGet package so that developers can declaratively build WSLC container images as part of their MSBuild (C++/C#) and CMake workflows, with full incremental rebuild support.

Developers declare <WslcImage> items (MSBuild) or call wslc_add_image() (CMake) in their project, and the build system automatically invokes wslc image build after the main build, skipping the step when sources haven't changed.

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

New files

File Description
build/Microsoft.WSL.Containers.common.targets Core MSBuild targets shared by C++ and C#: wslc CLI validation (WSLC0001), item metadata validation (WSLC0002WSLC0004), incremental image build via stamp files, design-time build guard, and clean target
build/native/Microsoft.WSL.Containers.targets C++ specific: writes .tlog files for VS Fast Up-to-Date Check
build/net/Microsoft.WSL.Containers.targets C# specific: registers CPS UpToDateCheckInput/UpToDateCheckBuilt items for VS up-to-date check
cmake/Microsoft.WSL.ContainersConfig.cmake wslc_add_image() CMake function with target name validation, IMAGE validation, path normalization, CONFIGURE_DEPENDS glob, and CONTEXT fallback when SOURCES is omitted

Usage — MSBuild (C++ / C#)

<ItemGroup>
  <WslcImage Include="echo-server"
             Dockerfile="container\server\Dockerfile"
             Context="container\server"
             Tag="latest"
             Sources="container\server;container\shared" />
</ItemGroup>

Usage — CMake

find_package(Microsoft.WSL.Containers REQUIRED)
wslc_add_image(echo-server
    IMAGE       ghcr.io/myorg/echo-server
    DOCKERFILE  container/Dockerfile
    CONTEXT     container/
    SOURCES     container/src/*.cpp container/src/*.h
    TAG         latest
)
add_dependencies(my_app echo-server)

Key design decisions

  • Stamp files for incremental tracking — MSBuild Inputs/Outputs and CMake DEPENDS/OUTPUT use a timestamp stamp file (wslc_<name>.built) to skip rebuilds when no source files have changed.
  • No image exportwslc image build is the terminal step; image save/export is not included and can be added later when wslc image save stabilizes.
  • Semicolon-safe property passingSources metadata is escaped via $([MSBuild]::Escape()) before passing through MSBuild task Properties=, and unescaped at the consumption site, so multi-directory paths work correctly.
  • Design-time build guard — All build and validation targets are skipped when $(DesignTimeBuild) == 'true' to avoid slowing down the VS IDE.
  • Input validationDockerfile and Context are required; Identity is validated against invalid filename characters with actionable error codes (WSLC0001WSLC0004). CMake IMAGE parameter is validated to not contain : (use TAG separately).

Validation Steps Performed

All tests run locally against wslc 2.8.1 on Windows 11 (26200):

Test Result
C++ MSBuild: fresh build Pass
C++ MSBuild: incremental skip (no changes) Pass
C++ MSBuild: rebuild on source change (multi-directory Sources) Pass
C++ MSBuild: clean removes stamp Pass
C# (.NET 8): fresh build Pass
C# (.NET 8): incremental skip Pass
C# (.NET 8): rebuild on source change Pass
CMake (VS 2022 generator): configure Pass
CMake: fresh build Pass
CMake: incremental skip Pass
CMake: rebuild on source change Pass
Validation: missing Dockerfile → error WSLC0002 Pass
Validation: Identity with / → error WSLC0004 Pass
CMake: invalid target name → FATAL_ERROR Pass
CMake: IMAGE with :FATAL_ERROR Pass
CMake: empty SOURCES defaults to CONTEXT contents Pass

Copilot AI review requested due to automatic review settings March 27, 2026 02:12

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings March 27, 2026 04:49

This comment was marked as resolved.

Comment thread nuget/Microsoft.WSL.Containers/cmake/Microsoft.WSL.ContainersConfig.cmake Outdated
Comment thread nuget/Microsoft.WSL.Containers/cmake/Microsoft.WSL.ContainersConfig.cmake Outdated
Comment thread nuget/Microsoft.WSL.Containers/cmake/Microsoft.WSL.ContainersConfig.cmake Outdated
Comment thread nuget/Microsoft.WSL.Containers/build/Microsoft.WSL.Containers.common.targets Outdated
Copilot AI review requested due to automatic review settings March 30, 2026 05:05

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings March 30, 2026 09:06

This comment was marked as resolved.

@benhillis
Copy link
Copy Markdown
Member

Hey @shuaiyuanxx 👋 — Following up on this draft PR. There are 11 unresolved review threads covering design and implementation feedback (flag file vs tar output, image save requirement, target naming, GLOB_RECURSE validation, VS design-time build interference, etc.).

Is this still actively being developed? The PR is marked DO NOT MERGE — just checking in on the status and whether the approach is still the planned direction.

@shuaiyuanxx
Copy link
Copy Markdown
Author

shuaiyuanxx commented Apr 9, 2026

Hey @shuaiyuanxx 👋 — Following up on this draft PR. There are 11 unresolved review threads covering design and implementation feedback (flag file vs tar output, image save requirement, target naming, GLOB_RECURSE validation, VS design-time build interference, etc.).

Is this still actively being developed? The PR is marked DO NOT MERGE — just checking in on the status and whether the approach is still the planned direction.

Hi @benhillis, thanks for following up.

Yes — this is still actively being developed. The design direction has been reviewed and approved via the spec. This PR is ready for review now.

Copilot AI review requested due to automatic review settings April 9, 2026 03:13

This comment was marked as resolved.

@shuaiyuanxx shuaiyuanxx changed the title draft pr for build UX Add MSBuild and CMake build integration for WSLC container images Apr 9, 2026
@shuaiyuanxx shuaiyuanxx marked this pull request as ready for review April 9, 2026 05:53
@shuaiyuanxx shuaiyuanxx requested a review from a team as a code owner April 9, 2026 05:53
Copilot AI review requested due to automatic review settings April 9, 2026 05:53

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings April 9, 2026 06:11

This comment was marked as resolved.

This comment was marked as resolved.

Comment thread nuget/Microsoft.WSL.Containers/build/Microsoft.WSL.Containers.common.targets Outdated
Copilot AI review requested due to automatic review settings April 10, 2026 23:58
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 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 13, 2026 01:38

This comment was marked as resolved.

florelis
florelis previously approved these changes Apr 13, 2026
@benhillis
Copy link
Copy Markdown
Member

The feature/wsl-for-apps branch is now defunct. If your PR is still valid, please retarget the master branch. Reach out to @benhillis for help if needed.

@shuaiyuanxx shuaiyuanxx changed the base branch from feature/wsl-for-apps to master May 6, 2026 02:36
@shuaiyuanxx shuaiyuanxx dismissed florelis’s stale review May 6, 2026 02:36

The base branch was changed.

Copilot AI review requested due to automatic review settings May 6, 2026 02:45
@shuaiyuanxx shuaiyuanxx force-pushed the user/shawn/buildUX branch from 40f6148 to acc6bcf Compare May 6, 2026 02:45

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings May 6, 2026 07:30
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 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 7, 2026 07:08
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 4 out of 4 changed files in this pull request and generated 6 comments.

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.

6 participants