Freigeben über


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 Deep Dive in theVisual Studio Extensibility Samples.

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:

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

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

Bb166190.collapse_all(de-de,VS.110).gifExtending MSBuild for Your Project Type

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

The Managed Package Framework for Projects (MPFProj) provides helper classes for creating and managing new project system. You can find the source code and compilation instructions at MPF for Projects - Visual Studio 2010.

The project-specific MPF classes are as follows:

Class

Implementation

Microsoft.VisualStudio.Package.ProjectNode

IVsProject3

IVsCfgProvider2

IPersistFileFormat

IVsSolutionEvents

Microsoft.VisualStudio.Package.ProjectFactory

IVsProjectFactory

Microsoft.VisualStudio.Package.HierarchyNode

IVsHierarchy

Microsoft.VisualStudio.Package.ProjectConfig

IVsCfg

IVsProjectCfg

IVsBuildableProjectCfg

IVsDebuggableProjectCfg

Microsoft.VisualStudio.Package.SettingsPage

IPropertyPageSite

Microsoft.VisualStudio.Package.ProjectElement class is a wrapper for MSBuild items.

Bb166190.collapse_all(de-de,VS.110).gifSingle 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

Other Resources

MSBuild Reference

MSBuild

Project Items (Visual Studio SDK)