Skip to content

Commit

Permalink
Allow try-convert to run on projects with unrecognized imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mjrousos committed Feb 22, 2021
1 parent 3118d1e commit d7ebacd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 48 deletions.
56 changes: 11 additions & 45 deletions src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,55 +276,21 @@ private ProjectStyle GetProjectStyle(IProjectRootElement projectRootElement)
return ProjectStyle.Custom;
}

var cleansedImports = imports.Select(import => Path.GetFileName(import.Project));
var allImportsConvertibleToSdk =
cleansedImports.All(import =>
MSBuildFacts.PropsConvertibleToSDK.Contains(import, StringComparer.OrdinalIgnoreCase) ||
MSBuildFacts.TargetsConvertibleToSDK.Contains(import, StringComparer.OrdinalIgnoreCase));

if (allImportsConvertibleToSdk)
if (MSBuildHelpers.IsNETFrameworkMSTestProject(projectRootElement))
{
if (MSBuildHelpers.IsNETFrameworkMSTestProject(projectRootElement))
{
return ProjectStyle.MSTest;
}
else if (MSBuildHelpers.IsWPF(projectRootElement) || MSBuildHelpers.IsWinForms(projectRootElement) || MSBuildHelpers.IsDesktop(projectRootElement))
{
return ProjectStyle.WindowsDesktop;
}
else if (MSBuildHelpers.IsWeb(projectRootElement))
{
return ProjectStyle.Web;
}
else
{
return ProjectStyle.Default;
}
return ProjectStyle.MSTest;
}
else if (MSBuildHelpers.IsWPF(projectRootElement) || MSBuildHelpers.IsWinForms(projectRootElement) || MSBuildHelpers.IsDesktop(projectRootElement))
{
return ProjectStyle.WindowsDesktop;
}
else if (MSBuildHelpers.IsWeb(projectRootElement))
{
return ProjectStyle.Web;
}
else
{
Console.WriteLine("This project has custom imports that are not accepted by try-convert.");
Console.WriteLine("Unexpected custom imports were found:");

var customImports =
cleansedImports.Where(import =>
!(MSBuildFacts.PropsConvertibleToSDK.Contains(import, StringComparer.OrdinalIgnoreCase) ||
MSBuildFacts.TargetsConvertibleToSDK.Contains(import, StringComparer.OrdinalIgnoreCase)));

foreach (var import in customImports)
{
Console.WriteLine($"\t{import}");
}

Console.WriteLine("The following imports are considered valid for conversion:");

foreach (var import in MSBuildFacts.TargetsConvertibleToSDK.Union(MSBuildFacts.PropsConvertibleToSDK))
{
Console.WriteLine($"\t{import}");
}

// It's something else, no idea what though
return ProjectStyle.Custom;
return ProjectStyle.Default;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/MSBuild.Conversion.Facts/MSBuildFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ namespace MSBuild.Conversion.Facts
public static class MSBuildFacts
{
/// <summary>
/// Props files which are known to be imported in standard projects created from templates that can be converted to use the SDK
/// Props files which are known to be imported in standard projects created from templates that can be omitted from SDK projects.
/// </summary>
public static ImmutableArray<string> PropsConvertibleToSDK => ImmutableArray.Create(
"Microsoft.Common.props",
"MSTest.TestAdapter.props"
"MSTest.TestAdapter.props",
"Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props"
);

/// <summary>
/// Targets files which are known to be imported in standard projects created from templates that can be converted to use the SDK.
/// Targets files which are known to be imported in standard projects created from templates that can be omitted from SDK projects.
/// </summary>
public static ImmutableArray<string> TargetsConvertibleToSDK => ImmutableArray.Create(
"Microsoft.CSharp.targets",
Expand Down

0 comments on commit d7ebacd

Please sign in to comment.