Skip to content

Commit f713d98

Browse files
authored
[automated] Merge branch 'release/10.0.1xx' => 'main' (#50428)
2 parents 69c5225 + 65602f8 commit f713d98

File tree

9 files changed

+76
-21
lines changed

9 files changed

+76
-21
lines changed

src/Layout/pkg/windows/Directory.Build.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<!-- Example: Microsoft .NET SDK 10.0.100 -->
77
<DefineConstants>$(DefineConstants);SdkBrandName=$(SdkBrandName)</DefineConstants>
88
<!-- Example: Microsoft .NET SDK 10.0.100 (x64) -->
9-
<DefineConstants>$(DefineConstants);SdkPlatformBrandName=$(SdkBrandName) ($(TargetArchitecture))</DefineConstants>
9+
<SdkPlatformBrandName>$(SdkBrandName) ($(TargetArchitecture))</SdkPlatformBrandName>
10+
<DefineConstants>$(DefineConstants);SdkPlatformBrandName=$(SdkPlatformBrandName)</DefineConstants>
1011

1112
<!-- NativeMachine values match the expected values for image file machine constants
1213
https://docs.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants -->

src/Microsoft.CodeAnalysis.NetAnalyzers/src/RulesMissingDocumentation.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22

33
Rule ID | Missing Help Link | Title |
44
--------|-------------------|-------|
5-
CA1873 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1873> | Avoid potentially expensive logging |
6-
CA1874 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1874> | Use 'Regex.IsMatch' |
7-
CA1875 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1875> | Use 'Regex.Count' |
8-
CA2023 | <https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2023> | Invalid braces in message template |

src/Tasks/Microsoft.NET.Build.Tasks/FrameworkPackages/FrameworkPackages.netcoreapp2.0.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal static class NETCoreApp20
1414
internal static FrameworkPackages Instance { get; } = new(NetCoreApp20, FrameworkNames.NetCoreApp, NETStandard20.Instance)
1515
{
1616
{ "Microsoft.CSharp", "4.4.0" },
17-
{ "Microsoft.NETCore.App", "2.0.0" },
1817
{ "Microsoft.VisualBasic", "10.2.0" },
1918
{ "Microsoft.Win32.Registry", "4.4.0" },
2019
{ "runtime.any.System.Collections", "4.3.0" },

src/Tasks/Microsoft.NET.Build.Tasks/FrameworkPackages/FrameworkPackages.netcoreapp2.1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal static class NETCoreApp21
1414
internal static FrameworkPackages Instance { get; } = new(NetCoreApp21, FrameworkNames.NetCoreApp, NETCoreApp20.Instance)
1515
{
1616
{ "Microsoft.CSharp", "4.5.0" },
17-
{ "Microsoft.NETCore.App", "2.1.0" },
1817
{ "Microsoft.VisualBasic", "10.3.0" },
1918
{ "Microsoft.Win32.Registry", "4.5.0" },
2019
{ "System.Buffers", "4.6.1" },

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public sealed class ResolvePackageAssets : TaskBase
5555
/// </summary>
5656
public string RuntimeIdentifier { get; set; }
5757

58+
/// <summary>
59+
/// The `any` RID can be passed to indicate that the assets should be resolved as a RID-agnostic application.
60+
/// We use this field to detect that case and ensure that we treat `any` the same as no RID at all.
61+
/// Essentially, if you see use of `RuntimeIdentifier` directly, you should ask "why?".
62+
/// </summary>
63+
private string EffectiveRuntimeIdentifier => !string.IsNullOrEmpty(RuntimeIdentifier) && RuntimeIdentifier != "any" ? RuntimeIdentifier : null;
64+
5865
/// <summary>
5966
/// The platform library name for resolving copy local assets.
6067
/// </summary>
@@ -478,6 +485,8 @@ internal byte[] HashSettings()
478485
writer.Write(ProjectLanguage ?? "");
479486
writer.Write(CompilerApiVersion ?? "");
480487
writer.Write(ProjectPath);
488+
// we want to ensure uniqueness of results, so even though `any` is No RID for purposes of Task logic,
489+
// we continue to treat it distinctly for hashing
481490
writer.Write(RuntimeIdentifier ?? "");
482491
if (ShimRuntimeIdentifiers != null)
483492
{
@@ -730,7 +739,7 @@ public CacheWriter(ResolvePackageAssets task)
730739
if (task.DesignTimeBuild)
731740
{
732741
_compileTimeTarget = _lockFile.GetTargetAndReturnNullIfNotFound(_targetFramework, runtimeIdentifier: null);
733-
_runtimeTarget = _lockFile.GetTargetAndReturnNullIfNotFound(_targetFramework, _task.RuntimeIdentifier);
742+
_runtimeTarget = _lockFile.GetTargetAndReturnNullIfNotFound(_targetFramework, runtimeIdentifier: _task.EffectiveRuntimeIdentifier);
734743
if (_compileTimeTarget == null)
735744
{
736745
_compileTimeTarget = new LockFileTarget();
@@ -745,7 +754,7 @@ public CacheWriter(ResolvePackageAssets task)
745754
else
746755
{
747756
_compileTimeTarget = _lockFile.GetTargetAndThrowIfNotFound(_targetFramework, runtimeIdentifier: null);
748-
_runtimeTarget = _lockFile.GetTargetAndThrowIfNotFound(_targetFramework, _task.RuntimeIdentifier);
757+
_runtimeTarget = _lockFile.GetTargetAndThrowIfNotFound(_targetFramework, runtimeIdentifier: _task.EffectiveRuntimeIdentifier);
749758
}
750759

751760

@@ -1271,11 +1280,11 @@ private void WriteAdditionalLogMessages()
12711280

12721281
private void WriteUnsupportedRuntimeIdentifierMessageIfNecessary()
12731282
{
1274-
if (_task.EnsureRuntimePackageDependencies && !string.IsNullOrEmpty(_task.RuntimeIdentifier))
1283+
if (_task.EnsureRuntimePackageDependencies && !string.IsNullOrEmpty(_task.EffectiveRuntimeIdentifier))
12751284
{
12761285
if (_compileTimeTarget.Libraries.Count >= _runtimeTarget.Libraries.Count)
12771286
{
1278-
WriteItem(string.Format(Strings.UnsupportedRuntimeIdentifier, _task.RuntimeIdentifier));
1287+
WriteItem(string.Format(Strings.UnsupportedRuntimeIdentifier, _task.EffectiveRuntimeIdentifier));
12791288
WriteMetadata(MetadataKeys.Severity, nameof(LogLevel.Error));
12801289
}
12811290
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ Copyright (c) .NET Foundation. All rights reserved.
5252
</Target>
5353

5454
<!-- TODO: https://github.com/dotnet/sdk/issues/49917 Remove the framework based condition when the data for netcoreapp2.1 and below is fixed-->
55+
<!-- Package pruning is expected to be enable for all TFMs for multi-targeted projects, so still generate the pruning data when RestoreEnablePackagePruning is '' which implies a multi-targeted project. -->
5556
<Target Name="AddPrunePackageReferences" BeforeTargets="CollectPrunePackageReferences"
5657
DependsOnTargets="ProcessFrameworkReferences"
57-
Condition="'$(RestoreEnablePackagePruning)' == 'true'
58-
AND (('$(TargetFrameworkIdentifier)' == '.NETCoreApp'
59-
AND '$(TargetFrameworkVersion)' != ''
60-
AND $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '3.0')))
61-
OR ('$(TargetFrameworkIdentifier)' != '.NETCoreApp'))">
58+
Condition="'$(RestoreEnablePackagePruning)' == 'true' OR '$(RestoreEnablePackagePruning)' == ''">
6259
<PropertyGroup>
6360
<PrunePackageDataRoot Condition="'$(PrunePackageDataRoot)' == ''">$(NetCoreRoot)\sdk\$(NETCoreSdkVersion)\PrunePackageData\</PrunePackageDataRoot>
6461
<PrunePackageTargetingPackRoots Condition="'$(PrunePackageTargetingPackRoots)' == ''">$(NetCoreTargetingPackRoot)</PrunePackageTargetingPackRoots>

test/Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public void PackageToolWithAnyRid()
257257
// Ensure that the package with the "any" RID is present
258258
var anyRidPackage = packages.FirstOrDefault(p => p.EndsWith($"{packageIdentifier}.any.{toolSettings.ToolPackageVersion}.nupkg"));
259259
anyRidPackage.Should().NotBeNull($"Package {packageIdentifier}.any.{toolSettings.ToolPackageVersion}.nupkg should be present in the tool packages directory")
260-
.And.Satisfy<string>(EnsurePackageIsFdd);
260+
.And.Satisfy<string>(EnsurePackageIsFdd)
261+
.And.Satisfy<string>(EnsureFddPackageHasAllRuntimeAssets);
261262

262263
// top-level package should declare all of the rids
263264
var topLevelPackage = packages.First(p => p.EndsWith($"{packageIdentifier}.{toolSettings.ToolPackageVersion}.nupkg"));
@@ -387,6 +388,13 @@ static void EnsurePackageIsFdd(string packagePath)
387388
runner.Should().Be("dotnet", "The tool should be packaged as a framework-dependent executable (FDD) with a 'dotnet' runner.");
388389
}
389390

391+
static void EnsureFddPackageHasAllRuntimeAssets(string packagePath)
392+
{
393+
using var zipArchive = ZipFile.OpenRead(packagePath);
394+
var runtimesEntries = zipArchive.Entries.Select(e => e.Name.Contains("/runtimes/"));
395+
runtimesEntries.Should().NotBeNull("The runtimes-assets should be present in the package.");
396+
}
397+
390398
static void EnsurePackageHasNoRunner(string packagePath)
391399
{
392400
var settingsXml = GetToolSettingsFile(packagePath);

test/Microsoft.DotNet.PackageInstall.Tests/TestToolBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public string CreateTestTool(ITestOutputHelper log, TestToolSettings toolSetting
130130
}
131131

132132
testProject.SourceFiles.Add("Program.cs", "Console.WriteLine(\"Hello Tool!\");");
133+
testProject.PackageReferences.Add(new("Microsoft.Data.Sqlite", version: "9.0.8"));
133134

134135
var testAssetManager = new TestAssetsManager(log);
135136
var testAsset = testAssetManager.CreateTestProject(testProject, identifier: toolSettings.GetIdentifier());

test/Microsoft.NET.Build.Tests/GivenThatWeWantToResolveConflicts.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ public void PlatformPackagesCanBePruned(bool prunePackages)
320320
[InlineData("net6.0")]
321321
[InlineData("netcoreapp3.1")]
322322
[InlineData("netcoreapp3.0")]
323-
[InlineData("netcoreapp2.1", false)] //TODO: https://github.com/dotnet/sdk/issues/49917
324-
[InlineData("netcoreapp2.0", false)] //TODO: https://github.com/dotnet/sdk/issues/49917
323+
[InlineData("netcoreapp2.1")]
324+
[InlineData("netcoreapp2.0")]
325325
[InlineData("netcoreapp1.1", false)]
326326
[InlineData("netcoreapp1.0", false)]
327327
[InlineData("netstandard2.1")]
@@ -331,7 +331,9 @@ public void PlatformPackagesCanBePruned(bool prunePackages)
331331
[InlineData("net451", false)]
332332
[InlineData("net462")]
333333
[InlineData("net481")]
334-
public void PrunePackageDataSucceeds(string targetFramework, bool shouldPrune = true)
334+
[InlineData("net9.0", true, "")]
335+
[InlineData("netstandard2.1", true, "")]
336+
public void PrunePackageDataSucceeds(string targetFramework, bool shouldPrune = true, string enablePackagePruning = "True")
335337
{
336338
var nugetFramework = NuGetFramework.Parse(targetFramework);
337339

@@ -342,7 +344,7 @@ List<KeyValuePair<string,string>> GetPrunedPackages(string frameworkReference)
342344
TargetFrameworks = targetFramework
343345
};
344346

345-
testProject.AdditionalProperties["RestoreEnablePackagePruning"] = "True";
347+
testProject.AdditionalProperties["RestoreEnablePackagePruning"] = enablePackagePruning;
346348

347349
if (!string.IsNullOrEmpty(frameworkReference))
348350
{
@@ -444,6 +446,49 @@ public void TransitiveFrameworkReferencesDoNotAffectPruning()
444446

445447
}
446448

449+
[CoreMSBuildOnlyTheory]
450+
[InlineData("net10.0;net9.0", true)]
451+
[InlineData("net10.0;net8.0", true)]
452+
[InlineData("net6.0;net7.0", false)]
453+
public void WithMultitargetedProjects_PruningsDefaultsAreApplies(string frameworks, bool prunePackages)
454+
{
455+
var referencedProject = new TestProject("ReferencedProject")
456+
{
457+
TargetFrameworks = frameworks,
458+
IsExe = false
459+
};
460+
referencedProject.PackageReferences.Add(new TestPackageReference("System.Text.Json", "6.0.0"));
461+
referencedProject.AdditionalProperties["RestoreEnablePackagePruning"] = "false";
462+
463+
var testProject = new TestProject()
464+
{
465+
TargetFrameworks = frameworks,
466+
};
467+
468+
testProject.ReferencedProjects.Add(referencedProject);
469+
470+
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: prunePackages.ToString());
471+
472+
var buildCommand = new BuildCommand(testAsset);
473+
474+
buildCommand.Execute().Should().Pass();
475+
476+
var assetsFilePath = Path.Combine(buildCommand.GetBaseIntermediateDirectory().FullName, "project.assets.json");
477+
var lockFile = LockFileUtilities.GetLockFile(assetsFilePath, new NullLogger());
478+
479+
foreach(var lockFileTarget in lockFile.Targets)
480+
{
481+
if (prunePackages)
482+
{
483+
lockFileTarget.Libraries.Should().NotContain(library => library.Name.Equals("System.Text.Json", StringComparison.OrdinalIgnoreCase));
484+
}
485+
else
486+
{
487+
lockFileTarget.Libraries.Should().Contain(library => library.Name.Equals("System.Text.Json", StringComparison.OrdinalIgnoreCase));
488+
}
489+
}
490+
}
491+
447492
static List<KeyValuePair<string, string>> ParsePrunePackageReferenceJson(string json)
448493
{
449494
List<KeyValuePair<string, string>> ret = new();

0 commit comments

Comments
 (0)