From 88e3fe0080d1d50234beaac39b7636d022f258da Mon Sep 17 00:00:00 2001 From: Tevin Stanley Date: Wed, 7 May 2025 15:07:03 -0700 Subject: [PATCH 1/2] update with streamlined and working queries --- .../.vsextension/string-resources.json | 2 +- .../AddSolutionConfigurationCommand.cs | 7 ++++++- .../{AddFileCommand.cs => CreateFileCommand.cs} | 6 +++--- .../DeleteSolutionConfigurationCommand.cs | 7 ++++++- .../Samples/VSProjectQueryAPISample/MoveFileCommand.cs | 2 +- .../Samples/VSProjectQueryAPISample/RenameFileCommand.cs | 2 +- .../VSProjectQueryAPISample/ShowActiveProjectCommand.cs | 2 +- .../Samples/VSProjectQueryAPISample/SkipOfNCommand.cs | 2 +- .../VSProjectQueryAPISample/TrackProjectQueryCommand.cs | 2 +- .../VSProjectQueryAPISample/UnloadProjectCommand.cs | 7 ++++++- 10 files changed, 27 insertions(+), 12 deletions(-) rename New_Extensibility_Model/Samples/VSProjectQueryAPISample/{AddFileCommand.cs => CreateFileCommand.cs} (88%) diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/.vsextension/string-resources.json b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/.vsextension/string-resources.json index 3abf04ec..6a6b2767 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/.vsextension/string-resources.json +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/.vsextension/string-resources.json @@ -1,5 +1,5 @@ { - "VSProjectQueryAPISample.AddFileCommand.DisplayName": "Add File", + "VSProjectQueryAPISample.CreateFileCommand.DisplayName": "Create File", "VSProjectQueryAPISample.AddSolutionConfigurationCommand.DisplayName": "Add Solution Configuration", "VSProjectQueryAPISample.DeleteSolutionConfigurationCommand.DisplayName": "Delete Solution Configuration", "VSProjectQueryAPISample.MoveFileCommand.DisplayName": "Move File", diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddSolutionConfigurationCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddSolutionConfigurationCommand.cs index 92a69c8d..be624d62 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddSolutionConfigurationCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddSolutionConfigurationCommand.cs @@ -27,7 +27,12 @@ public class AddSolutionConfigurationCommand : Command public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { WorkspacesExtensibility querySpace = this.Extensibility.Workspaces(); - const string solutionName = "ConsoleApp32"; + + var queryResults = await querySpace.QuerySolutionAsync( + solution => solution.With(solution => solution.BaseName), + cancellationToken); + + var solutionName = queryResults.First().BaseName; await querySpace.UpdateSolutionAsync( solution => solution.Where(solution => solution.BaseName == solutionName), diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddFileCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/CreateFileCommand.cs similarity index 88% rename from New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddFileCommand.cs rename to New_Extensibility_Model/Samples/VSProjectQueryAPISample/CreateFileCommand.cs index e9e948a5..fb7bdd4f 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/AddFileCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/CreateFileCommand.cs @@ -12,10 +12,10 @@ namespace VSProjectQueryAPISample; /// A sample command for adding a file. /// [VisualStudioContribution] -public class AddFileCommand : Command +public class CreateFileCommand : Command { /// - public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.AddFileCommand.DisplayName%") + public override CommandConfiguration CommandConfiguration => new("%VSProjectQueryAPISample.CreateFileCommand.DisplayName%") { Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), @@ -28,7 +28,7 @@ public override async Task ExecuteCommandAsync(IClientContext context, Cancellat await querySpace.UpdateProjectsAsync( project => project.Where(project => project.Name == "ConsoleApp1"), - project => project.AddFile("CreatedFile.txt"), + project => project.CreateFile("CreatedFile.txt"), cancellationToken); await this.Extensibility.Shell().ShowPromptAsync("Created new file in ConsoleApp1.", PromptOptions.OK, cancellationToken); diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/DeleteSolutionConfigurationCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/DeleteSolutionConfigurationCommand.cs index 4dc61102..5e687376 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/DeleteSolutionConfigurationCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/DeleteSolutionConfigurationCommand.cs @@ -27,7 +27,12 @@ public class DeleteSolutionConfigurationCommand : Command public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) { WorkspacesExtensibility querySpace = this.Extensibility.Workspaces(); - const string solutionName = "ConsoleApp32"; + + var queryResults = await querySpace.QuerySolutionAsync( + solution => solution.With(solution => solution.BaseName), + cancellationToken); + + var solutionName = queryResults.First().BaseName; await querySpace.UpdateSolutionAsync( solution => solution.Where(solution => solution.BaseName == solutionName), diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/MoveFileCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/MoveFileCommand.cs index 0ae7b4c6..42649f20 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/MoveFileCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/MoveFileCommand.cs @@ -38,7 +38,7 @@ public MoveFileCommand(TraceSource traceSource) // Use this object initializer to set optional parameters for the command. The required parameter, // displayName, is set above. To localize the displayName, add an entry in .vsextension\string-resources.json // and reference it here by passing "%VSProjectQueryAPISample.MoveFile.DisplayName%" as a constructor parameter. - Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu], + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), }; diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/RenameFileCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/RenameFileCommand.cs index 94b1e1c0..6f927ca4 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/RenameFileCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/RenameFileCommand.cs @@ -38,7 +38,7 @@ public RenameFileCommand(TraceSource traceSource) // Use this object initializer to set optional parameters for the command. The required parameter, // displayName, is set above. To localize the displayName, add an entry in .vsextension\string-resources.json // and reference it here by passing "%VSProjectQueryAPISample.RenameFile.DisplayName%" as a constructor parameter. - Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu], + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), }; diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ShowActiveProjectCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ShowActiveProjectCommand.cs index eb72d9f6..f64c2517 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ShowActiveProjectCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ShowActiveProjectCommand.cs @@ -36,7 +36,7 @@ public ShowActiveProjectCommand(TraceSource traceSource) // Use this object initializer to set optional parameters for the command. The required parameter, // displayName, is set above. To localize the displayName, add an entry in .vsextension\string-resources.json // and reference it here by passing "%VSProjectQueryAPISample.Command1.DisplayName%" as a constructor parameter. - Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu], + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), }; diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/SkipOfNCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/SkipOfNCommand.cs index 84921263..6894a76a 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/SkipOfNCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/SkipOfNCommand.cs @@ -37,7 +37,7 @@ public SkipOfNCommand(TraceSource traceSource) // Use this object initializer to set optional parameters for the command. The required parameter, // displayName, is set above. To localize the displayName, add an entry in .vsextension\string-resources.json // and reference it here by passing "%VSProjectQueryAPISample.SkipOfNCommand.DisplayName%" as a constructor parameter. - Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu], + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), }; diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/TrackProjectQueryCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/TrackProjectQueryCommand.cs index 50d46869..25f5dcae 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/TrackProjectQueryCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/TrackProjectQueryCommand.cs @@ -36,7 +36,7 @@ public TrackProjectQueryCommand(TraceSource traceSource) // Use this object initializer to set optional parameters for the command. The required parameter, // displayName, is set above. To localize the displayName, add an entry in .vsextension\string-resources.json // and reference it here by passing "%VSProjectQueryAPISample.TrackProjectQueryCommand.DisplayName%" as a constructor parameter. - Placements = [CommandPlacement.KnownPlacements.ExtensionsMenu], + Placements = [CommandPlacement.KnownPlacements.ToolsMenu], Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText), }; diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/UnloadProjectCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/UnloadProjectCommand.cs index 85377f62..7f8a3bd0 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/UnloadProjectCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/UnloadProjectCommand.cs @@ -26,9 +26,14 @@ public override async Task ExecuteCommandAsync(IClientContext context, Cancellat { WorkspacesExtensibility querySpace = this.Extensibility.Workspaces(); - const string solutionName = "ConsoleApp32"; const string projectPath = "ConsoleApp1\\\\ConsoleApp1.csproj"; + var solutionQueryResults = await querySpace.QuerySolutionAsync( + solution => solution.With(solution => solution.BaseName), + cancellationToken); + + var solutionName = solutionQueryResults.First().BaseName; + await querySpace.UpdateSolutionAsync( solution => solution.Where(solution => solution.BaseName == solutionName), solution => solution.UnloadProject(projectPath), From 538fd78145763f601ecefa5c6e8ce86e7cfe9ca0 Mon Sep 17 00:00:00 2001 From: Tevin Stanley Date: Wed, 7 May 2025 15:46:14 -0700 Subject: [PATCH 2/2] updated small item --- .../VSProjectQueryAPISample/ReloadProjectCommand.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ReloadProjectCommand.cs b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ReloadProjectCommand.cs index 4e6b0edb..86f3cdaf 100644 --- a/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ReloadProjectCommand.cs +++ b/New_Extensibility_Model/Samples/VSProjectQueryAPISample/ReloadProjectCommand.cs @@ -26,9 +26,14 @@ public override async Task ExecuteCommandAsync(IClientContext context, Cancellat { WorkspacesExtensibility querySpace = this.Extensibility.Workspaces(); - const string solutionName = "ConsoleApp32"; const string projectPath = "ConsoleApp1\\\\ConsoleApp1.csproj"; + var solutionQueryResults = await querySpace.QuerySolutionAsync( + solution => solution.With(solution => solution.BaseName), + cancellationToken); + + var solutionName = solutionQueryResults.First().BaseName; + await querySpace.UpdateSolutionAsync( solution => solution.Where(solution => solution.BaseName == solutionName), solution => solution.ReloadProject(projectPath),