Preserve files being published to the publish root and the wwwroot

Fixes https://github.com/dotnet/aspnetcore/issues/19926
This commit is contained in:
Pranav K 2020-03-17 16:19:19 -07:00
parent 113cb5422d
commit a9494214fa
No known key found for this signature in database
GPG Key ID: F748807460A27E91
11 changed files with 74 additions and 4 deletions

View File

@ -10,6 +10,7 @@
$CommonFileElements$
<file src="..\..\..\THIRD-PARTY-NOTICES.txt" />
<file src="build\**" target="build" />
<file src="buildTransitive\**" target="buildTransitive" />
<file src="targets\**" target="targets" />
<file src="$taskskDir$\**" target="tools/" />
<file src="..\..\..\Web.JS\dist\$configuration$\blazor.webassembly.js" target="tools/blazor" />

View File

@ -21,7 +21,8 @@
<Error Text="blazor.webassembly.js file could not be found at $(_BlazorJsPath)" Condition="!Exists($(_BlazorJsPath))" />
</Target>
<Import Project="$(MSBuildThisFileDirectory)targets/All.props" />
<Import Project="$(MSBuildThisFileDirectory)targets/All.targets" />
<Import Project="$(MSBuildThisFileDirectory)build\netstandard1.0\Microsoft.AspNetCore.Components.WebAssembly.Build.props" />
<Import Project="$(MSBuildThisFileDirectory)build\netstandard1.0\Microsoft.AspNetCore.Components.WebAssembly.Build.targets" />
<Import Project="$(MSBuildThisFileDirectory)buildTransitive\netstandard1.0\Microsoft.AspNetCore.Components.WebAssembly.Build.targets" />
</Project>

View File

@ -1,3 +1,7 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\..\targets\All.props" />
<PropertyGroup>
<ReferencesComponentsWebAssemblyBuild>true</ReferencesComponentsWebAssemblyBuild>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\..\targets\All.targets" Condition="'$(ReferencesComponentsWebAssemblyBuild)' == 'true'" />
<Import Project="$(MSBuildThisFileDirectory)..\..\targets\StaticWebAssetsWokarounds.targets" Condition="'$(ReferencesComponentsWebAssemblyBuild)' != 'true'" />
</Project>

View File

@ -0,0 +1,47 @@
<Project>
<!--
We're attempting to work around a behavior in the Razor SDK with publishing + static web assets for 3.1 applications.
Some assets such as dlls can appear both as part of a .NET project's publish output as well as the output of the wwwroot. For instance, consider the
MyApp.Shared.dll. The target in the RazorSDK: https://github.com/dotnet/aspnetcore-tooling/blob/fae9a5fdbc19edcf5b59a093ce347897a78b0386/src/Razor/src/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.StaticWebAssets.targets#L493-L519
unconditionally retargets these items to the wwwroot sub-directory of the publish folder.
The behavior we want is for these items to appear in both places.
-->
<Target
Name="_BlazorStashStaticWebAssets"
BeforeTargets="_StaticWebAssetsComputeFilesToPublish"
Condition="'$(RazorSdkSupportPublishingSharedBinaries)' == ''">
<ItemGroup>
<!-- These are all static web assets that are to be copied to the publish output -->
<_BlazorExternalPublishStaticWebAssets
Include="%(StaticWebAsset.FullPath)"
Condition="'%(StaticWebAsset.SourceType)' != ''" />
<!--
We want the intersection of static web assets and ResolvedFilesToPublish that are to be copied to the publish root.
_BlazorNonSharedFilesToPublish - set of items that only appear in ResolvedFileToPublish
_BlazorSharedFilesToPublish - set of items that appear in both groups are are copied to the publish root.
-->
<_BlazorNonSharedFilesToPublish Include="@(ResolvedFileToPublish)" Exclude="@(_BlazorExternalPublishStaticWebAssets)" />
<_BlazorSharedFilesToPublish
Include="@(ResolvedFileToPublish)"
Exclude="@(_BlazorNonSharedFilesToPublish)"
Condition="'%(ResolvedFileToPublish.RelativePath)' == '%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)'"
/>
</ItemGroup>
</Target>
<Target
Name="_BlazorUnstashStaticWebAssets"
AfterTargets="_StaticWebAssetsComputeFilesToPublish"
Condition="'$(RazorSdkSupportPublishingSharedBinaries)' == '' AND '@(_BlazorSharedFilesToPublish->Count())' != '0'">
<ItemGroup>
<ResolvedFileToPublish Include="@(_BlazorSharedFilesToPublish)" />
</ItemGroup>
</Target>
</Project>

View File

@ -198,6 +198,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
Assert.FileExists(result, blazorPublishDirectory, "_framework", "wasm", DotNetJsFileName);
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "standalone.dll");
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
// Verify project references appear as static web assets
Assert.FileExists(result, blazorPublishDirectory, "_framework", "_bin", "RazorClassLibrary.dll");
// Also verify project references to the server project appear in the publish output
Assert.FileExists(result, publishDirectory, "RazorClassLibrary.dll");
// Verify static assets are in the publish directory
Assert.FileExists(result, blazorPublishDirectory, "index.html");

View File

@ -10,6 +10,7 @@ namespace blazorhosted.Server
public static void Main(string[] args)
{
Console.WriteLine(typeof(IWebHost));
Console.WriteLine(typeof(RazorClassLibrary.RCLTest));
}
}
}

View File

@ -6,6 +6,10 @@
<ItemGroup>
<ProjectReference Include="..\standalone\standalone.csproj" />
<ProjectReference Include="..\razorclasslibrary\RazorClassLibrary.csproj" />
</ItemGroup>
<!-- Approximating a build transitive reference -->
<Import Project="$(BlazorBuildRoot)buildTransitive\netstandard1.0\Microsoft.AspNetCore.Components.WebAssembly.Build.targets" />
</Project>

View File

@ -0,0 +1,4 @@
namespace RazorClassLibrary
{
public class RCLTest {}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
namespace standalone
{

View File

@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="${MicrosoftAspNetCoreComponentsWebAssemblyPackageVersion}" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="${MicrosoftAspNetCoreComponentsWebAssemblyBuildPackageVersion}" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="${MicrosoftAspNetCoreComponentsWebAssemblyBuildPackageVersion}" IncludeAssets="build;buildTransitive" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="${MicrosoftAspNetCoreComponentsWebAssemblyDevServerPackageVersion}" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="${MicrosoftAspNetCoreComponentsWebAssemblyAuthenticationPackageVersion}" Condition="'$(IndividualLocalAuth)' == 'true'" />
<PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="${MicrosoftAuthenticationWebAssemblyMsalPackageVersion}" Condition="'$(OrganizationalAuth)' == 'true' OR '$(IndividualB2CAuth)' == 'true'" />