From d7ebacd646b025c7c7a991a0b7b887579c16ce9d Mon Sep 17 00:00:00 2001 From: Mike Rousos Date: Sun, 21 Feb 2021 20:11:03 -0500 Subject: [PATCH] Allow try-convert to run on projects with unrecognized imports --- .../MSBuildConversionWorkspace.cs | 56 ++++--------------- src/MSBuild.Conversion.Facts/MSBuildFacts.cs | 7 ++- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs b/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs index 9b5211688..f1ac5b9af 100644 --- a/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs +++ b/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs @@ -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; } } diff --git a/src/MSBuild.Conversion.Facts/MSBuildFacts.cs b/src/MSBuild.Conversion.Facts/MSBuildFacts.cs index c823a978e..7aba4ab30 100644 --- a/src/MSBuild.Conversion.Facts/MSBuildFacts.cs +++ b/src/MSBuild.Conversion.Facts/MSBuildFacts.cs @@ -10,15 +10,16 @@ namespace MSBuild.Conversion.Facts public static class MSBuildFacts { /// - /// 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. /// public static ImmutableArray PropsConvertibleToSDK => ImmutableArray.Create( "Microsoft.Common.props", - "MSTest.TestAdapter.props" + "MSTest.TestAdapter.props", + "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" ); /// - /// 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. /// public static ImmutableArray TargetsConvertibleToSDK => ImmutableArray.Create( "Microsoft.CSharp.targets",