S h o r t S t o r i e s

// Tales from software development

How to tell if your MSBuild project is running in Visual Studio

with one comment

Steve asked me a question the other day: “What’s the name of the property that tells you if your MSBuild project is running from the Visual Studio IDE ?”

I’d forgotten its name too and it took me a while to find an example of where I’d used it. The property is called BuildingInsideVisualStudio and is set to ‘true’ when the IDE is running MSBuild.

Why would you want to know if your project is being run from the IDE ? Well, as an example, on the project that Steve and I worked on, the automated builds used the Visual Studio project files to compile the projects in one step and then executed StyleCop (now publicly available at http://code.msdn.microsoft.com/sourceanalysis) in another step. The developers had to manually execute StyleCop on their source code and sometimes forgot to do this before checking code in. Actually, the testers who were writing test automation code were the worst for forgetting to run StyleCop.

So, I modified the pre-build project to check if the BuildingInsideVisualStudio property was set to ‘true’. If it was then StyleCop was executed otherwise it wasn’t. This gave us the behaviour we wanted: StyleCop would run automatically when a project was built in the Visual Studio IDE but would not be executed when the project file was used to compile the project in our automated builds.

Advertisements

Written by Sea Monkey

November 12, 2008 at 7:45 pm

Posted in MSBuild

Tagged with

One Response

Subscribe to comments with RSS.

  1. […] IDE but it will have access to all the IDE’s build properties and items. As discussed in How to tell if your MSBuild project is running in Visual Studio, the BuildingInsideVisualStudio property may be used to determine if your build file is running as […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: