Skip to content

Commit 9f45c8c

Browse files
Account for new boolean when generating runtimeconfig.dev.json (#17491)
1 parent 29de8d2 commit 9f45c8c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class GenerateRuntimeConfigurationFiles : TaskBase
5454

5555
public bool WriteIncludedFrameworks { get; set; }
5656

57+
public bool GenerateRuntimeConfigDevFile { get; set; }
58+
5759
List<ITaskItem> _filesWritten = new List<ITaskItem>();
5860

5961
private static readonly string[] RollForwardValues = new string[]
@@ -74,11 +76,12 @@ public ITaskItem[] FilesWritten
7476

7577
protected override void ExecuteCore()
7678
{
77-
bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath);
78-
7979
if (!WriteAdditionalProbingPathsToMainConfig)
8080
{
81-
if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig)
81+
// If we want to generate the runtimeconfig.dev.json file
82+
// and we have additional probing paths to add to it
83+
// BUT the runtimeconfigdevpath is empty, log a warning.
84+
if (GenerateRuntimeConfigDevFile && AdditionalProbingPaths?.Any() == true && string.IsNullOrEmpty(RuntimeConfigDevPath))
8285
{
8386
Log.LogWarning(Strings.SkippingAdditionalProbingPaths);
8487
}
@@ -138,7 +141,7 @@ protected override void ExecuteCore()
138141
projectContext.IsFrameworkDependent,
139142
projectContext.LockFile.PackageFolders);
140143

141-
if (writeDevRuntimeConfig)
144+
if (GenerateRuntimeConfigDevFile && !string.IsNullOrEmpty(RuntimeConfigDevPath))
142145
{
143146
WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders);
144147
}

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ Copyright (c) .NET Foundation. All rights reserved.
265265
HostConfigurationOptions="@(RuntimeHostConfigurationOption)"
266266
AdditionalProbingPaths="@(AdditionalProbingPath)"
267267
IsSelfContained="$(SelfContained)"
268-
WriteIncludedFrameworks="$(_WriteIncludedFrameworks)">
268+
WriteIncludedFrameworks="$(_WriteIncludedFrameworks)"
269+
GenerateRuntimeConfigDevFile="$(GenerateRuntimeConfigDevFile)">
269270

270271
</GenerateRuntimeConfigurationFiles>
271272

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,15 @@ public void It_stops_generating_runtimeconfig_dev_json_after_net6(string targetF
393393
};
394394

395395
var buildCommand = new BuildCommand(_testAssetsManager.CreateTestProject(proj, identifier: targetFramework));
396+
396397
var runtimeconfigFile = Path.Combine(
397398
buildCommand.GetOutputDirectory(targetFramework).FullName,
398399
$"{proj.Name}.runtimeconfig.dev.json");
399400

400-
buildCommand.Execute();
401+
buildCommand.Execute().StdOut
402+
.Should()
403+
.NotContain("NETSDK1048");
404+
401405
File.Exists(runtimeconfigFile).Should().Be(shouldGenerateRuntimeConfigDevJson);
402406
}
403407

@@ -423,10 +427,14 @@ public void It_stops_generating_runtimeconfig_dev_json_after_net6_allow_property
423427
$"{proj.Name}.runtimeconfig.dev.json");
424428

425429
// GenerateRuntimeConfigDevFile overrides default behavior
426-
buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=true");
430+
buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=true").StdOut
431+
.Should()
432+
.NotContain("NETSDK1048"); ;
427433
File.Exists(runtimeconfigFile).Should().BeTrue();
428434

429-
buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=false");
435+
buildCommand.Execute("/p:GenerateRuntimeConfigDevFile=false").StdOut
436+
.Should()
437+
.NotContain("NETSDK1048"); ;
430438
File.Exists(runtimeconfigFile).Should().BeFalse();
431439
}
432440

0 commit comments

Comments
 (0)