aspnetcore/src/Microsoft.AspNetCore.Blazor.../targets/Publish.targets

62 lines
3.1 KiB
XML

<Project>
<PropertyGroup>
<BlazorLinkOnBuild Condition="'$(BlazorLinkOnBuild)'==''">true</BlazorLinkOnBuild>
<BlazorPublishDistDir>$(AssemblyName)\dist\</BlazorPublishDistDir>
<!-- Disable unwanted parts of the default publish process -->
<CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
<PreserveCompilationContext>false</PreserveCompilationContext>
<RazorCompileOnPublish>false</RazorCompileOnPublish>
<GenerateDependencyFile>false</GenerateDependencyFile>
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
</PropertyGroup>
<Target Name="BlazorGetCopyToPublishDirectoryItems"
BeforeTargets="GetCopyToPublishDirectoryItems"
DependsOnTargets="PrepareBlazorOutputs">
<ItemGroup>
<!-- Don't want to publish the assemblies from the regular 'bin' dir. Instead we publish ones from 'dist'. -->
<ResolvedAssembliesToPublish Remove="@(ResolvedAssembliesToPublish)" />
<!-- Move wwwroot files to output root -->
<ContentWithTargetPath Update="@(ContentWithTargetPath)" Condition="$([System.String]::new(%(TargetPath)).StartsWith('wwwroot\'))">
<TargetPath>$(BlazorPublishDistDir)$([System.String]::new(%(TargetPath)).Substring(8))</TargetPath>
</ContentWithTargetPath>
<!-- Publish all the 'dist' files -->
<_BlazorGCTPDIDistFiles Include="@(BlazorItemOutput->'%(TargetOutputPath)')" />
<_BlazorGCTPDI Include="@(_BlazorGCTPDIDistFiles)">
<TargetPath>$(BlazorPublishDistDir)$([MSBuild]::MakeRelative('$(ProjectDir)$(OutDir)dist\', %(Identity)))</TargetPath>
</_BlazorGCTPDI>
<ContentWithTargetPath Include="@(_BlazorGCTPDI)">
<TargetPath>%(TargetPath)</TargetPath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ContentWithTargetPath>
</ItemGroup>
<!-- Replace the .blazor.config contents with what we need to serve in production -->
<PropertyGroup>
<_BlazorConfigPath>$(OutDir)$(AssemblyName).blazor.config</_BlazorConfigPath>
</PropertyGroup>
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="." Overwrite="true" />
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="$(AssemblyName)\" Overwrite="false" />
</Target>
<!-- The following target runs only for standalone publishing -->
<Target Name="BlazorCompleteStandalonePublish" AfterTargets="CopyFilesToPublishDirectory">
<!-- Add a suitable web.config file if there isn't one already -->
<ItemGroup>
<_StandaloneWebConfigContent Include="$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)Standalone.Web.config'))"/>
</ItemGroup>
<WriteLinesToFile
Condition="!Exists('$(PublishDir)web.config')"
File="$(PublishDir)web.config"
Lines="@(_StandaloneWebConfigContent->Replace('[ServeSubdirectory]','$(BlazorPublishDistDir)'))" />
<!-- Remove the .blazor.config file, since it's irrelevant for standalone publishing -->
<Delete Files="$(PublishDir)$(AssemblyName).blazor.config" />
</Target>
</Project>