VS2012 Post-build event not firing

Grant picture Grant · Aug 23, 2012 · Viewed 14.5k times · Source

I have a web project that fires a post-build event "On successful build" to perform some cleanup/migration activities (command script).

In VS2012, post-build on success ONLY fires when there is a code change. If there is no code change, the compiler still reports Successful Build, however, the on success post-build event does not fire.

In VS2010, post-build event on success fires on every successful build regardless of code changes. This is what I would expect. The compile was successful, even if no changes occurred, so the event should fire.

Example VS2012 build with code change:

------ Build started: Project: ABC.Business.Web.Migrate, Configuration: Debug Any CPU ------
Build started 2012-08-23 01:26:13.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva- /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /debug+ /debug:full /optimize- /out:obj\Debug\ABC.Web.Migrate.dll /target:library /utf8output Properties\AssemblyInfo.cs "C:\Users\Administrator\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
_CopyFilesMarkedCopyLocal:
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll" to "bin\ABC.Business.Web.dll".
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Web.dll" to "bin\ABC.Web.dll".
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC._Services.dll" to "bin\ABC._Services.dll".
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.pdb" to "bin\ABC.Business.Web.pdb".
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Web.pdb" to "bin\ABC.Web.pdb".
  Copying file from "C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC._Services.pdb" to "bin\ABC._Services.pdb".
CopyFilesToOutputDirectory:
  Copying file from "obj\Debug\ABC.Web.Migrate.dll" to "bin\ABC.Web.Migrate.dll".
  ABC.Business.Web.Migrate -> C:\Dev\ABC\Source\ABC.Business.Web.Migrate\bin\ABC.Web.Migrate.dll
  Copying file from "obj\Debug\ABC.Web.Migrate.pdb" to "bin\ABC.Web.Migrate.pdb".
PostBuildEvent:
  "C:\Dev\bin\spawn.exe" "C:\Dev\ABC\Scripts\Migrate Business Web.bat"

Build succeeded.

Time Elapsed 00:00:00.34
========== Build: 4 succeeded, 0 failed, 53 up-to-date, 0 skipped ==========

Example VS2012 build without code change:

------ Build started: Project: ABC.Business.Web, Configuration: Debug Any CPU ------
Build started 2012-08-23 01:36:04.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  ABC.Business.Web -> C:\Dev\ABC\Source\ABC.Business.Web\bin\ABC.Business.Web.dll

Build succeeded.

Time Elapsed 00:00:00.31
========== Build: 1 succeeded, 0 failed, 56 up-to-date, 0 skipped ==========

I tried using post-build event "Always" in VS2012. It only fires the Always post-build event if there is a code change (identical to On success). My only workaround has been to do a Rebuild - painful when I have dozens of dependent projects! Or manually run my script - also annoying! (And NO, it's not my script - this script works perfectly fine when there is a code change as the first example illustrates!)

This is either an intentional change or a bug.

Has anyone else experienced this post-build problem in VS2012?

Answer

Jorge L. Fatta picture Jorge L. Fatta · Jan 11, 2013

I had the same problem and I solved it as follows:

  • add some dummy empty txt file to the project.
  • property "Build Action": Content.
  • property "Copy to Output Directory": Always.

thats it, it will execute de POST-BUILD step always, even if the project is up to date or is not the startup project.

enter image description here