-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Static web assets] Several fixes for additional scenarios (#19963)
* Fixes an issue with projects not working with reference assemblies using HintPath. * Fixes an issue where files without an extension where being included inside an additional folder with the file name on nuget packages. * Adds additional error logging for the brotli compression tool. * Adds additional login for the gzip compress task. * Adds editor config files in the blazor wasm and razor sdk folders to handle 'var' usage preferences in ASP.NET Core projects. * Performs a more selective filtering for static web assets candidates from the build candidates in blazor webassembly applications. * Fixes an issue with AppendTargetFramework=false causing issues dotnet/aspnetcore#35349 dotnet/aspnetcore#32744 dotnet/aspnetcore#29561 dotnet/aspnetcore#35561
- Loading branch information
Showing
26 changed files
with
5,649 additions
and
305 deletions.
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.