I have an ASP.NET Core 8 web project, where the client source code lives in a client
folder.
I also have an npm run build
that will compile those client files, and copy the output to the wwwroot
folder.
I would like to make the npm build part of the dotnet publish
, but not the dotnet build
.
Right now I have used this in my .csproj
file:
<Target Name="NpmBuild" BeforeTargets="Publish">
<Exec Command="npm ci" WorkingDirectory="client" />
<Exec Command="npm run build" WorkingDirectory="client" />
</Target>
The npm
commands are executed, but not until the publish
folder has already been populated by the publish command.
What is the right way to ensure that the npm
commands are run before the files are copied to the output folder?
BeforeTargets="Publish"
and theAfterTargets="PrepareForPublish"
attributes in your.csproj
file. learn.microsoft.com/en-us/visualstudio/msbuild/…BeforeTargets="BeforePublish"
.BeforePublish
is publicly documented.