The issue in essence seems to be that during a publish of an .NET MVC4 application Visual Studio throws an error with expecting to copy an existing bundle filename that gulp is removing and adding back with a new revision # in the file name. Even though the gulp event is "pre-build". Below is a a detailed desciption of the occurence.
We have a Visual Studio 2015 MVC project setup to run a pre-build event which calls a npm cmd for gulp. Gulp is minifying and bundling assets conditionally on the $(ConfigurationName). When built as Release gulp tasks includes a gulp-rev cmd to append a hashset to the bundle file name to counter caching issues. Here is the pre-build event:
cd $(ProjectDir)
call npm install
call npm run $(ConfigurationName)
Sidenote: The csproj is configured to include this bundle using a wildcard(*) for the name.
<ItemGroup>
<Content Include="Areas\**\modules\dist\*.min.js" />
</ItemGroup>
Builds compile successfully in release. However an issue arises with publishing. We receive this error:
Copying file C:\MyProject\Areas\Quality\modules\dist\documents-used-9ed3bdf4c9.bundle.min.js to obj\Release\Package\PackageTmp\Areas\Quality\modules\dist\scripts-9ed3bdf4c9.bundle.min.js failed. Could not find file 'Areas\Quality\modules\dist\scripts-9ed3bdf4c9.bundle.min.js'.
The build output for the publish is as such:
1> MyProject-> C:\workspace\MyProject\MyProject\bin\MyProject.dll 2>------ Publish started: Project: MyProject, Configuration: Release Any CPU ------ 2>Connecting to C:\publish... 2>Copying all files to temporary location below for package/publish: 2>obj\Release\Package\PackageTmp. 2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(3003,5): Error : Copying file Areas\Quality\modules\dist\scripts-9ed3bdf4c9.bundle.min.js to obj\Release\Package\PackageTmp\Areas\Quality\modules\dist\scripts-9ed3bdf4c9.bundle.min.js failed. Could not find file 'Areas\Quality\modules\dist\scripts-9ed3bdf4c9.bundle.min.js'.
Notes:
- Manually deleting the target published and project generated bundle files fixes the issue and results in a successful publish.
- Setting Items to Deploy to "All files in this project" in the csproj fixes the issue but is not a valid solution.