Skip to content

Commit d57cd76

Browse files
committed
WIP
1 parent 2f51829 commit d57cd76

File tree

1 file changed

+11
-3
lines changed
  • src/Cli/dotnet/commands/dotnet-sln/remove

1 file changed

+11
-3
lines changed

src/Cli/dotnet/commands/dotnet-sln/remove/Program.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5+
using Microsoft.Build.Construction;
6+
using Microsoft.Build.Execution;
57
using Microsoft.DotNet.Cli;
68
using Microsoft.DotNet.Cli.Sln.Internal;
79
using Microsoft.DotNet.Cli.Utils;
810
using Microsoft.DotNet.Tools.Common;
11+
using Microsoft.Extensions.EnvironmentAbstractions;
912
using Microsoft.VisualStudio.SolutionPersistence;
1013
using Microsoft.VisualStudio.SolutionPersistence.Model;
1114

@@ -44,7 +47,7 @@ public override int Execute()
4447
RemoveProjectsAsync(solutionFileFullPath, fullProjectPaths, CancellationToken.None).Wait();
4548
return 0;
4649
}
47-
catch (Exception ex)
50+
catch (Exception ex) when (ex is not GracefulException)
4851
{
4952
throw new GracefulException(ex.Message, ex);
5053
}
@@ -55,9 +58,14 @@ private async Task RemoveProjectsAsync(string solutionFileFullPath, IEnumerable<
5558
ISolutionSerializer serializer = SlnCommandParser.GetSolutionSerializer(solutionFileFullPath);
5659
SolutionModel solution = await serializer.OpenAsync(solutionFileFullPath, cancellationToken);
5760

58-
foreach (var project in projectPaths)
61+
foreach (var projectPath in projectPaths)
5962
{
60-
SolutionProjectModel projectModel = solution.FindProject(project);
63+
// Open project instance to see if it is a valid project
64+
ProjectRootElement projectRootElement = ProjectRootElement.Open(projectPath);
65+
ProjectInstance projectInstance = new ProjectInstance(projectRootElement);
66+
string projectInstanceId = projectInstance.GetProjectId();
67+
68+
SolutionProjectModel? projectModel = (SolutionProjectModel?) solution.FindItemById(new Guid(projectInstanceId));
6169
solution.RemoveProject(projectModel);
6270
}
6371

0 commit comments

Comments
 (0)