-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathUnloadProjectCommand.cs
More file actions
42 lines (34 loc) · 1.72 KB
/
UnloadProjectCommand.cs
File metadata and controls
42 lines (34 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 unloading a project.
/// </summary>
[VisualStudioContribution]
public class UnloadProjectCommand : Command
{
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.UnloadProjectCommand.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 projectPath = "ConsoleApp1\\\\ConsoleApp1.csproj";
var solutionQueryResults = await this.Extensibility.Workspaces().QuerySolutionAsync(
solution => solution.With(solution => solution.BaseName),
cancellationToken);
var solutionName = solutionQueryResults.First().BaseName;
await this.Extensibility.Workspaces().UpdateSolutionAsync(
solution => solution.Where(solution => solution.BaseName == solutionName),
solution => solution.UnloadProject(projectPath),
cancellationToken);
await this.Extensibility.Shell().ShowPromptAsync($"Unloaded a project called {projectPath} in solution {solutionName}.", PromptOptions.OK, cancellationToken);
}
}