Skip to content

Commit bde62ca

Browse files
authored
Merge pull request #17982 from dsplaisted/include-netcore-in-runtimeconfig
Don't omit Microsoft.NETCore.App from list of frameworks in runtimeconfig
2 parents 7e3cc54 + 6c4881d commit bde62ca

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class GenerateRuntimeConfigurationFiles : TaskBase
5656

5757
public bool GenerateRuntimeConfigDevFile { get; set; }
5858

59+
public bool AlwaysIncludeCoreFramework { get; set; }
60+
5961
List<ITaskItem> _filesWritten = new List<ITaskItem>();
6062

6163
private static readonly string[] RollForwardValues = new string[]
@@ -206,14 +208,15 @@ private void AddFrameworks(RuntimeOptions runtimeOptions,
206208
HashSet<string> usedFrameworkNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
207209
foreach (var platformLibrary in runtimeFrameworks)
208210
{
209-
if (runtimeFrameworks.Length > 1 &&
211+
// In earlier versions of the SDK, we would exclude Microsoft.NETCore.App from the frameworks listed in the runtimeconfig file.
212+
// This was originally a workaround for a bug: https://github.com/dotnet/core-setup/issues/4947
213+
// We would only do this for framework-dependent apps, as the full list was required for self-contained apps.
214+
// As the bug is fixed, we now always include the Microsoft.NETCore.App framework by default for .NET Core 6 and higher
215+
if (!AlwaysIncludeCoreFramework &&
216+
runtimeFrameworks.Length > 1 &&
210217
platformLibrary.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase) &&
211218
isFrameworkDependent)
212219
{
213-
// If there are multiple runtime frameworks, then exclude Microsoft.NETCore.App,
214-
// as a workaround for https://github.com/dotnet/core-setup/issues/4947
215-
// The workaround only applies to normal framework references, included frameworks
216-
// (in self-contained apps) must list all frameworks.
217220
continue;
218221
}
219222

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Copyright (c) .NET Foundation. All rights reserved.
107107
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
108108
UserRuntimeConfig="$(UserRuntimeConfig)"
109109
WriteAdditionalProbingPathsToMainConfig="true"
110+
AlwaysIncludeCoreFramework="$(AlwaysIncludeCoreFrameworkInRuntimeConfig)"
110111
/>
111112

112113
<ItemGroup>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Copyright (c) .NET Foundation. All rights reserved.
3232
<PropertyGroup>
3333
<EnableDynamicLoading Condition="'$(EnableDynamicLoading)' == '' and '$(EnableComHosting)' == 'true'">true</EnableDynamicLoading>
3434
<GenerateRuntimeConfigurationFiles Condition=" '$(GenerateRuntimeConfigurationFiles)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and ('$(HasRuntimeOutput)' == 'true' or '$(EnableComHosting)' == 'true' or '$(EnableDynamicLoading)' == 'true') ">true</GenerateRuntimeConfigurationFiles>
35+
<AlwaysIncludeCoreFrameworkInRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">false</AlwaysIncludeCoreFrameworkInRuntimeConfig>
36+
<AlwaysIncludeCoreFrameworkInRuntimeConfig Condition="'$(AlwaysIncludeCoreFrameworkInRuntimeConfig)' == ''">true</AlwaysIncludeCoreFrameworkInRuntimeConfig>
3537
<UserRuntimeConfig Condition=" '$(UserRuntimeConfig)' == '' ">$(MSBuildProjectDirectory)/runtimeconfig.template.json</UserRuntimeConfig>
3638
<GenerateSatelliteAssembliesForCore Condition=" '$(GenerateSatelliteAssembliesForCore)' == '' and '$(MSBuildRuntimeType)' == 'Core' ">true</GenerateSatelliteAssembliesForCore>
3739
<ComputeNETCoreBuildOutputFiles Condition=" '$(ComputeNETCoreBuildOutputFiles)' == '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">true</ComputeNETCoreBuildOutputFiles>
@@ -266,7 +268,8 @@ Copyright (c) .NET Foundation. All rights reserved.
266268
AdditionalProbingPaths="@(AdditionalProbingPath)"
267269
IsSelfContained="$(SelfContained)"
268270
WriteIncludedFrameworks="$(_WriteIncludedFrameworks)"
269-
GenerateRuntimeConfigDevFile="$(GenerateRuntimeConfigDevFile)">
271+
GenerateRuntimeConfigDevFile="$(GenerateRuntimeConfigDevFile)"
272+
AlwaysIncludeCoreFramework="$(AlwaysIncludeCoreFrameworkInRuntimeConfig)">
270273

271274
</GenerateRuntimeConfigurationFiles>
272275

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ public static void Main(string [] args)
3434
}
3535
}";
3636

37-
[WindowsOnlyFact]
38-
public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_multiple_FrameworkReferences()
37+
[WindowsOnlyTheory]
38+
[InlineData("net6.0", true)]
39+
[InlineData("netcoreapp3.1", false)]
40+
public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_multiple_FrameworkReferences(string targetFramework, bool shouldIncludeBaseFramework)
3941
{
4042
var testProject = new TestProject()
4143
{
4244
Name = "MultipleFrameworkReferenceTest",
43-
TargetFrameworks = "netcoreapp3.0",
45+
TargetFrameworks = targetFramework,
4446
IsExe = true
4547
};
4648

@@ -49,7 +51,7 @@ public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_mult
4951

5052
testProject.SourceFiles.Add("Program.cs", FrameworkReferenceEmptyProgramSource);
5153

52-
var testAsset = _testAssetsManager.CreateTestProject(testProject);
54+
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework);
5355

5456
var buildCommand = new BuildCommand(testAsset);
5557

@@ -63,9 +65,14 @@ public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_mult
6365
string runtimeConfigFile = Path.Combine(outputDirectory.FullName, testProject.Name + ".runtimeconfig.json");
6466
var runtimeFrameworkNames = GetRuntimeFrameworks(runtimeConfigFile);
6567

66-
// When we remove the workaround for https://github.com/dotnet/core-setup/issues/4947 in GenerateRuntimeConfigurationFiles,
67-
// Microsoft.NETCore.App will need to be added to this list
68-
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App", "Microsoft.WindowsDesktop.App");
68+
if (shouldIncludeBaseFramework)
69+
{
70+
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App", "Microsoft.WindowsDesktop.App", "Microsoft.NETCore.App");
71+
}
72+
else
73+
{
74+
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App", "Microsoft.WindowsDesktop.App");
75+
}
6976
}
7077

7178
[Theory]
@@ -148,7 +155,7 @@ public void DuplicateFrameworksAreNotWrittenToRuntimeConfigWhenThereAreDifferent
148155
var testProject = new TestProject()
149156
{
150157
Name = "MultipleProfileFrameworkReferenceTest",
151-
TargetFrameworks = "netcoreapp3.0",
158+
TargetFrameworks = "net6.0",
152159
IsExe = true
153160
};
154161

@@ -171,9 +178,7 @@ public void DuplicateFrameworksAreNotWrittenToRuntimeConfigWhenThereAreDifferent
171178
string runtimeConfigFile = Path.Combine(outputDirectory.FullName, testProject.Name + ".runtimeconfig.json");
172179
var runtimeFrameworkNames = GetRuntimeFrameworks(runtimeConfigFile);
173180

174-
// When we remove the workaround for https://github.com/dotnet/core-setup/issues/4947 in GenerateRuntimeConfigurationFiles,
175-
// Microsoft.NETCore.App will need to be added to this list
176-
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.WindowsDesktop.App");
181+
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.WindowsDesktop.App", "Microsoft.NETCore.App");
177182
}
178183

179184
[Fact]
@@ -677,14 +682,14 @@ public void TransitiveFrameworkReferenceFromProjectReference()
677682
var testProject = new TestProject()
678683
{
679684
Name = "TransitiveFrameworkReference",
680-
TargetFrameworks = "netcoreapp3.0",
685+
TargetFrameworks = "net6.0",
681686
IsExe = true
682687
};
683688

684689
var referencedProject = new TestProject()
685690
{
686691
Name = "ReferencedProject",
687-
TargetFrameworks = "netcoreapp3.0",
692+
TargetFrameworks = "net6.0",
688693
};
689694

690695
referencedProject.FrameworkReferences.Add("Microsoft.ASPNETCORE.App");
@@ -707,7 +712,7 @@ public void TransitiveFrameworkReferenceFromProjectReference()
707712

708713
// When we remove the workaround for https://github.com/dotnet/core-setup/issues/4947 in GenerateRuntimeConfigurationFiles,
709714
// Microsoft.NETCore.App will need to be added to this list
710-
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App");
715+
runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App", "Microsoft.NETCore.App");
711716
}
712717

713718
[Fact]

0 commit comments

Comments
 (0)