6

What we are looking for is: while compiling the same configuration, say Release|Win32, is there a way to only do the postbuild steps sometimes. Like, if I am on a dev machine do all the post-build steps or if I am on a build server then don't do them. Or is the only way to accomplish this is by implementing a new configuration?

Commenters: Thanks for the ideas, we do not want to use scripts as they would be one more thing to maintain, and going to MSBuild proj files would be a lot of headache at this point as well. Thanks for trying though.

Alex
  • 12,749
  • 3
  • 31
  • 45
  • Duplicate of http://stackoverflow.com/questions/150053/how-to-run-visual-studio-post-build-events-for-debug-build-only – JC. Mar 18 '10 at 15:25

4 Answers4

16

You could use environment variables in the post build script. Something like this:

if NOT %ComputerName% == DEVMACHINENAME GOTO end
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ngen "$(TargetPath)"
:end
Lurker Indeed
  • 1,521
  • 1
  • 12
  • 21
  • 1
    +1 This feels like the most straight forward approach to solving the problem. Let the build do it's thing, and push the conditional logic into the post build step. – Scott Saad Dec 01 '08 at 15:54
1

If you want to crack into MSBuild itself (.*proj files are essentially just MSBuild scripts), you can run machine-specific steps post-build: http://flimflan.com/blog/MachineSpecificTasksWithMSBuild.aspx

"This takes advantage of the fact that all environment variables are immediately available as properties in an MSBuild script; and that all Windows machines (that I've worked on recently) have the COMPUTERNAME environment variable set."

Chris
  • 4,030
  • 4
  • 47
  • 76
  • 1
    I'd suggest just setting a different env variable, not hard-code the scripts to specific machine names - rather set some env var like BUILD_MACHINE=TRUE and then check them. – Tim Dec 01 '08 at 15:31
0

If you don't like to have a separate build configuration (which I think would make most sense) you could e.g. define an environment variable on your build server which you then can test for in you post-build script.

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
0

Would it be possible to implement your post build steps as an external script which is always executed, but has logic to conditionally perform the steps you require?

Peter M
  • 7,309
  • 3
  • 50
  • 91