Skip to content

Commit 8b22cd9

Browse files
committed
Several other refactorings
1 parent 8d8052a commit 8b22cd9

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public override int Execute()
6161
return Directory.Exists(fullPath) ? MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName : fullPath;
6262
});
6363

64+
// Add projects to the solution
6465
AddProjectsToSolutionAsync(fullProjectPaths, CancellationToken.None).GetAwaiter().GetResult();
6566
return 0;
6667
}
@@ -120,7 +121,6 @@ private async Task AddProjectsToSolutionAsync(IEnumerable<string> projectPaths,
120121
SlnFileFactory.DefaultBuildTypes.ToList().ForEach(solution.AddBuildType);
121122
}
122123

123-
124124
foreach (var projectPath in projectPaths)
125125
{
126126
// TODO: Remove this when we have a better way to handle this
@@ -150,12 +150,12 @@ private void AddProject(SolutionModel solution, string fullProjectPath, Solution
150150
}
151151

152152
ProjectInstance projectInstance = new ProjectInstance(projectRootElement);
153-
SolutionProjectModel project;
154153

155-
// Handle guid
156154
string projectTypeGuid = solution.ProjectTypes.FirstOrDefault(t => t.Extension == Path.GetExtension(fullProjectPath))?.ProjectTypeId.ToString()
157155
?? projectRootElement.GetProjectTypeGuid() ?? projectInstance.GetDefaultProjectTypeGuid();
158156

157+
SolutionProjectModel project;
158+
159159
try
160160
{
161161
project = solution.AddProject(solutionRelativeProjectPath, projectTypeGuid, solutionFolder);
@@ -196,17 +196,7 @@ private void AddProject(SolutionModel solution, string fullProjectPath, Solution
196196
project.AddProjectConfigurationRule(new ConfigurationRule(BuildDimension.BuildType, solutionBuildType, "*", projectBuildType));
197197
}
198198

199-
// Get referencedprojects from the project instance
200-
//var referencedProjectsFullPaths = projectInstance.EvaluatedItemElements
201-
// .Where(item => item.ItemType == "ProjectReference")
202-
// .Select(item => item.Include)
203-
// .Select(item => Path.GetFullPath(item, Path.GetDirectoryName(fullProjectPath)))
204-
// .ToList();
205-
206-
//foreach (var referencedProjectFullPath in referencedProjectsFullPaths)
207-
//{
208-
// var referencedProjectRelativePath = Path.GetRelativePath(_solutionFileFullPath, referencedProjectFullPath);
209-
//}
199+
210200

211201
Reporter.Output.WriteLine(CliStrings.ProjectAddedToTheSolution, solutionRelativeProjectPath);
212202
}

src/Cli/dotnet/SlnFileFactory.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ public static SolutionModel CreateFromFileOrDirectory(string fileOrDirectory, bo
6969
}
7070
try
7171
{
72-
ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(solutionPath) ?? throw new GracefulException(
73-
CliStrings.CouldNotFindSolutionOrDirectory,
74-
solutionPath);
75-
72+
ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(solutionPath)!;
7673
return serializer.OpenAsync(solutionPath, CancellationToken.None).Result;
7774
}
78-
catch (SolutionException ex)
75+
catch (Exception ex)
7976
{
8077
throw new GracefulException(
8178
CliStrings.InvalidSolutionFormatString,

0 commit comments

Comments
 (0)