Repository navigation
Migrate GenerateStaticWebAssetsDevelopmentManifest #54836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlesProkop
merged 8 commits into
dotnet:main
from
AlesProkop:migrate-generate-static-web-assets-development-manifest
Jun 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
238c89d
migrate GenerateStaticWebAssetsDevelopmentManifest
AlesProkop 4d45bbe
addressed comments
AlesProkop de9c402
addressed comments
AlesProkop 84707c4
Merge branch 'main' into migrate-generate-static-web-assets-developme…
AlesProkop 5e6d758
Merge branch 'main' into migrate-generate-static-web-assets-developme…
AlesProkop 4270c8b
Convert new dev-manifest multithreading test to MSTest
AlesProkop 06061dd
Merge branch 'main' into migrate-generate-static-web-assets-developme…
AlesProkop bf0e51d
Set required ManifestPath/CacheFilePath in SkipsManifestGenerationWhe…
AlesProkop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
146 changes: 146 additions & 0 deletions
146
...ets.Tests/StaticWebAssets/GenerateStaticWebAssetsDevelopmentManifestMultiThreadingTest.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable disable | ||
|
|
||
| using Microsoft.AspNetCore.StaticWebAssets.Tasks; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Moq; | ||
|
|
||
| namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; | ||
|
|
||
| // These tests mutate the process current directory, so they must run sequentially. | ||
| // The project disables parallelization (MSTestParallelizeScope=None) and | ||
| // [DoNotParallelize] enforces that for this class. | ||
| [DoNotParallelize] | ||
| [TestClass] | ||
| public class GenerateStaticWebAssetsDevelopmentManifestMultiThreadingTest | ||
| { | ||
| [TestMethod] | ||
| public void WritesManifestRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() | ||
| { | ||
| var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(GenerateStaticWebAssetsDevelopmentManifestMultiThreadingTest), Guid.NewGuid().ToString("N")); | ||
| var projectDir = Path.Combine(testRoot, "project"); | ||
| var spawnDir = Path.Combine(testRoot, "spawn"); | ||
| var relativeManifestPath = Path.Combine("obj", "staticwebassets.development.json"); | ||
| var relativeCacheFilePath = Path.Combine("obj", "staticwebassets.build.cache.json"); | ||
| Directory.CreateDirectory(Path.Combine(projectDir, "obj")); | ||
| Directory.CreateDirectory(Path.Combine(spawnDir, "obj")); | ||
|
|
||
| var originalCurrentDirectory = Directory.GetCurrentDirectory(); | ||
| try | ||
| { | ||
| Directory.SetCurrentDirectory(spawnDir); | ||
|
|
||
| var task = new GenerateStaticWebAssetsDevelopmentManifest | ||
| { | ||
| BuildEngine = new Mock<IBuildEngine>().Object, | ||
| TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment(projectDir), | ||
| Source = "CurrentProjectId", | ||
| Assets = [CreateAssetItem("css/site.css")], | ||
| DiscoveryPatterns = [], | ||
| ManifestPath = relativeManifestPath, | ||
| CacheFilePath = relativeCacheFilePath | ||
| }; | ||
|
|
||
| task.Execute().Should().BeTrue(); | ||
|
|
||
| var expectedPath = Path.Combine(projectDir, relativeManifestPath); | ||
| File.Exists(expectedPath).Should().BeTrue("the manifest should be written under the project dir, not the process CWD"); | ||
|
|
||
| var incorrectPath = Path.Combine(spawnDir, relativeManifestPath); | ||
| File.Exists(incorrectPath).Should().BeFalse(); | ||
| } | ||
| finally | ||
| { | ||
| Directory.SetCurrentDirectory(originalCurrentDirectory); | ||
| if (Directory.Exists(testRoot)) | ||
| { | ||
| Directory.Delete(testRoot, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ResolvesExistingManifestProbeRelativeToProjectDirectory_NotProcessCurrentDirectory() | ||
| { | ||
| // Verifies that the File.Exists/File.ReadAllBytes change-detection probe in PersistManifest (and | ||
| // the up-to-date check in Execute) is rooted against TaskEnvironment.ProjectDirectory rather than | ||
| // the process CWD. A decoy manifest is planted in the process CWD at the same relative path. If the | ||
| // task read that decoy as the "existing" manifest it would overwrite the decoy or skip writing the | ||
| // project-dir file. The correct behavior is to ignore the decoy entirely: create the manifest under | ||
| // the project dir and leave the decoy untouched. | ||
| var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(GenerateStaticWebAssetsDevelopmentManifestMultiThreadingTest), Guid.NewGuid().ToString("N")); | ||
| var projectDir = Path.Combine(testRoot, "project"); | ||
| var spawnDir = Path.Combine(testRoot, "spawn"); | ||
| var relativeManifestPath = Path.Combine("obj", "staticwebassets.development.json"); | ||
| var relativeCacheFilePath = Path.Combine("obj", "staticwebassets.build.cache.json"); | ||
| Directory.CreateDirectory(Path.Combine(projectDir, "obj")); | ||
| Directory.CreateDirectory(Path.Combine(spawnDir, "obj")); | ||
|
|
||
| const string decoyContents = "DECOY - must not be read or overwritten"; | ||
| var decoyPath = Path.Combine(spawnDir, relativeManifestPath); | ||
| File.WriteAllText(decoyPath, decoyContents); | ||
|
|
||
| var originalCurrentDirectory = Directory.GetCurrentDirectory(); | ||
| try | ||
| { | ||
| Directory.SetCurrentDirectory(spawnDir); | ||
|
|
||
| var task = new GenerateStaticWebAssetsDevelopmentManifest | ||
| { | ||
| BuildEngine = new Mock<IBuildEngine>().Object, | ||
| TaskEnvironment = TaskEnvironment.CreateWithProjectDirectoryAndEnvironment(projectDir), | ||
| Source = "CurrentProjectId", | ||
| Assets = [CreateAssetItem("css/site.css")], | ||
| DiscoveryPatterns = [], | ||
| ManifestPath = relativeManifestPath, | ||
| CacheFilePath = relativeCacheFilePath | ||
| }; | ||
|
|
||
| task.Execute().Should().BeTrue(); | ||
|
|
||
| var expectedPath = Path.Combine(projectDir, relativeManifestPath); | ||
| File.Exists(expectedPath).Should().BeTrue("the existence probe must target the project dir, find nothing, and create the manifest there"); | ||
|
|
||
| File.ReadAllText(decoyPath).Should().Be(decoyContents, "the decoy in the process CWD must be neither read nor overwritten"); | ||
| } | ||
| finally | ||
| { | ||
| Directory.SetCurrentDirectory(originalCurrentDirectory); | ||
| if (Directory.Exists(testRoot)) | ||
| { | ||
| Directory.Delete(testRoot, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static ITaskItem CreateAssetItem(string relativePath) | ||
| { | ||
| var asset = new StaticWebAsset | ||
| { | ||
| Identity = relativePath, | ||
| SourceId = "OtherPackage", | ||
| SourceType = StaticWebAsset.SourceTypes.Discovered, | ||
| ContentRoot = "wwwroot", | ||
| BasePath = "_content/Base", | ||
| RelativePath = relativePath, | ||
| AssetKind = StaticWebAsset.AssetKinds.All, | ||
| AssetMode = StaticWebAsset.AssetModes.All, | ||
| AssetRole = StaticWebAsset.AssetRoles.Primary, | ||
| RelatedAsset = "", | ||
| AssetTraitName = "", | ||
| AssetTraitValue = "", | ||
| CopyToOutputDirectory = "", | ||
| CopyToPublishDirectory = "", | ||
| OriginalItemSpec = relativePath, | ||
| Integrity = "integrity", | ||
| Fingerprint = "fingerprint", | ||
| LastWriteTime = DateTime.UtcNow, | ||
| FileLength = 10, | ||
| }; | ||
|
|
||
| return asset.ToTaskItem(); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.