From 50c10decf527216b3ba2a4bb60ba9e5df6014e88 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Wed, 8 Feb 2017 00:20:04 -0800 Subject: [PATCH] Migrate compilationOptions --- .../ProjectReader.cs | 40 ++++++++++--------- .../GivenThatIWantToMigrateBuildOptions.cs | 17 ++++++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs index 7a2778d9c..298766d64 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs @@ -591,25 +591,10 @@ namespace Microsoft.DotNet.Internal.ProjectModel var rawOptions = rawObject.Value("buildOptions") as JObject; if (rawOptions == null) { - rawOptions = rawObject.Value("compilationOptions") as JObject; - if (rawOptions == null) + return new CommonCompilerOptions { - return new CommonCompilerOptions - { - CompilerName = compilerName ?? "csc" - }; - } - - var lineInfo = (IJsonLineInfo)rawOptions; - - project.Diagnostics.Add( - new DiagnosticMessage( - ErrorCodes.DOTNET1015, - $"The 'compilationOptions' option is deprecated. Use 'buildOptions' instead.", - project.ProjectFilePath, - DiagnosticMessageSeverity.Warning, - lineInfo.LineNumber, - lineInfo.LinePosition)); + CompilerName = compilerName ?? "csc" + }; } var analyzerOptionsJson = rawOptions.Value("analyzerOptions") as JObject; @@ -814,6 +799,9 @@ namespace Microsoft.DotNet.Internal.ProjectModel private static void AddProjectFilesDeprecationDiagnostics(JObject rawProject, Project project) { + var compilationOptionsWarning = "'buildOptions'"; + AddDeprecatedDiagnosticMessage(rawProject, project, "compilationOptions", compilationOptionsWarning); + var compileWarning = "'compile' in 'buildOptions'"; AddDeprecatedDiagnosticMessage(rawProject, project, "compile", compileWarning); AddDeprecatedDiagnosticMessage(rawProject, project, "compileExclude", compileWarning); @@ -870,6 +858,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel private static void ConvertDeprecatedToSupportedFormat(JObject rawProject) { + ConvertToBuildOptions(rawProject); ConvertToBuildOptionsCompile(rawProject); ConvertToBuildOptionsEmbed(rawProject); ConvertToBuildOptionsCopyToOutput(rawProject); @@ -877,6 +866,21 @@ namespace Microsoft.DotNet.Internal.ProjectModel ConvertToPublishOptions(rawProject); } + private static void ConvertToBuildOptions(JObject rawProject) + { + var jpath = "buildOptions"; + if (AreDeprecatedOptionsIgnored(rawProject, jpath)) + { + return; + } + + var deprecatedValue = rawProject.Value("compilationOptions"); + if (deprecatedValue != null) + { + rawProject["buildOptions"] = deprecatedValue.DeepClone(); + } + } + private static void ConvertToBuildOptionsCompile(JObject rawProject) { var jpath = "buildOptions.compile"; diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs index 03405bb14..ef8105572 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs @@ -16,6 +16,23 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests { public class GivenThatIWantToMigrateBuildOptions : TestBase { + [Fact] + public void MigratingDeprecatedCompilationOptionsWithEmitEntryPointPopulatesOutputTypeField() + { + var mockProj = RunBuildOptionsRuleOnPj(@" + { + ""compilationOptions"": { + ""emitEntryPoint"": ""true"" + }, + ""exclude"": [ + ""node_modules"" + ] + }"); + + mockProj.Properties.Count(p => p.Name == "OutputType").Should().Be(1); + mockProj.Properties.First(p => p.Name == "OutputType").Value.Should().Be("Exe"); + } + [Fact] public void SpecifiedDefaultPropertiesAreRemovedWhenTheyExistInTheCsprojTemplate() {