Publish give MSB3030 error when wwwroot/dist assets are deleted and recreated as part of MSBuild Exec task #914

Closed
opened 2025-08-09 17:18:09 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @asadsahi on 3/22/2017

I have custom webpack configuration in my project, which generate javascript bundles in wwwroot/dist folder when running project under dev mode. Here is how it looks:

image

While these dev assets are still in wwwroot/dist directory and we do dotnet publish or publish from visual studio IDE. There is a custom task as configured in angular 2 spa template csproj file.

 <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <!--<Exec Command="npm install" />-->
    <Exec Command="npm run build:prod" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="wwwroot\dist\**\**;" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

npm run build:prod is an npm script which cleans wwwroot/dist directory and then creates minified assets, which look like this:
image

However, as soon as npm run build:prod finishes, I get following error:

image

It looks like the files are read by MSBuild and there is a race conditions between MSBuild and its Exec task in a sense that MSBuild doesn't wait for the Exec task to finish first.

This project is upgraded from project.json based architecture and we never had this issues as there was pre-publish task which finished first and give dotnet publish chance to pickup latest wwwroot/dist files.

Not sure if https://github.com/aspnet/JavaScriptServices/issues/735 is linked to this as well.

*Originally created by @asadsahi on 3/22/2017* I have custom webpack configuration in my project, which generate javascript bundles in wwwroot/dist folder when running project under dev mode. Here is how it looks: ![image](https://cloud.githubusercontent.com/assets/3470892/24201227/558139e6-0f07-11e7-91ac-359b91a4c560.png) While these dev assets are still in wwwroot/dist directory and we do `dotnet publish` or publish from visual studio IDE. There is a custom task as configured in angular 2 spa template csproj file. ``` <Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish"> <!-- As part of publishing, ensure the JS resources are freshly built in production mode --> <!--<Exec Command="npm install" />--> <Exec Command="npm run build:prod" /> <!-- Include the newly-built files in the publish output --> <ItemGroup> <DistFiles Include="wwwroot\dist\**\**;" /> <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)"> <RelativePath>%(DistFiles.Identity)</RelativePath> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </ResolvedFileToPublish> </ItemGroup> </Target> ``` `npm run build:prod` is an npm script which cleans wwwroot/dist directory and then creates minified assets, which look like this: ![image](https://cloud.githubusercontent.com/assets/3470892/24201518/2805b1ee-0f08-11e7-9f84-9fc55a3931c1.png) However, as soon as `npm run build:prod` finishes, I get following error: ![image](https://cloud.githubusercontent.com/assets/3470892/24201503/1f107b46-0f08-11e7-8167-c769b9654453.png) It looks like the files are read by MSBuild and there is a race conditions between MSBuild and its Exec task in a sense that MSBuild doesn't wait for the Exec task to finish first. This project is upgraded from project.json based architecture and we never had this issues as there was pre-publish task which finished first and give dotnet publish chance to pickup latest wwwroot/dist files. Not sure if https://github.com/aspnet/JavaScriptServices/issues/735 is linked to this as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#914
No description provided.