0
votes

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:

  1. Manually deleting the target published and project generated bundle files fixes the issue and results in a successful publish.
  2. Setting Items to Deploy to "All files in this project" in the csproj fixes the issue but is not a valid solution.
1

1 Answers

1
votes

This issue was solved by setting the ItemGroup's Target to AfterBuild

   <Target Name="AfterBuild"> 
    <ItemGroup>
      <Content Include="Areas\**\Views\**\dist.cshtml" />
      <Content Include="Areas\**\modules\dist\*" />
      <Content Include="Areas\**\modules\dist\maps\*" /> 
    </ItemGroup>
   </Target>

This causes the paths to be analyzed and included after the build is conducted and Gulp has rendered the revisioned files. See MSBuild MSDN Target.

Also note that to get the rendered js files in the outdir of an msbuild cmd needed to set

 <PropertyGroup>
    <UseWPP_CopyWebApplication>True</UseWPP_CopyWebApplication>
    <PipelineDependsOnBuild>False</PipelineDependsOnBuild>
 </PropertyGroup>

in the csproj. There is already a post describing this here.