From 9c66d139fe7142bdc5ea10d39cc91acd43d56b41 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 2 Dec 2024 14:54:04 -0800 Subject: [PATCH] WIP --- .../dotnet/commands/dotnet-sln/remove/Program.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs b/src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs index 444b0ecd42c4..30735728740f 100644 --- a/src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs @@ -2,10 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; +using Microsoft.Build.Construction; +using Microsoft.Build.Execution; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Sln.Internal; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; +using Microsoft.Extensions.EnvironmentAbstractions; using Microsoft.VisualStudio.SolutionPersistence; using Microsoft.VisualStudio.SolutionPersistence.Model; @@ -44,7 +47,7 @@ public override int Execute() RemoveProjectsAsync(solutionFileFullPath, fullProjectPaths, CancellationToken.None).Wait(); return 0; } - catch (Exception ex) + catch (Exception ex) when (ex is not GracefulException) { throw new GracefulException(ex.Message, ex); } @@ -55,9 +58,14 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable< ISolutionSerializer serializer = SlnCommandParser.GetSolutionSerializer(solutionFileFullPath); SolutionModel solution = await serializer.OpenAsync(solutionFileFullPath, cancellationToken); - foreach (var project in projectPaths) + foreach (var projectPath in projectPaths) { - SolutionProjectModel projectModel = solution.FindProject(project); + // Open project instance to see if it is a valid project + ProjectRootElement projectRootElement = ProjectRootElement.Open(projectPath); + ProjectInstance projectInstance = new ProjectInstance(projectRootElement); + string projectInstanceId = projectInstance.GetProjectId(); + + SolutionProjectModel? projectModel = (SolutionProjectModel?) solution.FindItemById(new Guid(projectInstanceId)); solution.RemoveProject(projectModel); }