diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index 11f12fd44aef..7e9426fc6348 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 additional probing paths to add to it + // 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 && !string.IsNullOrEmpty(RuntimeConfigDevPath)) { 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(); }