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);
Pack project
SDK style .NET projects can be packed by executiong Visual Studio’s built in command. See #318.
await Package.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken);
await VS.Commands.ExecuteAsync("Build.Packselection");
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");