Share via


Using MSBuild

MSBuild supplies a well-defined, extensible XML format for creating project files that fully describe project items to be built, build tasks, and build configurations.

For an end-to-end sample of a language project system based on MSBuild, see the IronPython sample.

General MSBuild Considerations

MSBuild project files, for example, Visual C# .csproj and Visual Basic .vbproj files, contain data that is used at build time, but also can contain data that is used at design time. Build-time data is stored using MSBuild primitives, including Item Element (MSBuild) and Property Element (MSBuild). Design-time data, which is data specific to the project type and any related project subtypes, is stored in free-form XML reserved for it.

MSBuild does not have native support for configuration objects, but does provide conditional attributes for specifying configuration-specific data. For example:

<OuputDir Condition="'$(Configuration)'=="release'">Bin\MyReleaseConfig</OutputDir>

For more information on conditional attributes, see MSBuild Conditional Constructs.

Extending MSBuild for Your Project Type

MSBuild interfaces and APIs are subject to change in future versions of Visual Basic 2008. Therefore, it is prudent to use the managed package framework (MPF) classes because they provide shielding from changes.

The project-specific MPF classes are as follows:

Class

Implementation

ProjectNode

IVsProject3

IVsCfgProvider2

IPersistFileFormat

IVsSolutionEvents

ProjectFactory

IVsProjectFactory

HierarchyNode

IVsHierarchy

ProjectConfig

IVsCfg

IVsProjectCfg

IVsBuildableProjectCfg

IVsDebuggableProjectCfg

SettingsPage

IPropertyPageSite

ProjectElement class is a wrapper for MSBuild items.

See IronPython Project System Sample for details about the IronPython integration sample's project type. By default, the source code for the IronPython project type is installed on <Visual Studio SDK installation path>\VisualStudioIntegration\Samples\IronPythonIntegration\Project. Note the folders under Templates\Projects that contain the .pyproj MSBuild file for the IronPython project type.

Single File Generators vs. MSBuild Tasks

Single file generators are accessible at design-time only, but MSBuild tasks can be used at design-time and build-time. For maximum flexibility, therefore, use MSBuild tasks to transform and generate code. For more information, see Project Items (Visual Studio SDK).

See Also

Concepts

MSBuild

Reference

ProjectNode

Other Resources

MSBuild Reference

Project Items (Visual Studio SDK)