-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Static web assets] Account for HintPath when we compute the build assets #19873
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a464f24
Static web assets fixes and cleanups
javiercn cd1f4d2
Additional tests and cleanups
javiercn 33ca8f8
Fix log messages
javiercn c3e1a22
Update src/RazorSdk/Tasks/StaticWebAssets/ComputeStaticWebAssetsTarge…
javiercn a6bd12a
Respect AppendFrameowrkToOutputPath=false
javiercn a996c81
new test baselines
javiercn b58cf5b
Update src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.StaticWebAssets.t…
javiercn d10a14d
Fix test
javiercn 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 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,9 @@ | ||
# C# files | ||
[*.cs] | ||
|
||
#### Core EditorConfig Options #### | ||
|
||
# var preferences | ||
csharp_style_var_elsewhere = true | ||
csharp_style_var_for_built_in_types = true | ||
csharp_style_var_when_type_is_apparent = true |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,76 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Microsoft.NET.Sdk.BlazorWebAssembly | ||
{ | ||
// During the blazor build process some assets might not be at their final location by the time we try to compress them. | ||
// For that reason we need to determine the path to use to compress the file, which is what this task deals with. | ||
// We first check on the OriginalItemSpec of the asset and use that if the asset exists there. | ||
// In case it does not, we rely use the ItemSpec, which in case OriginalItemSpec does not exist, should point to an existing file on disk. | ||
// If neither the ItemSpec nor the OriginalItemSpec exist, we issue an error, since it indicates that the asset is not correctly | ||
// defined. | ||
// We can't just use the ItemSpec because for some assets that points to the output folder and causes issues with incrementalism. | ||
public class ComputeBlazorFilesToCompress : Task | ||
{ | ||
[Required] public ITaskItem[] Assets { get; set; } | ||
|
||
[Output] public ITaskItem[] AssetsToCompress { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
var result = new List<ITaskItem>(); | ||
|
||
for (var i = 0; i < Assets.Length; i++) | ||
{ | ||
var asset = Assets[i]; | ||
var originalItemSpec = asset.GetMetadata("OriginalItemSpec"); | ||
if (File.Exists(originalItemSpec)) | ||
{ | ||
Log.LogMessage("Asset '{0}' found at OriginalItemSpec '{1}' and will be used for compressing the asset", | ||
asset.ItemSpec, | ||
originalItemSpec); | ||
|
||
result.Add(CreateGzipAsset(asset, originalItemSpec)); | ||
} | ||
else if (File.Exists(asset.ItemSpec)) | ||
{ | ||
Log.LogMessage("Asset '{0}' found at '{1}' and will be used for compressing the asset", | ||
asset.ItemSpec, | ||
asset.ItemSpec); | ||
|
||
result.Add(CreateGzipAsset(asset, asset.ItemSpec)); | ||
} | ||
else | ||
{ | ||
Log.LogError("The asset '{0}' can not be found at any of the searched locations '{1}' and '{2}'", | ||
asset.ItemSpec, | ||
asset.ItemSpec, | ||
originalItemSpec); | ||
break; | ||
} | ||
} | ||
|
||
AssetsToCompress = result.ToArray(); | ||
|
||
return !Log.HasLoggedErrors; | ||
|
||
static TaskItem CreateGzipAsset(ITaskItem asset, string gzipSpec) | ||
{ | ||
var result = new TaskItem(gzipSpec, asset.CloneCustomMetadata()); | ||
|
||
result.SetMetadata("RelatedAsset", asset.ItemSpec); | ||
result.SetMetadata("AssetRole", "Alternative"); | ||
result.SetMetadata("AssetTraitName", "Content-Encoding"); | ||
result.SetMetadata("AssetTraitValue", "gzip"); | ||
|
||
return result; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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,9 @@ | ||
# C# files | ||
[*.cs] | ||
|
||
#### Core EditorConfig Options #### | ||
|
||
# var preferences | ||
csharp_style_var_elsewhere = true | ||
csharp_style_var_for_built_in_types = true | ||
csharp_style_var_when_type_is_apparent = true |
This file contains 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
This file contains 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
This file contains 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
9 changes: 9 additions & 0 deletions
9
src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/.editorconfig
This file contains 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,9 @@ | ||
# C# files | ||
[*.cs] | ||
|
||
#### Core EditorConfig Options #### | ||
|
||
# var preferences | ||
csharp_style_var_elsewhere = true | ||
csharp_style_var_for_built_in_types = true | ||
csharp_style_var_when_type_is_apparent = true |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotnet/aspnetcore#32744