Add a new MSBuild target to include existing SPA dist files in the publish output when the SkipSpaBuild flag is set to true, ensuring the pre-built frontend assets are available in the published application without rebuilding.
72 lines
3.4 KiB
XML
72 lines
3.4 KiB
XML
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
|
|
<PropertyGroup>
|
|
<TargetFramework>net9.0</TargetFramework>
|
|
<Nullable>enable</Nullable>
|
|
<ImplicitUsings>enable</ImplicitUsings>
|
|
<SpaRoot>ClientApp\</SpaRoot>
|
|
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
|
|
</PropertyGroup>
|
|
|
|
<ItemGroup>
|
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
|
|
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.0" />
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
|
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
<PrivateAssets>all</PrivateAssets>
|
|
</PackageReference>
|
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
|
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
<PrivateAssets>all</PrivateAssets>
|
|
</PackageReference>
|
|
</ItemGroup>
|
|
|
|
<!-- Include the SPA project for publishing -->
|
|
<ItemGroup>
|
|
<Content Remove="$(SpaRoot)**" />
|
|
<None Remove="$(SpaRoot)**" />
|
|
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
|
|
</ItemGroup>
|
|
|
|
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
|
|
<!-- Ensure Node.js is installed -->
|
|
<Exec Command="node --version" ContinueOnError="true">
|
|
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
|
</Exec>
|
|
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build the frontend. See https://nodejs.org" />
|
|
<Message Importance="high" Text="Restoring frontend dependencies using npm..." />
|
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" />
|
|
</Target>
|
|
|
|
<!-- Always include pre-built SPA dist files in publish output (if they exist) -->
|
|
<Target Name="IncludeSpaDist" AfterTargets="ComputeFilesToPublish" Condition=" '$(SkipSpaBuild)' == 'true' And Exists('$(SpaRoot)dist\') ">
|
|
<ItemGroup>
|
|
<DistFiles Include="$(SpaRoot)dist\**" />
|
|
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
|
|
<RelativePath>%(DistFiles.Identity)</RelativePath>
|
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
|
</ResolvedFileToPublish>
|
|
</ItemGroup>
|
|
</Target>
|
|
|
|
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish" Condition=" '$(SkipSpaBuild)' != 'true' ">
|
|
<!-- Build the frontend -->
|
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm ci" Condition=" !Exists('$(SpaRoot)node_modules') " />
|
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
|
|
<Error Condition="'$(ErrorCode)' != '0'" Text="Frontend build failed." />
|
|
|
|
<!-- Include the built frontend in publish output -->
|
|
<ItemGroup>
|
|
<DistFiles Include="$(SpaRoot)dist\**" />
|
|
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
|
|
<RelativePath>%(DistFiles.Identity)</RelativePath>
|
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
|
</ResolvedFileToPublish>
|
|
</ItemGroup>
|
|
</Target>
|
|
|
|
</Project>
|