-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathQueryOutputGroupByNameCommand.cs
58 lines (48 loc) · 2.3 KB
/
QueryOutputGroupByNameCommand.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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 the project system for output groups by name.
/// </summary>
[VisualStudioContribution]
public class QueryOutputGroupByNameCommand : Command
{
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.QueryOutputGroupByNameCommand.DisplayName%")
{
Placements = [CommandPlacement.KnownPlacements.ToolsMenu],
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText),
};
/// <inheritdoc />
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
WorkspacesExtensibility querySpace = this.Extensibility.Workspaces();
var result = await querySpace.QueryProjectsAsync(
project => project.With(p => p.Name)
.With(p => p.ActiveConfigurations
.With(c => c.Name)
.With(c => c.OutputGroupsByName("Built", "XmlSerializer", "SourceFiles", "RandomNameShouldntBePickedUp")
.With(g => g.Name))),
cancellationToken);
StringBuilder message = new StringBuilder($"\n \n === Querying OutputGroups by Name === \n");
foreach (var project in result)
{
_ = message.Append(CultureInfo.CurrentCulture, $"{project.Name}\n");
foreach (var config in project.ActiveConfigurations)
{
_ = message.Append(CultureInfo.CurrentCulture, $" \t {config.Name}\n");
foreach (var group in config.OutputGroups)
{
_ = message.Append(CultureInfo.CurrentCulture, $"\t \t {group.Name}\n");
}
}
}
await this.Extensibility.Shell().ShowPromptAsync(message.ToString(), PromptOptions.OK, cancellationToken);
}
}