Skip to content

Cache NativeAOT Visual Studio tool discovery#129316

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-vcvarsall-cache
Jun 18, 2026
Merged

Cache NativeAOT Visual Studio tool discovery#129316
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-vcvarsall-cache

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Fixes #129265

Run vswhere during Windows NativeAOT setup to validate the selected Visual Studio installation and reuse cached vcvarsall output when the installation path and version match.

Run vswhere during Windows NativeAOT setup to validate the selected Visual Studio installation and reuse cached vcvarsall output when the installation path and version match.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Windows NativeAOT build integration to discover Visual Studio toolchains via vswhere.exe and cache the derived vcvarsall.bat output (tool directory + LIB paths) in $(NativeIntermediateOutputPath) so subsequent builds can reuse it.

Changes:

  • Replace the findvcvarsall.bat invocation with in-target vswhere.exe calls to locate the VS installation path/version and compute the appropriate vcvarsall environment.
  • Add a per-architecture cache file (findvcvarsall.$(_targetArchitecture).txt) to reuse prior vcvarsall output when the VS path/version match.
  • Remove the now-unused findvcvarsall.bat script.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets Implements vswhere-based VS discovery and a cache file to reuse vcvarsall output.
src/coreclr/nativeaot/BuildIntegration/findvcvarsall.bat Deleted (logic is now embedded in the .targets file).

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@eduardo-vp could you have a look at this? it basically inlines the findvcvarsall into MSBuild and introduces caching.

Before this change, we were guaranteed to spend a second of the build in findvcvarsall, even in incremental do nothing scenarios. Now incremental builds take ~100 ms (running vswhere takes ~50 ms by itself and we run it twice).

@eduardo-vp eduardo-vp left a comment

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.

LGTM!

@MichalStrehovsky MichalStrehovsky enabled auto-merge (squash) June 17, 2026 06:13
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g arm64 Windows helix is known to be dead

@MichalStrehovsky MichalStrehovsky merged commit 1f49500 into dotnet:main Jun 18, 2026
109 of 113 checks passed
@MichalStrehovsky MichalStrehovsky deleted the nativeaot-vcvarsall-cache branch June 18, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SetupOSSPecificProps target is not incremental

3 participants