-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from microsoft/dev/jasminewoon/UpdateSample
Update ReadMe and Commands to Project Query API Sample
- Loading branch information
Showing
12 changed files
with
480 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddSolutionConfigurationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using System.Globalization; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command adding solution configurations. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class AddSolutionConfigurationCommand : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.AddSolutionConfigurationCommand.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
const string solutionName = "ConsoleApp32"; | ||
|
||
await this.Extensibility.Workspaces().UpdateSolutionAsync( | ||
solution => solution.Where(solution => solution.BaseName == solutionName), | ||
solution => solution.AddSolutionConfiguration("Foo", "Debug", false), | ||
cancellationToken); | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync($"Adding solution configuration called 'Foo'.", PromptOptions.OK, cancellationToken); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...Extensibility_Model/Samples/VSProjectQueryAPISample/DeleteSolutionConfigurationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using System.Globalization; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command deleting a solution configurations. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class DeleteSolutionConfigurationCommand : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.DeleteSolutionConfigurationCommand.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
const string solutionName = "ConsoleApp32"; | ||
|
||
await this.Extensibility.Workspaces().UpdateSolutionAsync( | ||
solution => solution.Where(solution => solution.BaseName == solutionName), | ||
solution => solution.DeleteSolutionConfiguration("Foo"), | ||
cancellationToken); | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync($"Deleting a solution configuration called 'Foo'.", PromptOptions.OK, cancellationToken); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
New_Extensibility_Model/Samples/VSProjectQueryAPISample/ProjectBuildCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command for building a project. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class ProjectBuildCommand : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.ProjectBuildCommand.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
const string projectName = "ConsoleApp1"; | ||
|
||
var result = await this.Extensibility.Workspaces().QueryProjectsAsync( | ||
project => project.Where(p => p.Name == projectName), | ||
cancellationToken); | ||
|
||
await result.First().BuildAsync(cancellationToken); | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync($"Building project {projectName}.", PromptOptions.OK, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
New_Extensibility_Model/Samples/VSProjectQueryAPISample/QuerySolutionConfigurations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using System.Globalization; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command for querying solution configurations. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class QuerySolutionConfigurations : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.QuerySolutionConfigurations.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
var results = await this.Extensibility.Workspaces().QuerySolutionAsync( | ||
solution => solution.With(solution => solution.SolutionConfigurations | ||
.With(c => c.Name)), | ||
cancellationToken); | ||
|
||
StringBuilder message = new StringBuilder(); | ||
|
||
message.Append($"\n \n === Querying Solution Configurations === \n"); | ||
|
||
foreach (var solution in results) | ||
{ | ||
foreach (var solutionConfiguration in solution.SolutionConfigurations) | ||
{ | ||
message.Append(CultureInfo.CurrentCulture, $"\t \t {solutionConfiguration.Name}\n"); | ||
} | ||
} | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync(message.ToString(), PromptOptions.OK, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
New_Extensibility_Model/Samples/VSProjectQueryAPISample/ReloadProjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command for reloading a project. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class ReloadProjectCommand : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.ReloadProjectCommand.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
const string solutionName = "ConsoleApp32"; | ||
const string projectPath = "ConsoleApp1\\\\ConsoleApp1.csproj"; | ||
|
||
await this.Extensibility.Workspaces().UpdateSolutionAsync( | ||
solution => solution.Where(solution => solution.BaseName == solutionName), | ||
solution => solution.ReloadProject(projectPath), | ||
cancellationToken); | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync($"Reloaded a project called {projectPath} in solution {solutionName}.", PromptOptions.OK, cancellationToken); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
New_Extensibility_Model/Samples/VSProjectQueryAPISample/RenameProjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace VSProjectQueryAPISample; | ||
|
||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Commands; | ||
using Microsoft.VisualStudio.Extensibility.Shell; | ||
using Microsoft.VisualStudio.ProjectSystem.Query; | ||
|
||
/// <summary> | ||
/// A sample command for renaming a project. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
public class RenameProjectCommand : Command | ||
{ | ||
/// <inheritdoc /> | ||
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.RenameProjectCommand.DisplayName%") | ||
{ | ||
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu }, | ||
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) | ||
{ | ||
var serviceBroker = context.Extensibility.ServiceBroker; | ||
ProjectQueryableSpace querySpace = new ProjectQueryableSpace(serviceBroker: serviceBroker, joinableTaskContext: null); | ||
var result = await querySpace.Projects | ||
.Where(p => p.Name == "ConsoleApp1") | ||
.AsUpdatable() | ||
.Rename("NewProjectName") | ||
.ExecuteAsync(cancellationToken); | ||
|
||
await this.Extensibility.Shell().ShowPromptAsync("Renamed Project to NewProjectName.", PromptOptions.OK, cancellationToken); | ||
} | ||
} |
Oops, something went wrong.