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.
Extending 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 |
|
Microsoft.VisualStudio.Package.ProjectFactory |
|
Microsoft.VisualStudio.Package.HierarchyNode |
|
Microsoft.VisualStudio.Package.ProjectConfig |
|
Microsoft.VisualStudio.Package.SettingsPage |
Microsoft.VisualStudio.Package.ProjectElement class is a wrapper for MSBuild items.
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).