Goz
Goz

Reputation: 62333

Parsing VS2010 MSBuild vcxproj file

I'm currently working on a console application that will pass a vcxproj file and compile it using GCC. Unfortunately, I've come up against a whole load of problems pretty much instantly.

I notice a bunch of directory shortcuts such as:

VCTargetsPath
VCInstallDir
SolutionDir
ProjectDir
UserRootDir

and so on.

Where does MSBuild get these values from? I assumed they were environment variables set up for the MSBuild process (afterall known environment variables are addressed the same way, ie "$(...)"). This was a bad assumption so I'm left wondering exactly how I get at these. Has anyone any idea on this?

Any info would be much appreciated :)

Upvotes: 0

Views: 2579

Answers (3)

Agent_9191
Agent_9191

Reputation: 7253

The MSBuild executable (and dependent DLLs) processes those properties the same way it processes any other property in the build file. In this case, they're simply predefined properties that it looks for explicitly.

If you really want to dig into it, open up the Microsoft.Build.dll in Reflector and look for the Microsoft.Build.Construction.SolutionProjectGenerator.AddGlobalProperties(...) method to get an idea of how it's handling some of the well known properties.

As an additional note, make sure you fully navigate down Import directives and handle overwriting of property and item values with each Import. There's a number of properties and items that are part of a Visual Studio build that are not always necessary for your code to compile correctly.

Upvotes: 3

Greg Domjan
Greg Domjan

Reputation: 14125

Some of them are defined by the location of your files

  • SolutionDir - the directory containing the solution (.sln) file including this project
  • ProjectDir - the directory containing the project file (.vcproj, .vcxproj)

Others are defined by the location of the MSVC install

  • VCInstallDir - where the Visual C portion of Visual Studio is installed. ie. C:\Program Files\Microsoft Visual Studio 8\VC

and so on, and would be internal to msbuild based on what you loaded.

Upvotes: 2

PJ8
PJ8

Reputation: 1278

I believe that these are tied to Visual Studio macros: MSDN

Upvotes: 2

Related Questions