diff --git a/sdk.slnx b/sdk.slnx new file mode 100644 index 000000000000..cbd4594cef46 --- /dev/null +++ b/sdk.slnx @@ -0,0 +1,332 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Cli/Microsoft.DotNet.Cli.Sln.Internal/ProjectTypeGuids.cs b/src/Cli/Microsoft.DotNet.Cli.Sln.Internal/ProjectTypeGuids.cs index 5db6beb30ed7..772028ed2a34 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Sln.Internal/ProjectTypeGuids.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Sln.Internal/ProjectTypeGuids.cs @@ -10,5 +10,6 @@ public static class ProjectTypeGuids public const string VBProjectTypeGuid = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}"; public const string SolutionFolderGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"; public const string SharedProjectGuid = "{D954291E-2A0B-460D-934E-DC6B0785DB48}"; + public const string UnknownProjectGuid = "{130159A9-F047-44B3-88CF-0CF7F02ED50F}"; } } diff --git a/src/Cli/dotnet/commands/dotnet-sln/add/Program.cs b/src/Cli/dotnet/commands/dotnet-sln/add/Program.cs index 798e1920066a..d8754720a360 100644 --- a/src/Cli/dotnet/commands/dotnet-sln/add/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-sln/add/Program.cs @@ -79,14 +79,15 @@ private async Task AddProjectsToSolutionAsync(string solutionFileFullPath, strin foreach (var projectPath in projectPaths) { // Get full project path - var relativePath = Path.GetRelativePath(Path.GetDirectoryName(solutionFileFullPath), projectPath); + var relativePath = Path.GetRelativePath(Path.GetDirectoryName(solutionFileFullPath), projectPath); try { - solution.AddProject(relativePath, null, solutionFolder); + AddProjectToSolutionWithDefaultType(solution, relativePath, solutionFolder); Reporter.Output.WriteLine(CommonLocalizableStrings.ProjectAddedToTheSolution, relativePath); } catch (Exception ex) { + // TODO: Update with error codes from vs-solutionpersistence if (Regex.Match(ex.Message, @"Project name '.*' already exists in the solution folder\.").Success || Regex.Match(ex.Message, @"Duplicate item '.*' of type 'Project'\.").Success) { Reporter.Output.WriteLine( @@ -106,5 +107,21 @@ private string GetSolutionFolderPathWithForwardSlashes() // SolutionModel::AddFolder expects path to have leading, trailing and inner forward slashes return PathUtility.EnsureTrailingForwardSlash( PathUtility.GetPathWithForwardSlashes(Path.Join(" / ", _solutionFolderPath)) ); } + + private void AddProjectToSolutionWithDefaultType(SolutionModel solution, string relativePath, SolutionFolderModel solutionFolder) + { + try + { + solution.AddProject(relativePath, null, solutionFolder); + } + catch (ArgumentException ex) + { + // TODO: Update with error codes from vs-solutionpersistence + if (ex.Message == "ProjectType '' not found. (Parameter 'projectTypeName')") + { + solution.AddProject(relativePath, ProjectTypeGuids.UnknownProjectGuid, solutionFolder); + } + } + } } } diff --git a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs index 8c13d746f746..272b3c850c31 100644 --- a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs @@ -484,7 +484,7 @@ public void WhenInvalidSolutionIsPassedItPrintsErrorAndUsage(string solutionComm .WithWorkingDirectory(projectDirectory) .Execute(solutionCommand, "InvalidSolution.sln", "add", projectToAdd); cmd.Should().Fail(); - cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", LocalizableStrings.FileHeaderMissingError)); + cmd.StdErr.Should().Contain(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, "InvalidSolution.sln", "").TrimEnd(".")); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); } @@ -504,7 +504,7 @@ public void WhenInvalidSolutionIsFoundAddPrintsErrorAndUsage(string solutionComm .WithWorkingDirectory(projectDirectory) .Execute(solutionCommand, "add", projectToAdd); cmd.Should().Fail(); - cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionPath, LocalizableStrings.FileHeaderMissingError)); + cmd.StdErr.Should().Contain(string.Format(CommonLocalizableStrings.InvalidSolutionFormatString, solutionPath, "").TrimEnd(".")); cmd.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized(""); }