Tuesday 22 July 2014

Could not copy the file manifest because it was not found

This is an old chestnut that has maddened me for quite some time. It all starts with the error message

  • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(4453, 5): error MSB3030: Could not copy the file "bin\Release\myapp.exe.manifest" because it was not found. 
  • Project src\mysolution\myapp\myapp.csproj failed. 
  • Project src\mysolution\mysolution.sln failed. 

It almost certainly happens when you are doing the following:

  • Using msbuild directly, rather than Visual Studio "right click" (e.g. you are using Team City)
  • Have a solution with a web application and some other application types (e.g. a console app)
  • Are using the Target "Publish" to publish the website

For example, here are the TC settings that cause the problem for me:


I'm also using a solution that has this structure

  • MySolution
    • MyConsoleApp
    • MyWebApp

MyWebApp has a publish profile setup called "PublishToDisk". If I build or publish from Visual studio, everything is fine. If I build from Team City, I get the errors above.

I've known the cause of the problem for ages. The blanket "Publish" target is being applied to every project in the solution that might be publishable. That includes my console application. My console app is not setup for publishing however, nor do I want it to be. I do, however, want it to be built during the Team City process, as the app will get copied elsewhere via the packaging process in later stages.

However the possible solutions are not so obvious. running msbuild separately on myConsoleApp.csproj and MyWebApp.csproj seems ridiculously inefficient. Making my console application a click once app just to stop a build failure seems equally silly. By far the best solution I've found is to edit your myconsoleapp.csproj file and add the following section

<PropertyGroup>
    <GenerateManifests>true</GenerateManifests>
</PropertyGroup>

You can add this just before the ItemGroup for reference includes.

This should be enough to keep to allow your application to build without a load of very awkward feeling bodges.

Incidentally - this problem is one that occurs if you try to do this publishing process with Orchard via TC, so would solve that scenario too.

4 comments:

  1. Thank you, that was very helpful!

    ReplyDelete
  2. Thanks for this. I was hit by this one when trying to automate publish of Orchard to Azure Cloud Services using PowerShell. I will be committing this fix to the core Orchard repo on Codeplex for the upcoming 1.9 release.

    ReplyDelete
  3. Thank you so much, this worked for us!

    ReplyDelete
  4. Thanks on behalf of my co-developer and myself. This was very helpful, and certainly saved us much grief.

    ReplyDelete