简体   繁体   中英

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 :)

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.

我相信这些与Visual Studio宏有关: MSDN

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM