From f60a853209c9a4c5154836b9caaed5634babc291 Mon Sep 17 00:00:00 2001 From: Ben Villalobos <4691428+BenVillalobos@users.noreply.github.com> Date: Wed, 5 May 2021 18:04:37 -0700 Subject: [PATCH 1/2] Account for new boolean when emitting a warning about generating runtimeconfig.dev.json file --- .../GenerateRuntimeConfigurationFiles.cs | 11 +++++++---- .../targets/Microsoft.NET.Sdk.targets | 3 ++- .../GivenThatWeWantToBuildANetCoreApp.cs | 14 +++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index 11f12fd44aef..6a452fed26e0 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs @@ -54,6 +54,8 @@ public class GenerateRuntimeConfigurationFiles : TaskBase public bool WriteIncludedFrameworks { get; set; } + public bool GenerateRuntimeConfigDevFile { get; set; } + List _filesWritten = new List(); private static readonly string[] RollForwardValues = new string[] @@ -74,11 +76,12 @@ public ITaskItem[] FilesWritten protected override void ExecuteCore() { - bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath); - if (!WriteAdditionalProbingPathsToMainConfig) { - if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig) + // If we want to generate the runtimeconfig.dev.json file + // and we have probing paths to log + // BUT the runtimeconfigdevpath is empty, log a warning. + if (GenerateRuntimeConfigDevFile && AdditionalProbingPaths?.Any() == true && string.IsNullOrEmpty(RuntimeConfigDevPath)) { Log.LogWarning(Strings.SkippingAdditionalProbingPaths); } @@ -138,7 +141,7 @@ protected override void ExecuteCore() projectContext.IsFrameworkDependent, projectContext.LockFile.PackageFolders); - if (writeDevRuntimeConfig) + if (GenerateRuntimeConfigDevFile) { WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders); } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index cc925614e349..21e423da555d 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -265,7 +265,8 @@ Copyright (c) .NET Foundation. All rights reserved. HostConfigurationOptions="@(RuntimeHostConfigurationOption)" AdditionalProbingPaths="@(AdditionalProbingPath)" IsSelfContained="$(SelfContained)" - WriteIncludedFrameworks="$(_WriteIncludedFrameworks)"> + WriteIncludedFrameworks="$(_WriteIncludedFrameworks)" + GenerateRuntimeConfigDevFile="$(GenerateRuntimeConfigDevFile)"> diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs index 15caf025efdd..6144eb5a1c58 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs @@ -393,11 +393,15 @@ public void It_stops_generating_runtimeconfig_dev_json_after_net6(string targetF }; var buildCommand = new BuildCommand(_testAssetsManager.CreateTestProject(proj, identifier: targetFramework)); + var runtimeconfigFile = Path.Combine( buildCommand.GetOutputDirectory(targetFramework).FullName, $"{proj.Name}.runtimeconfig.dev.json"); - buildCommand.Execute(); + buildCommand.Execute().StdOut + .Should() + .NotContain("NETSDK1048"); + File.Exists(runtimeconfigFile).Should().Be(shouldGenerateRuntimeConfigDevJson); } @@ -423,10 +427,14 @@ public void It_stops_generating_runtimeconfig_dev_json_after_net6_allow_property $"{proj.Name}.runtimeconfig.dev.json"); // GenerateRuntimeConfigDevFile overrides default behavior - buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=true"); + buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=true").StdOut + .Should() + .NotContain("NETSDK1048"); ; File.Exists(runtimeconfigFile).Should().BeTrue(); - buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=false"); + buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=false").StdOut + .Should() + .NotContain("NETSDK1048"); ; File.Exists(runtimeconfigFile).Should().BeFalse(); } From 274a5b6e18449a0969b7bd25447f340b861caf5f Mon Sep 17 00:00:00 2001 From: Ben Villalobos <4691428+BenVillalobos@users.noreply.github.com> Date: Tue, 11 May 2021 12:17:35 -0700 Subject: [PATCH 2/2] PR Feedback: Update comment & skip generation of dev file when path is empty --- .../GenerateRuntimeConfigurationFiles.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index 6a452fed26e0..7e9426fc6348 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs @@ -79,7 +79,7 @@ protected override void ExecuteCore() if (!WriteAdditionalProbingPathsToMainConfig) { // If we want to generate the runtimeconfig.dev.json file - // and we have probing paths to log + // and we have additional probing paths to add to it // BUT the runtimeconfigdevpath is empty, log a warning. if (GenerateRuntimeConfigDevFile && AdditionalProbingPaths?.Any() == true && string.IsNullOrEmpty(RuntimeConfigDevPath)) { @@ -141,7 +141,7 @@ protected override void ExecuteCore() projectContext.IsFrameworkDependent, projectContext.LockFile.PackageFolders); - if (GenerateRuntimeConfigDevFile) + if (GenerateRuntimeConfigDevFile && !string.IsNullOrEmpty(RuntimeConfigDevPath)) { WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders); }