[Blazor] Fixes publishing for standalone blazor-wasm applications (#17353)
* Updates the publish path on the static web assets to match the convention used by standalone blazor applications.
This commit is contained in:
parent
ca948aae28
commit
4400467c15
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
<Import Project="Blazor.MonoRuntime.targets" />
|
||||
<Import Project="Publish.targets" />
|
||||
<Import Project="StaticWebAssets.targets" />
|
||||
|
||||
<Target Name="GenerateBlazorMetadataFile"
|
||||
BeforeTargets="GetCopyToOutputDirectoryItems">
|
||||
|
|
@ -42,17 +43,4 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<PropertyGroup>
|
||||
<GetCurrentProjectStaticWebAssetsDependsOn>
|
||||
$(GetCurrentProjectStaticWebAssetsDependsOn);
|
||||
_ClearCurrentStaticWebAssetsForReferenceDiscovery
|
||||
</GetCurrentProjectStaticWebAssetsDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="_ClearCurrentStaticWebAssetsForReferenceDiscovery">
|
||||
<ItemGroup>
|
||||
<StaticWebAsset Remove="@(StaticWebAsset)" Condition="'%(SourceType)' == ''" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<ResolveStaticWebAssetsInputsDependsOn>
|
||||
$(ResolveStaticWebAssetsInputsDependsOn);
|
||||
_RemoveBlazorCurrentProjectAssetsFromStaticWebAssets;
|
||||
</ResolveStaticWebAssetsInputsDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<Target Name="_RemoveBlazorCurrentProjectAssetsFromStaticWebAssets">
|
||||
<ItemGroup>
|
||||
<StaticWebAsset Remove="@(StaticWebAsset)" Condition="'%(SourceType)' == ''" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="BlazorStaticWebAssetsComputeFilesToPublish"
|
||||
AfterTargets="_StaticWebAssetsComputeFilesToPublish">
|
||||
|
||||
<ItemGroup>
|
||||
<!-- We need to update the external static web assets to follow the blazor publish output convention that puts them inside $(TargetName)/dist instead of wwwroot -->
|
||||
<_StandaloneExternalPublishStaticWebAsset Include="@(_ExternalPublishStaticWebAsset)" Condition="'%(RelativePath)' != ''">
|
||||
<RelativePath>$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '$([MSBuild]::NormalizePath('$([System.Text.RegularExpressions.Regex]::Replace('%(RelativePath)','^wwwroot\\?\/?(.*)','$(BlazorPublishDistDir)$1'))'))'))</RelativePath>
|
||||
</_StandaloneExternalPublishStaticWebAsset>
|
||||
|
||||
<!-- Update doesn't work inside targets so we need to remove the items and re-add them. See https://github.com/microsoft/msbuild/issues/2835 for details -->
|
||||
<ResolvedFileToPublish Remove="@(_StandaloneExternalPublishStaticWebAsset)" />
|
||||
<ResolvedFileToPublish Include="@(_StandaloneExternalPublishStaticWebAsset)" />
|
||||
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
public async Task Publish_WithDefaultSettings_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("standalone");
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new string[] { "razorclasslibrary" });
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
|
@ -28,6 +28,10 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
|
||||
// Verify referenced static web assets
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "wwwroot", "exampleJsInterop.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "styles.css");
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
|
|
@ -39,7 +43,7 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
public async Task Publish_WithLinkOnBuildDisabled_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("standalone");
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new string[] { "razorclasslibrary" });
|
||||
project.AddProjectFileContent(
|
||||
@"<PropertyGroup>
|
||||
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
|
||||
|
|
@ -62,6 +66,10 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify referenced static web assets
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "wwwroot", "exampleJsInterop.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "styles.css");
|
||||
|
||||
// Verify web.config
|
||||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<RazorLangVersion>3.0</RazorLangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -13,4 +13,8 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="$(MicrosoftAspNetCoreBlazorMonoPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\razorclasslibrary\RazorClassLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -11,17 +11,4 @@
|
|||
<Reference Include="Microsoft.AspNetCore.Blazor" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<GetCurrentProjectStaticWebAssetsDependsOn>
|
||||
$(GetCurrentProjectStaticWebAssetsDependsOn);
|
||||
_ClearCurrentStaticWebAssetsForReferenceDiscovery
|
||||
</GetCurrentProjectStaticWebAssetsDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="_ClearCurrentStaticWebAssetsForReferenceDiscovery">
|
||||
<ItemGroup>
|
||||
<StaticWebAsset Remove="@(StaticWebAsset)" Condition="'%(SourceType)' == ''" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue