views:

126

answers:

2

In Visual Studio, I have custom MSBuild actions for various tiers - development, staging, testing, and so on. These scripts will automatically compile everything, do web.config swapping, and push code out to a location based on the chosen configuration. Usually when I want to run one of these builds on something other than development, I call the build script from the command line.

Though I try to be as diligent as possible, sometimes myself (and others working in the solution) will accidentally leave the configuration in one they didn't mean to - maybe they switched it to the "staging" configuration to view how the code looks with its specific preprocessor directives. Then they hit "F5" thinking they're in development to debug...and push busted code out accidentally.

So the question is, is there a way to still have the build scripts tied to the configuration, but disallow builds for certain configs from the IDE? Or pop up a warning? Or am I going about this the wrong way to begin with?

A: 

Task Class for adding more control on MSBuild compile process.

Avram
+2  A: 

To have the staging build fail unless it's a Team Build, you should be able to use

<Error
  Text="No Staging builds except on the Team Build server"
  Condition=" '$(IsDesktopBuild)'=='true' And $(Configuration)='Staging' " />

CruiseControl.NET also passes distinctive properties to msbuild, so a similar idea would work with one of those in place of IsDesktopBuild.

I'm not aware of any differences in the default properties between a Visual Studio build and a command line msbuild one, but if you can bear a little extra typing, this should do the job

<Error
  Text="You didn't say the magic word"
  Condition=" '$(MagicWord)'!='please' And $(Configuration)='Staging' " />

then

msbuild /p:Configuration=Staging /p:MagicWord=please

Visual Studio won't include the extra property, so the build will fail.

stevemegson
+1 from me, we do something similar and it works well.
Si