MSBuild packaging no longer working. CopyAllFilesToSingleFolderForPackageDependsOn no longer triggers.

dylan's Avatar


11 May, 2018 04:59 AM

I have been using CopyAllFilesToSingleFolderForPackageDependsOn to help package generated files in a grunt-built web project, as per your instructions here:

I have recently updated a number of nuget packages across the solution and in the branch I'm testing this in doesn't seem to run the triggers anymore. The package no longer includes the files I need. There no error that I can see, it just doesn't work anymore.

Does anyone know of any changes or had a similar? I've been googling but I'm really running out of ideas and there's no other way to include it in the build that I know of. Here's the .csproj section, the EnsureNuGetPackageBuildImports is automatically added and I've tried rolling back the versions in this (they were the only things to change):

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see The missing file is {0}.</ErrorText>
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.8\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props'))" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  <Target Name="AfterBuild">
  <Target Name="IncludeCustomFilesInPackage">
    <Message Text="Collecting custom files..." />
      <CustomFiles Include="dist\**\*" />
      <FilesForPackagingFromProject Include="%(CustomFiles.Identity)">
    <Message Text="Add to package %(FilesForPackagingFromProject.Identity)" />
  <Target Name="MoveDistToRoot" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
    <!--1.Deleting Folders except dist-->
      <_FolderToDelete Include="$(_PackageTempDir)\app" />
      <_FolderToDelete Include="$(_PackageTempDir)\node_modules" />
      <_FolderToDelete Include="$(_PackageTempDir)\Pages" />
      <_FolderToDelete Include="$(_PackageTempDir)\Scripts" />
      <_FolderToDelete Include="$(_PackageTempDir)\assets" />
      <_FolderToDelete Include="$(_PackageTempDir)\img" />
    <RemoveDir Directories="@(_FolderToDelete)" />
    <!--2.Copying files,folders from dist to root directory-->
      <_FileToMove Include="$(_PackageTempDir)\dist\**" />
    <Move SourceFiles="%(_FileToMove.Identity)" DestinationFolder="$(_PackageTempDir)\%(RecursiveDir)" />
    <!--3.Deleting the empty folder dist-->
    <RemoveDir Directories="$(_PackageTempDir)\dist" />
  1. Support Staff 1 Posted by Ilya Finkelshte... on 12 May, 2018 02:18 AM

    Ilya Finkelshteyn's Avatar

    I would recommend to do the following experiments to have more data:

    • re-build last know good commit and see if files were copied

    • remove EnsureNuGetPackageBuildImports target at all and see if this helps

    • set msbuild verbosity level to detailed (build / verbosity: detailed in YAML) and compare good and bad build results. If you use YAML, you cannot update YAML in the old commit, so use remote YAML with re-build commit to get detailed logs from last known good commit. When you get detailed logs for both good and bad builds, search for CopyAllFilesToSingleFolderForPackageDependsOn and IncludeCustomFilesInPackage and see if you can spot the difference.

    Let us know what you found.

  2. 2 Posted by dylan on 14 May, 2018 01:18 AM

    dylan's Avatar

    Hi Ilya,

    Thanks for the response, I'm attempting to replicate the build process on
    my computer so I can quickly tweak it. Can you give me the exact package
    commands you run for the web deploy artifact packaging? I'm using

    msbuild.exe .\Project.csproj /t:WebPublish /p:WebPublishMethod=FileSystem
    /p:DeleteExistingFiles=True /p:publishUrl='C:\temp\develop\project'

    to create the folder, but I'm not sure how to package the artefact. Is it a
    different WebPublishMethod? I got the above command from your docs.

  3. 3 Posted by dylan on 14 May, 2018 01:42 AM

    dylan's Avatar

    Sorry, /p:WebPublishMethod=Package did the trick :)

    Will follow up when I have more details or hopefully figure out exactly what the difference is.

  4. 4 Posted by dylan on 14 May, 2018 04:53 AM

    dylan's Avatar

    Ok, I've solved the problem.

    I was using before_package - I'm not sure why, but after the nuget updates before_package now actually happens after packaging.

    I thought it simply wasn't taking the steps but it was, the files generated by grunt simply didn't exist yet. Carefully analysing the logs found the packaging (now for some reason the msbuild command isn't logged anymore either) as part of the build, and the grunt generation of the files happening later.

    Moving the before_package script into the before_build script fixed the issue.

    Thanks for your help.

  5. Support Staff 5 Posted by Ilya Finkelshte... on 15 May, 2018 01:33 AM

    Ilya Finkelshteyn's Avatar

    I see, thanks a lot for the update!

  6. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:28 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac