This is a mirror of official site: http://jasper-net.blogspot.com/

A guide to .vcxproj and .props file structure

| Sunday, May 16, 2010
If you inspect the contents of a .vcxproj file (the new VC++ project file format in VS2010) in notepad or in VS editor (by first unloading the project and then choosing "Edit Foo.vcxproj" from the context menu in Solution Explorer), you will see that the various top-level MSBuild elements are laid out in a particular order. Go ahead and open a .vcxproj file right now. Notice, e.g., that most of the property groups and item definition groups occur after the import for Microsoft.Cpp.Default.props. Also, all targets are imported at the end of the project file. Then there are multiple property groups - distinguished by Labels on them – and they occur in a particular order.

What is the purpose of this ordered layout? Why are there multiple property groups (import groups, etc.) instead of only one? Well, read on.

The concept of an ordered layout is a natural outcome of MSBuild’s sequential evaluation model.  If your project file consists of two definitions of a property, such as below, the last definition overrides the preceding ones. So, the value “xyz” will be used during build time.

<MyProperty>abc</MyProperty>
<MyProperty>xyz</MyProperty>

The first property definition need not necessarily be in the project file itself. You could have included it via some import that is imported before the second definition of the property. What I say about properties here is also true about item definition metadata (in general, this holds true for the entire article).

Having said that, let me now show you the layout. The following skeletal (but legal) MSBuild file captures the layout succinctly. Any .vcxproj file generated by VS will contain these top-level MSBuild elements and in this particular order (although they may contain multiple copies of each such top-level element). Note that Labels are arbitrary tags only read and written by Visual Studio and used as signposts for editing; they have no other function.

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
 <ItemGroup Label="ProjectConfigurations" />
 <PropertyGroup Label="Globals" />
 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
 <PropertyGroup Label="Configuration" />
 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
 <ImportGroup Label="ExtensionSettings" />
 <ImportGroup Label="PropertySheets" />
 <PropertyGroup Label="UserMacros" />
 <PropertyGroup />
 <ItemDefinitionGroup />
 <ItemGroup />
 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 <ImportGroup Label="ExtensionTargets" />
</Project>

Let me explain what each of these elements are and why they are ordered this way.

Read more:  The Visual Studio blog

Posted via email from jasper22's posterous

0 comments: