visual-studiorebuildbuild-events

Visual Studio 2008 Post Build event -- only run on Rebuild


In Visual Studio 2008 we run a post build event which calls NANT and in turn creates our config files.

e.g.

if $(SolutionDir) == . GOTO end
nant -buildfile:$(SolutionDir)default.build create..web.config

Is there a way to run this only on ReBuild?


Solution

  • I think you can do this by specifying build targets rather than using build events. Try creating an AfterClean target to delete your generated config files, and a BeforeBuild target to create them. Make sure you set up the file dependency for the BeforeBuild target, so msbuild knows it should only run the step if the file isn't present.

    I haven't actually tried this, but I beleive msbuild will only run the target if the target files don't exist. When you rebuild, the cleaning process will be invoked, and in turn your AfterClean target.

    You can read more about build targets here. The only real downside to using build targets instead of events is that they are not visible anywhere in the VS UI - you will only find them if you inspect the project file.

    There may be a more direct solution involving events - have look at the msbuild team blog here.