Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
edvilme committed Dec 4, 2024
1 parent edbac1e commit 9c66d13
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 9c66d13

Please sign in to comment.