Repository navigation
Fix dotnet-new template samples test and dotnet-watch .slnx sharing violation - #57089
Merged
Merged
Conversation
The test installed the latest package, so publishing 11.0.100 changed the generated F# project (FSharp.NET.Sdk removed) and broke the checked-in snapshot. Pin to 10.0.404, which the snapshots match. Fixes dotnet#57031 Co-authored-by: Copilot App <[email protected]>
…he published one Pack documentation/TemplateEngine/Samples as part of building dotnet-new.IntegrationTests and install that nupkg in TemplateEngineSamplesTest, replacing the unversioned install of the latest published package. Update the F# snapshot to match the in-repo sample. Fixes dotnet#57031 Co-authored-by: Copilot App <[email protected]>
…kage Mark the samples content CopyToOutputDirectory (under TemplateEngineSamples/) so a ProjectReference copies it into the dotnet-new.IntegrationTests output, and install that folder in TemplateEngineSamplesTest. The package layout is unchanged. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the Windows temporary-file sharing fix.
No open issues 🎉
What changed in this PR
This PR fixes Windows file-sharing failures when dotnet watch builds multiple projects through a generated .slnx, addressing the build failure linked to #57065.
Changes:
- Close the temporary file’s write handle before retaining a read-only handle for the build.
- Update solution generation to use a content-writing callback and expose the file path instead of its stream.
- Exercise
File.OpenReadcompatibility and verify that Windows still denies write access.
| File | Description |
|---|---|
test/dotnet-watch.Tests/Utilities/TemporaryFileManagerTests.cs |
Tests reader compatibility and Windows write protection with the updated API. |
src/Dotnet.Watch/Watch/Utilities/TemporaryFileManager.cs |
Separates writing from the retained read-only handle and cleans up on creation failure. |
src/Dotnet.Watch/Watch/HotReload/HotReloadDotNetWatcher.cs |
Uses the updated helper to write and build generated solutions. |
Review effort: Balanced
rbhanda
approved these changes
Nov 12, 2026
Member
Author
|
CI triage for build 1678012: the failures are unrelated to this change.
|
This was referenced Nov 12, 2026
dotnet-watch held the generated multi-project .slnx open with FileAccess.ReadWrite and FileShare.Read while building it. MSBuild's solution parser opens solution files with File.OpenRead, which requests FileShare.Read and therefore fails on Windows while another handle has write access (MSB4025 sharing violation). The failed initial build left the Aspire ServerAndResources test waiting until the test host timed out. TemporaryFileManager.Create now writes the content through an exclusive handle and then keeps only a read-only, read-shared handle open until disposal, so readers can open the file while it still can't be modified or deleted. Fixes dotnet#57065 Co-authored-by: Copilot App <[email protected]>
MiYanni
force-pushed
the
miyanni-fix-watch-aspire-slnx-race
branch
from
November 12, 2026 19:34
6fb5f7e to
0447796
Compare
Member
Author
|
/azp run dotnet-sdk-public-ci |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
lbussell
reviewed
Nov 12, 2026
Address review feedback - Rename TemporaryFile.Path to FilePath to avoid shadowing System.IO.Path. - Use an intention-revealing comment for best-effort cleanup. - Document why write access is only denied on Windows (Unix FileShare is advisory flock()). - Use Path.Join in TemplateEngineSamplesTest. Co-authored-by: Copilot App <[email protected]>
MiYanni
enabled auto-merge
November 12, 2026 23:54
JeremyKuhne
approved these changes
Nov 13, 2026
This was referenced Nov 13, 2026
MiYanni
added a commit
that referenced
this pull request
Nov 17, 2026
Keep approval snapshots deterministic by installing the Template Engine samples version aligned with this servicing branch. Backport of #57089 (issue #57031). Co-authored-by: Copilot App <[email protected]>
nagilson
added a commit
that referenced
this pull request
Nov 17, 2026
… the published package Backport of the samples changes from #57089 (main). TemplateEngineSamplesTest installed the latest published Microsoft.TemplateEngine.Samples, so publishing 11.0.100 GA (SDK-style F# project) broke the checked-in snapshot on every branch. Build the samples project into the test output and install from that folder, and update the F# snapshot to the in-repo content. Fixes #57042 on release/11.0.1xx. Co-authored-by: Copilot <[email protected]> Copilot-Session: 3a9812a1-ab94-4bad-b412-d16ef17dc6fa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖Copilot🤖
This PR combines two independent CI fixes so they can be reviewed and merged together. CI build 1678390 passed with both changes applied.
.slnxwrite handle indotnet-watchbefore building. Fixes [AI discovered CI] dotnet-watch test host crashes during ServerAndResources #57065.Fixes #57031
Fixes #57065
Part 1: Test the in-repo template engine samples instead of the published package
TemplateEngineSamplesTestinstalled the latest publishedMicrosoft.TemplateEngine.Samplespackage, so publishing11.0.100(which dropsFSharp.NET.Sdkfrom the F# sample) broke the checked-insample06 --language F#snapshot.The samples live in this repo (
documentation/TemplateEngine/Samples), so the test now uses them directly instead of any package:Microsoft.TemplateEngine.Samples.csprojmarks its template contentCopyToOutputDirectory(linked underTemplateEngineSamples/). The package layout is unchanged (verified the nupkg entries are identical).dotnet-new.IntegrationTests.csprojhas aProjectReference(ReferenceOutputAssembly="false") to the samples project, so building the tests copies the templates into the test output.TemplateEngineSamplesTestinstalls theTemplateEngineSamplesfolder from its output directory.Microsoft.NET.Sdk, no legacy package references).Snapshots now always match the template content in the same commit.
Validated locally: all 16
TemplateEngineSamplesTestcases pass.Part 2: Release the generated
.slnxwrite handle before buildingRoot cause
Commit 2133b17 ("Create dotnet-watch solution files privately") changed
dotnet-watchto keep the generated multi-project.slnxopen withFileAccess.ReadWrite+FileShare.Readfor the duration of the build. MSBuild's solution parser (Microsoft.VisualStudio.SolutionPersistence) opens the file withFile.OpenRead, which requestsFileShare.Read; Windows denies that open while another handle holds write access. From the Helix console of the failing runs:The initial build of the Aspire watch server failed, so
AspireLauncherIntegrationTests.ServerAndResourceswaited forCapabilitiesoutput that never came until the test host was killed (hang dumps ofMicrosoft.DotNet.HotReload.Watch.Aspire/dotnet). Anydotnet watchsession that builds multiple projects through a generated solution on Windows hits the same build failure. The existing unit test masked the bug by reading withFileShare.ReadWriteinstead ofFile.OpenRead.Fix
TemporaryFileManager.Createnow takes a content writer: it writes through an exclusive handle, closes it, and then keeps only a read-only,FileShare.Readhandle open until disposal. Readers usingFile.OpenReadsucceed, while the file still can't be modified or deleted during the build (and stays in the owner-only private directory).TemporaryFileexposesPathinstead of the underlying stream, so callers can't use a closed or read-only stream by mistake.Validation
TemporaryFileManagerTestsnow reads viaFile.OpenRead(what MSBuild uses) and, on Windows, asserts that write access is still denied.TemporaryFileManagerTests+AspireLauncherIntegrationTestslocally on Windows against a rebuilt redist layout: 3/3 passed, and the server log showsBuild succeeded: ...\1.slnx.Note: #57066 (draft, Copilot coding agent) addresses the same
dotnet-watchissue by reopening the handle at the call site; this PR instead makes the helper API safe by construction. Only one of the two should be merged.