Skip to content
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 8 commits into from
Aug 20, 2021

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Aug 19, 2021

@javiercn javiercn added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Aug 19, 2021
Comment on lines 203 to 206
if (string.Equals(candidate.GetMetadata("ResolvedFrom"), "{HintPathFromItem}", StringComparison.Ordinal))
{
candidate.SetMetadata("OriginalItemSpec", candidate.ItemSpec);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We need this to account for the fact that the assembly was resolved using HintPath, otherwise static web assets thinks the .csproj is the original representation of the item and will try to copy that to the output folder.

Will be adding some more unit tests in this area

* 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.
* Moves static web assets pack tests with the rest of the static web
  assets tests.
* Adds multiple additional pack tests
  * Packages targeting multiple frameworks.
  * Pack with no build
* Adds build and publish tests for libraries using Reference and HintPath
* Add baseline test for publish with GenerateDocumentationFile=true
* Adds tests to validate the criteria we use to select the source file
  to use for compressing static web assets during build
@javiercn javiercn force-pushed the javiercn/dotnet-sdk-swa-fixes branch from 2821a18 to cd1f4d2 Compare August 20, 2021 15:59
@javiercn javiercn marked this pull request as ready for review August 20, 2021 15:59
}

[Fact]
public void Pack_StaticWebAssets_WithoutFileExtension_AreCorrectlyPacked()
Copy link
Member Author

Choose a reason for hiding this comment

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

dotnet/aspnetcore#29561

GeneratePackageOnBuild doesn't matter (as the issue mentions)

}

[Fact]
public void Build_Works_WithLibraryUsingHintPath()
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -103,6 +103,54 @@ public void Publish_WithDefaultSettings_Works()
VerifyTypeGranularTrimming(blazorPublishDirectory);
}

[Fact]
public void Publish_Works_WithLibraryUsingHintPath()
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -147,6 +147,37 @@ public void StaticWebAssets_Publish_Hosted_Works()
intermediateOutputPath);
}

[Fact]
public void StaticWebAssets_Publish_DoesNotIncludeXmlDocumentationFiles_AsAssets()
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a test to validate dotnet/aspnetcore#32744

Comment on lines +234 to 255
var fromMonoPackage = string.Equals(
candidate.GetMetadata("NuGetPackageId"),
"Microsoft.NETCore.App.Runtime.Mono.browser-wasm",
StringComparison.Ordinal);

reason = extension switch
{
".a" => "extension is .a is not supported.",
".c" => "extension is .c is not supported.",
".h" => "extension is .h is not supported.",
".a" when fromMonoPackage => "extension is .a is not supported.",
".c" when fromMonoPackage => "extension is .c is not supported.",
".h" when fromMonoPackage => "extension is .h is not supported.",
// It is safe to filter out all XML files since we are not interested in any XML file from the list
// of ResolvedFilesToPublish to become a static web asset. Things like this include XML doc files and
// so on.
".xml" => "it is a documentation file",
".rsp" => "extension is .rsp is not supported.",
".props" => "extension is .props is not supported.",
".rsp" when fromMonoPackage => "extension is .rsp is not supported.",
".props" when fromMonoPackage => "extension is .props is not supported.",
".blat" when !timezoneSupport => "timezone support is not enabled.",
".dat" when invariantGlobalization && fileName.StartsWith("icudt") => "invariant globalization is enabled",
".json" when fileName == "emcc-props" => $"{fileName}{extension} is not used by Blazor",
".json" when fromMonoPackage && fileName == "emcc-props" => $"{fileName}{extension} is not used by Blazor",
".js" when fileName == "dotnet" => "dotnet.js is already processed by Blazor",
".js" when assetType == "native" => $"{fileName}{extension} is not used by Blazor",
".pdb" when !copySymbols => "copying symbols is disabled",
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -295,7 +295,8 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="ResolveStaticWebAssetsConfiguration">
<PropertyGroup>
<_StaticWebAssetsManifestBase>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</_StaticWebAssetsManifestBase>
<_StaticWebAssetsManifestBase>$(BaseIntermediateOutputPath)$(Configuration)\</_StaticWebAssetsManifestBase>
<_StaticWebAssetsManifestBase Condition="'$(AppendTargetFrameworkToOutputPath)' != 'false'">$(_StaticWebAssetsManifestBase)\$(TargetFramework.ToLowerInvariant())\</_StaticWebAssetsManifestBase>
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -737,6 +737,46 @@ public void PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAnd
intermediateOutputPath);
}

[Fact]
public void PublishProjectWithReferences_AppendTargetFrameworkToOutputPathFalse_GeneratesPublishJsonManifestAndCopiesPublishAssets()
Copy link
Member Author

Choose a reason for hiding this comment

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

@javiercn javiercn merged commit 843f0f9 into main Aug 20, 2021
@javiercn
Copy link
Member Author

/backport to release/6.0.1xx-rc1

@VWilcox2000
Copy link

Had this issue after moving a .net 5.0 blazor app to 6.0. Error went away after navigating to ..\obj\Debug and just an 'md net6.0' to create a net6.0 path. Simple missing directory check on the MS side.

@mmitche mmitche deleted the javiercn/dotnet-sdk-swa-fixes branch October 4, 2021 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment