Working with builds in Visual Studio extensions

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Here's a collection of small code samples on different ways to work with builds.

Build solution

To build the entire solution, call the BuildAsync() method.

bool buildStarted = await VS.Build.BuildSolutionAsync(BuildAction.Build);

Build project

You can build any project by passing it to the method.

Project project = await VS.Solutions.GetActiveProjectAsync();
await project.BuildAsync(BuildAction.Rebuild);

Set build property

Shows how to set a build property on the project.

Project project = await VS.Solutions.GetActiveProjectAsync();
bool succeeded = await project.TrySetAttributeAsync("propertyName", "value");

Get build property

Shows how to get a build property of any project or project item.

Project item = await VS.Solutions.GetActiveProjectAsync();
string value = await item.GetAttributeAsync("propertyName");