共用方式為


在 Visual Studio 擴充功能中使用建置

以下是有關使用組建的不同方法的小型程式碼範例集合。

建置解決方案

若要建置整個解決方案,請呼叫BuildAsync()方法

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

建置專案

您可以透過將任何專案傳遞給方法來建置任何專案。

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

設定建置屬性

示範如何在專案上設定建置屬性。

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

取得建置屬性

示範如何取得任何專案或專案項目的組建屬性。

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