Skip to content

Commit e579a10

Browse files
authored
[automated] Merge branch 'release/9.0.3xx' => 'main' (#48150)
2 parents 99fe7ae + 022df31 commit e579a10

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private static void AddProject(SolutionModel solution, string solutionRelativePr
134134
{
135135
// Open project instance to see if it is a valid project
136136
ProjectRootElement projectRootElement = ProjectRootElement.Open(fullPath);
137+
ProjectInstance projectInstance = new ProjectInstance(projectRootElement);
137138
SolutionProjectModel project;
138139
try
139140
{
@@ -142,7 +143,7 @@ private static void AddProject(SolutionModel solution, string solutionRelativePr
142143
catch (SolutionArgumentException ex) when (ex.ParamName == "projectTypeName")
143144
{
144145
// If guid is not identified by vs-solutionpersistence, check in project element itself
145-
var guid = projectRootElement.GetProjectTypeGuid();
146+
var guid = projectRootElement.GetProjectTypeGuid() ?? projectInstance.GetDefaultProjectTypeGuid();
146147
if (string.IsNullOrEmpty(guid))
147148
{
148149
Reporter.Error.WriteLine(CommonLocalizableStrings.UnsupportedProjectType, fullPath);
@@ -151,7 +152,6 @@ private static void AddProject(SolutionModel solution, string solutionRelativePr
151152
project = solution.AddProject(solutionRelativeProjectPath, guid, solutionFolder);
152153
}
153154
// Add settings based on existing project instance
154-
ProjectInstance projectInstance = new ProjectInstance(projectRootElement);
155155
string projectInstanceId = projectInstance.GetProjectId();
156156
if (!string.IsNullOrEmpty(projectInstanceId) && serializer is ISolutionSerializer<SlnV12SerializerSettings>)
157157
{

src/Cli/dotnet/Parser.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,29 @@ internal static int ExceptionHandler(Exception exception, ParseResult parseResul
221221

222222
if (exception is GracefulException)
223223
{
224-
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose
225-
? exception.ToString().Red().Bold()
226-
: exception.Message.Red().Bold());
224+
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
225+
exception.ToString().Red().Bold() :
226+
exception.Message.Red().Bold());
227227
}
228228
else if (exception is CommandParsingException)
229229
{
230-
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose
231-
? exception.ToString().Red().Bold()
232-
: exception.Message.Red().Bold());
230+
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
231+
exception.ToString().Red().Bold() :
232+
exception.Message.Red().Bold());
233233
parseResult.ShowHelp();
234234
}
235+
else if (exception.GetType().Name.Equals("WorkloadManifestCompositionException"))
236+
{
237+
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
238+
exception.ToString().Red().Bold() :
239+
exception.Message.Red().Bold());
240+
}
235241
else
236242
{
237243
Reporter.Error.Write("Unhandled exception: ".Red().Bold());
238-
Reporter.Error.WriteLine(exception.ToString().Red().Bold());
244+
Reporter.Error.WriteLine(CommandLoggingContext.IsVerbose ?
245+
exception.ToString().Red().Bold() :
246+
exception.Message.Red().Bold());
239247
}
240248

241249
return 1;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<Solution />
1+
<Solution />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26006.2
5+
MinimumVisualStudioVersion = 10.0.40219.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Solution />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<DefaultProjectTypeGuid>{2F08BC15-189B-4804-B644-653F34C968A8}</DefaultProjectTypeGuid>
5+
</PropertyGroup>
6+
7+
</Project>

test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static class ProjectTypeGuids
1919
public const string VBProjectTypeGuid = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}";
2020
public const string SolutionFolderGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}";
2121
public const string SharedProjectGuid = "{D954291E-2A0B-460D-934E-DC6B0785DB48}";
22+
public const string DefaultProjectGuid = "{130159A9-F047-44B3-88CF-0CF7F02ED50F}";
2223
}
2324

2425
public class GivenDotnetSlnAdd : SdkTest
@@ -750,13 +751,13 @@ public void WhenPassedAnUnknownProjectTypeItFails(string solutionCommand)
750751
[InlineData("sln", "SlnFileWithNoProjectReferencesAndCSharpProject", "CSharpProject", "CSharpProject.csproj", ProjectTypeGuids.CSharpProjectTypeGuid)]
751752
[InlineData("sln", "SlnFileWithNoProjectReferencesAndFSharpProject", "FSharpProject", "FSharpProject.fsproj", ProjectTypeGuids.FSharpProjectTypeGuid)]
752753
[InlineData("sln", "SlnFileWithNoProjectReferencesAndVBProject", "VBProject", "VBProject.vbproj", ProjectTypeGuids.VBProjectTypeGuid)]
753-
[InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")]
754-
[InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")]
754+
[InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", ProjectTypeGuids.DefaultProjectGuid)]
755+
[InlineData("sln", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", ProjectTypeGuids.DefaultProjectGuid)]
755756
[InlineData("solution", "SlnFileWithNoProjectReferencesAndCSharpProject", "CSharpProject", "CSharpProject.csproj", ProjectTypeGuids.CSharpProjectTypeGuid)]
756757
[InlineData("solution", "SlnFileWithNoProjectReferencesAndFSharpProject", "FSharpProject", "FSharpProject.fsproj", ProjectTypeGuids.FSharpProjectTypeGuid)]
757758
[InlineData("solution", "SlnFileWithNoProjectReferencesAndVBProject", "VBProject", "VBProject.vbproj", ProjectTypeGuids.VBProjectTypeGuid)]
758-
[InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")]
759-
[InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", "{130159A9-F047-44B3-88CF-0CF7F02ED50F}")]
759+
[InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithSingleProjectTypeGuid", "UnknownProject", "UnknownProject.unknownproj", ProjectTypeGuids.DefaultProjectGuid)]
760+
[InlineData("solution", "SlnFileWithNoProjectReferencesAndUnknownProjectWithMultipleProjectTypeGuids", "UnknownProject", "UnknownProject.unknownproj", ProjectTypeGuids.DefaultProjectGuid)]
760761
public async Task WhenPassedAProjectItAddsCorrectProjectTypeGuid(
761762
string solutionCommand,
762763
string testAsset,
@@ -789,7 +790,7 @@ public async Task WhenPassedAProjectItAddsCorrectProjectTypeGuid(
789790
[InlineData("solution", ".sln")]
790791
[InlineData("sln", ".slnx")]
791792
[InlineData("solution", ".slnx")]
792-
public void WhenPassedAProjectWithoutATypeGuidItErrors(string solutionCommand, string solutionExtension)
793+
public void WhenPassedAProjectWithoutATypeGuidNorDefaultTypeGuidItErrors(string solutionCommand, string solutionExtension)
793794
{
794795
var solutionDirectory = _testAssetsManager
795796
.CopyTestAsset("SlnFileWithNoProjectReferencesAndUnknownProjectType", identifier: $"GivenDotnetSlnAdd-{solutionCommand}{solutionExtension}")
@@ -815,6 +816,26 @@ public void WhenPassedAProjectWithoutATypeGuidItErrors(string solutionCommand, s
815816
.BeVisuallyEquivalentTo(contentBefore);
816817
}
817818

819+
[Theory]
820+
[InlineData("sln", ".sln")]
821+
[InlineData("solution", ".sln")]
822+
[InlineData("sln", ".slnx")]
823+
[InlineData("solution", ".slnx")]
824+
public void WhenPassedAProjectWithDefaultProjectGuidItPasses(string solutionCommand, string solutionExtension)
825+
{
826+
var solutionDirectory = _testAssetsManager
827+
.CopyTestAsset("TestAppWithSlnAndDefaultProjectType", identifier: $"GivenDotnetSlnAdd-{solutionCommand}{solutionExtension}")
828+
.WithSource()
829+
.Path;
830+
831+
var cmd = new DotnetCommand(Log)
832+
.WithWorkingDirectory(solutionDirectory)
833+
.Execute(solutionCommand, $"App{solutionExtension}", "add", "Unknown.unknownproj");
834+
835+
cmd.Should().Pass();
836+
cmd.StdErr.Should().BeEmpty();
837+
}
838+
818839
[Theory]
819840
[InlineData("sln", ".sln")]
820841
[InlineData("solution", ".sln")]

0 commit comments

Comments
 (0)