简体   繁体   中英

MSBuild tries to copy files overwritten as part of the PreBuildEvent

When I'm building the application, one of the PreBuildEvents is the build of the React front-end:

<PropertyGroup>
    <PreBuildEvent>
        powershell.exe "npm --prefix """$(ProjectDir)Scripts\client""" run build"   
    </PreBuildEvent>
 </PropertyGroup>

Which overwrites the Project\Scripts\client\build

As part of the build I include the build folder in the project:

<Content Include="Scripts\client\build\**" />

However, towards the end of the build, I get an error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets(182,5): 
error MSB3030: Could not copy the file "Scripts\client\build\precache-manifest.639e62e5c73567fc96d77fd52068e2d7.js" 
because it was not found.

The problem is that the Scripts\client\build\precache-manifest.639e62e5c73567fc96d77fd52068e2d7.js was the file in the build folder before the PreBuildEvent was executed, after the PreBuildEvent was run the file is Scripts\client\build\precache-manifest.9fab5f56d5c8f9561b6f289e96f4a80e.js .

This problem just randomly started to happen recently, and seems to persist even if the entire repo is reverted 50+ versions back, and the issue is replicable across multiple computers running different versions of Visual Studio (2017 & 2019)

It sounds like the Include to the Content item group is being handled before the React build. Move the Include to a target that executes after the React build to ensure that the newly generated files are picked up.

If you have something like the following in the 'top level' of your project, the files will be added to the Content item collection before any targets have run -- which is not what you want.

<ItemGroup>
  <Content Include="Scripts\client\build\**" />
</ItemGroup>

How best to include the files after the React build, depends a bit on how the React build is actually being done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM