Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Implementation Plan: CMake File API Integration

  • Research and understand CMake File API format
    • Understand File API request/response structure
    • Understand codemodel object format
    • Understand how to map CMakeLists.txt to output artifacts
  • Create new build tasks project for CMake File API operations
    • Add C# tasks to Microsoft.DotNet.CMake.Sdk project
    • Add task to generate File API request before configure
    • Add task to parse File API response and extract output paths
  • Update CMake SDK targets to generate File API request
    • Add File API request generation before Configure target
    • Ensure request is created in correct location
  • Update ProjectReference.targets to use File API response
    • Use File API response for artifact detection
    • Remove legacy fallback logic per review feedback
    • Copy output files based on File API response
  • Test the implementation
    • Create test CMake project to verify functionality
    • Verify files are copied correctly
    • Confirm File API is being used
  • Address PR review feedback
    • Use client stateless query file with client name
    • Remove backward compatibility fallback logic
    • Define C# object models for File API structures
    • Add error/warning logging as requested
    • Condition System.Text.Json to .NET Framework only
    • Remove unreferenced CopyNativeProjectBinaries target
    • Derive tasks from BuildTask instead of Task
    • Use LINQ for configuration and directory lookup
    • Seal all model types and add CMake File API documentation
    • Remove redundant VSWhereVersion property

Summary

Successfully implemented CMake File API integration for the Microsoft.DotNet.CMake.Sdk package and addressed all PR review feedback.

Changes Made:

  1. New C# Tasks: Created two MSBuild tasks:

    • CreateCMakeFileApiQuery: Generates File API client stateless query before CMake configure
    • GetCMakeArtifactsFromFileApi: Parses File API response to locate build artifacts
  2. C# Object Models: Created strongly-typed models in CMakeFileApiModels.cs for JSON deserialization

    • All types are sealed for performance
    • Comprehensive documentation with links to CMake File API specification
  3. Updated CMake SDK: Modified Microsoft.DotNet.CMake.Sdk.csproj to build C# tasks alongside SDK files

  4. Updated Targets:

    • Added CreateFileApiQuery target that runs before Configure
    • Updated ProjectReference.targets to use File API exclusively (removed fallback logic)
    • Added proper error/warning logging for missing configurations, directories, and artifacts
    • Removed unreferenced legacy CopyNativeProjectBinaries target
    • Removed redundant VSWhereVersion property (already defined by Arcade SDK)
  5. Code Quality:

    • Tasks derive from BuildTask for consistency with other Arcade build tasks
    • Used LINQ for cleaner configuration and directory lookups
    • All model types sealed with proper documentation

Benefits:

  • Eliminates hard-coded assumptions about CMake generator types
  • Works correctly with any CMake generator (VS, Ninja, Unix Makefiles, etc.)
  • More accurate artifact detection based on actual CMake build output
  • Provides clear error messages when File API data is missing
  • Cleaner codebase with legacy code removed and modern LINQ patterns
  • Well-documented with references to official CMake specifications
Original prompt

Today, the CMake SDK (Microsoft.DotNet.CMake.Sdk) uses built-in knowledge of different kinds of generators (multi-configuration vs single-configuration, VS vs non-VS) to determine where the artifacts for a given CMakeLists.txt file within the CMake tree will build its output artifacts.

Recently, CMake as introduced the CMake File API. The File API provides a mechanism through the "codemodel" object and its subobjects to determine exactly where output files for a given CMakeLists.txt will end up for a given configuration.

Update the CMake SDK to generate a CMake File API request before running the configure step.

Then update the ProjectReference.targets logic to locate the output build items based on the CMake File API response.

If you need to introduce any C# tasks, you can follow the model of other build task libraries in this repository for how to hook up the C# project (Microsoft.DotNet.Build.Tasks.Installers for example).

Generally, the output should work as follows:

  1. The user defines an MSBuild project that uses the CMake SDK to run the CMake configure and build for the whole tree.
  2. The CMake SDK will create the File API request and run configure and build.
  3. In another project, the user defines a CMakeProjectReference. This project reference points to a CMakeLists.txt file and a project that uses the CMake SDK.
  4. The targets in ProjectReference.targets should discover the output files that correspond to the source directory the CMakeLists.txt is in (pulled from a file API response).
  5. The targets should add the files such that they are copied the same way items are copied to the output directory.

Your change should not make any changes to the bringup script or the compiler search script.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update CMake SDK to use CMake File API for output paths Add CMake File API support to Microsoft.DotNet.CMake.Sdk Oct 20, 2025
Copilot AI requested a review from jkoritzinsky October 20, 2025 21:18
Copilot finished work on behalf of jkoritzinsky October 20, 2025 21:18
Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

Please address

@jkoritzinsky
Copy link
Member

@copilot please address the above comments

- Use client stateless query file with client name "Microsoft.DotNet.CMake.Sdk"
- Remove old fallback logic - File API is now required
- Define C# object models for File API JSON structures
- Add error logging when configuration not found
- Add error logging when source directory not found
- Add warning logging when no artifacts found
- Condition System.Text.Json package reference to .NET Framework TFM only

Co-authored-by: jkoritzinsky <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot please address the above comments

All review feedback has been addressed in commit d5a1e0c:

  • Created client stateless query file with client name "Microsoft.DotNet.CMake.Sdk"
  • Removed old fallback logic - File API is now required
  • Defined C# object models for File API JSON structures
  • Added error logging when configuration not found
  • Added error logging when source directory not found
  • Added warning logging when no artifacts found
  • Conditioned System.Text.Json package reference to .NET Framework TFM only

The implementation has been tested and verified to work correctly.

Copilot finished work on behalf of jkoritzinsky October 20, 2025 21:54
Copilot AI requested a review from jkoritzinsky October 20, 2025 21:54
Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

@copilot please address this feedback

Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

@copilot please address this feedback

The CopyNativeProjectBinaries target is no longer used after switching to File API-based artifact detection. Removed the entire target and its legacy filtering logic.

Co-authored-by: jkoritzinsky <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot please address this feedback

Done in commit ad3848c. Removed the unreferenced CopyNativeProjectBinaries target that was left over from the old logic.

- Updated CreateCMakeFileApiQuery and GetCMakeArtifactsFromFileApi to derive from BuildTask instead of Task
- Replaced loop-based configuration and directory finding with LINQ FirstOrDefault
- Updated Log method calls to use BuildTask's Log API (LogImportance enum and params object[] format)
- Added using Microsoft.Build.Utilities for TaskItem

Co-authored-by: jkoritzinsky <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot please address this feedback

All feedback addressed in commit {short_hash}:

  • Tasks now derive from BuildTask instead of Task
  • Used LINQ FirstOrDefault for configuration and directory lookups
  • Updated Log method calls to use BuildTask's API

Copilot finished work on behalf of jkoritzinsky October 20, 2025 22:19
- Sealed all classes in CMakeFileApiModels.cs as they don't need to be inherited
- Added comprehensive documentation comment explaining these types represent a subset of the CMake File API
- Included links to the official CMake File API specification (index file and codemodel v2)

Co-authored-by: jkoritzinsky <[email protected]>
@jkoritzinsky
Copy link
Member

jkoritzinsky commented Oct 21, 2025

This is blocked on getting a newer CMake that has a new enough file API implementation rolled out on the Windows machines so we don't break our WinForms users.

Validated locally that this works for the WinForms use case.

@jkoritzinsky jkoritzinsky marked this pull request as ready for review October 21, 2025 15:42
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<VSWhereVersion Condition="'$(VSWhereVersion)' == ''">3.1.7</VSWhereVersion>
Copy link
Member

Choose a reason for hiding this comment

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

do we really need this? VSWhereVersion should always be defined by arcade SDK's DefaultVersions.props

Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove this VSWhereVersion property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit {short_hash}. Removed the redundant VSWhereVersion property since it's already defined by Arcade SDK's DefaultVersions.props.

@jkoritzinsky
Copy link
Member

Blocked on #16233.

VSWhereVersion is already defined by arcade SDK's DefaultVersions.props, so the default value here is redundant and can be removed.

Co-authored-by: jkoritzinsky <[email protected]>
Copilot AI requested a review from jkoritzinsky October 22, 2025 17:46
Copilot finished work on behalf of jkoritzinsky October 22, 2025 17:46
@akoeplinger
Copy link
Member

akoeplinger commented Oct 23, 2025

Blocked on #16233.

This links to this PR 😄 is it still blocked or good to go?

@jkoritzinsky
Copy link
Member

I messed up the copy, dang it. It's blocked on an update to the helix machines (need a newer CMake for WinForms) which isn't in yet.

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.

[Microsoft.DotNet.CMake.Sdk]: Add ability to specify custom filters for NativeProjectReference artifacts

3 participants