diff --git a/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs b/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs index 4227a99ee..5d39971bb 100644 --- a/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs +++ b/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs @@ -281,55 +281,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..e57c298b4 100644 --- a/src/MSBuild.Conversion.Facts/MSBuildFacts.cs +++ b/src/MSBuild.Conversion.Facts/MSBuildFacts.cs @@ -10,17 +10,19 @@ 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( + public static ImmutableArray PropsToRemove => ImmutableArray.Create( "Microsoft.Common.props", - "MSTest.TestAdapter.props" + "MSTest.TestAdapter.props", + "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props", + "Microsoft.Net.Compilers.props" // https://stackoverflow.com/a/60623906 ); /// - /// 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( + public static ImmutableArray TargetsToRemove => ImmutableArray.Create( "Microsoft.CSharp.targets", "Microsoft.VisualBasic.targets", "Microsoft.Portable.CSharp.targets", @@ -31,6 +33,14 @@ public static class MSBuildFacts "Microsoft.WebApplication.targets" ); + /// + /// Props and targets files which are recognized and can be left unchanged during conversion. + /// + public static ImmutableArray ImportsToKeep => ImmutableArray.Create( + "Microsoft.TypeScript.Default.props", + "Microsoft.TypeScript.targets" + ); + /// /// Mapping of PCL profiles to netstandard versions. /// diff --git a/src/MSBuild.Conversion.Project/ProjectRootElementExtensionsForConversion.cs b/src/MSBuild.Conversion.Project/ProjectRootElementExtensionsForConversion.cs index 22d2999d5..cebf056f3 100644 --- a/src/MSBuild.Conversion.Project/ProjectRootElementExtensionsForConversion.cs +++ b/src/MSBuild.Conversion.Project/ProjectRootElementExtensionsForConversion.cs @@ -16,7 +16,16 @@ public static IProjectRootElement ChangeImportsAndAddSdkAttribute(this IProjectR { foreach (var import in projectRootElement.Imports) { - projectRootElement.RemoveChild(import); + var fileName = Path.GetFileName(import.Project); + if (MSBuildFacts.PropsToRemove.Contains(fileName, StringComparer.OrdinalIgnoreCase) || + MSBuildFacts.TargetsToRemove.Contains(fileName, StringComparer.OrdinalIgnoreCase)) + { + projectRootElement.RemoveChild(import); + } + else if (!MSBuildFacts.ImportsToKeep.Contains(fileName, StringComparer.OrdinalIgnoreCase)) + { + Console.WriteLine($"This project has an unrecognized custom import which may need reviewed after conversion: {fileName}"); + } } if (baselineProject.ProjectStyle is ProjectStyle.WindowsDesktop && baselineProject.TargetTFM is MSBuildFacts.NetCoreApp31)