Migrate compilationOptions

This commit is contained in:
Justin Goshi 2017-02-08 00:20:04 -08:00
parent d881d45b75
commit 50c10decf5
2 changed files with 39 additions and 18 deletions

View file

@ -590,9 +590,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel
var rawOptions = rawObject.Value<JToken>("buildOptions") as JObject;
if (rawOptions == null)
{
rawOptions = rawObject.Value<JToken>("compilationOptions") as JObject;
if (rawOptions == null)
{
return new CommonCompilerOptions
{
@ -600,18 +597,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel
};
}
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));
}
var analyzerOptionsJson = rawOptions.Value<JToken>("analyzerOptions") as JObject;
if (analyzerOptionsJson != null)
{
@ -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<JToken>("compilationOptions");
if (deprecatedValue != null)
{
rawProject["buildOptions"] = deprecatedValue.DeepClone();
}
}
private static void ConvertToBuildOptionsCompile(JObject rawProject)
{
var jpath = "buildOptions.compile";

View file

@ -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()
{