Skip to content

Commit

Permalink
use a switch statement to ensure we don't miss any supported cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Dec 9, 2019
1 parent 069dcd6 commit af3ad23
Showing 1 changed file with 68 additions and 47 deletions.
115 changes: 68 additions & 47 deletions src/MSBuild.Abstractions/MSBuildWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private ProjectStyle GetProjectStyle(IProjectRootElement projectRootElement)
// It's something else, no idea what though
return ProjectStyle.Custom;
}
}
}
}
}

Expand All @@ -229,79 +229,100 @@ private bool IsSupportedProjectType(MSBuildProjectRootElement root)
// Lots of wild old project types have project type guids that the old project system uses to light things up!
if (MSBuildHelpers.HasProjectTypeGuidsNode(root))
{
// Check if it's an acceptable desktop type and reject those that aren't
if (MSBuildHelpers.IsDesktop(root))
var projectType = GetProjectSupportType(root);
switch (projectType)
{
if (!root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.AllProjectTypeGuidsAreDesktopProjectTypeGuids)))
{
case ProjectSupportType.LegacyWeb:
Console.WriteLine($"'{root.FullPath}' is a legacy web project, which is unsupported by this tool.");
return false;
case ProjectSupportType.CodedUITest:
Console.WriteLine($"'{root.FullPath}' is a coded UI test. Coded UI tests are deprecated and not convertable to .NET Core.");
return false;
case ProjectSupportType.UnknownTestProject:
Console.WriteLine($"'{root.FullPath}' has invalid Project Type Guids for test projects and is not supported.");
return false;
case ProjectSupportType.UnsupportedTestType:
Console.WriteLine($"'{root.FullPath}' is an unsupported MSTest test type. Only Unit Tests are supported.");
return false;
case ProjectSupportType.Desktop:
case ProjectSupportType.MSTest:
// Let them know about System.Web while we're here
if (MSBuildHelpers.IsProjectReferencingSystemWeb(root))
{
Console.WriteLine($"'{root.FullPath}' references System.Web, which is unsupported on .NET Core. You may have significant work remaining after conversion.");
}
return true;
case ProjectSupportType.Unsupported:
default:
var allSupportedProjectTypeGuids = DesktopFacts.KnownSupportedDesktopProjectTypeGuids.Select(ptg => ptg.ToString());
var allReadProjectTypeGuids = MSBuildHelpers.GetAllProjectTypeGuids(root);

Console.WriteLine($"{root.FullPath} is an unsupported project type. Not all project type guids are supported.");

PrintGuidMessage(allSupportedProjectTypeGuids, allReadProjectTypeGuids);

return false;
}
}
// Reject if it's a web project
}

// assume its supported
return true;

static void PrintGuidMessage(IEnumerable<string> allSupportedProjectTypeGuids, IEnumerable<string> allReadProjectTypeGuids)
{
Console.WriteLine("All supported project type guids:");
foreach (var guid in allSupportedProjectTypeGuids)
{
Console.WriteLine($"\t{guid}");
}

Console.WriteLine("All given project type guids:");
foreach (var guid in allReadProjectTypeGuids)
{
Console.WriteLine($"\t{guid}");
}
}

static ProjectSupportType GetProjectSupportType(MSBuildProjectRootElement root)
{
if (root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.AllProjectTypeGuidsAreDesktopProjectTypeGuids)))
{
return ProjectSupportType.Unsupported;
}
else if (root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.IsLegacyWebProjectTypeGuidsProperty)))
{
Console.WriteLine($"'{root.FullPath}' is a legacy web project, which is unsupported by this tool.");
return false;
return ProjectSupportType.LegacyWeb;
}
// Check if it's a valid MSTest project type.
else if (MSBuildHelpers.IsNETFrameworkMSTestProject(root))
{
if (!root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.AllProjectTypeGuidsAreLegacyTestProjectTypeGuids)))
{
Console.WriteLine($"'{root.FullPath}' has invalid Project Type Guids for test projects and is not supported.");
return false;
return ProjectSupportType.UnknownTestProject;
}

if (root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.IsCodedUITest)))
{
Console.WriteLine($"'{root.FullPath}' is a coded UI test. Coded UI tests are deprecated and not convertable to .NET Core.");
return false;
return ProjectSupportType.CodedUITest;
}

if (!root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.IsUnitTestType)))
{
Console.WriteLine($"'{root.FullPath}' is an unsupported MSTest test type. Only Unit Tests are supported.");
return false;
return ProjectSupportType.UnsupportedTestType;
}
}
// If it still has project type guids, bail if it's anything other than a language GUID because it probably wouldn't work on .NET Core
else if (!root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.AllProjectTypeGuidsAreLanguageProjectTypeGuids)))
{
Console.WriteLine($"{root.FullPath} is an unsupported project type.");
return false;
}
}

// Let them know about System.Web while we're here
if (MSBuildHelpers.IsProjectReferencingSystemWeb(root))
{
Console.WriteLine($"'{root.FullPath}' references System.Web, which is unsupported on .NET Core. You may have significant work remaining after conversion.");
}

// It's supported
return true;

static void PrintGuidMessage(IEnumerable<string> allSupportedProjectTypeGuids, IEnumerable<string> allReadProjectTypeGuids)
{
Console.WriteLine("All supported project type guids:");
foreach (var guid in allSupportedProjectTypeGuids)
{
Console.WriteLine($"\t{guid}");
return ProjectSupportType.MSTest;
}

Console.WriteLine("All given project type guids:");
foreach (var guid in allReadProjectTypeGuids)
{
Console.WriteLine($"\t{guid}");
}
return ProjectSupportType.Desktop;
}
}

private enum ProjectSupportType
{
Desktop,
LegacyWeb,
MSTest,
Unsupported,
CodedUITest,
UnsupportedTestType,
UnknownTestProject,
}
}
}

0 comments on commit af3ad23

Please sign in to comment.