Skip to content

Commit 32c6ffa

Browse files
authored
Merge pull request #28668 from dotnet-maestro-bot/merge/release/7.0.1xx-to-release/7.0.2xx
[automated] Merge branch 'release/7.0.1xx' => 'release/7.0.2xx'
2 parents 4200cb1 + 2939b90 commit 32c6ffa

File tree

9 files changed

+185
-16
lines changed

9 files changed

+185
-16
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace newc;
2+
3+
static class Program
4+
{
5+
static void Main()
6+
{
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace lib;
2+
public class Class1
3+
{
4+
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<PublishSingleFile>true</PublishSingleFile>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net7.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<PublishSingleFile>true</PublishSingleFile>
10+
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="lib\lib.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.ComponentModel.DataAnnotations;
67
using System.IO;
78
using System.Linq;
89
using Microsoft.DotNet.Cli;
@@ -17,7 +18,7 @@ public class SdkDirectoryWorkloadManifestProvider : IWorkloadManifestProvider
1718
private readonly string [] _manifestDirectories;
1819
private static HashSet<string> _outdatedManifestIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "microsoft.net.workload.android", "microsoft.net.workload.blazorwebassembly", "microsoft.net.workload.ios",
1920
"microsoft.net.workload.maccatalyst", "microsoft.net.workload.macos", "microsoft.net.workload.tvos" };
20-
private readonly HashSet<string>? _knownManifestIds;
21+
private readonly Dictionary<string, int>? _knownManifestIdsAndOrder;
2122

2223
public SdkDirectoryWorkloadManifestProvider(string sdkRootPath, string sdkVersion, string? userProfileDir)
2324
: this(sdkRootPath, sdkVersion, Environment.GetEnvironmentVariable, userProfileDir)
@@ -44,7 +45,12 @@ internal SdkDirectoryWorkloadManifestProvider(string sdkRootPath, string sdkVers
4445
var knownManifestIdsFilePath = Path.Combine(_sdkRootPath, "sdk", sdkVersion, "IncludedWorkloadManifests.txt");
4546
if (File.Exists(knownManifestIdsFilePath))
4647
{
47-
_knownManifestIds = File.ReadAllLines(knownManifestIdsFilePath).Where(l => !string.IsNullOrEmpty(l)).ToHashSet();
48+
_knownManifestIdsAndOrder = new Dictionary<string, int>();
49+
int lineNumber = 0;
50+
foreach (var manifestId in File.ReadAllLines(knownManifestIdsFilePath).Where(l => !string.IsNullOrEmpty(l)))
51+
{
52+
_knownManifestIdsAndOrder[manifestId] = lineNumber++;
53+
}
4854
}
4955

5056
string? userManifestsDir = userProfileDir is null ? null : Path.Combine(userProfileDir, "sdk-manifests", _sdkVersionBand.ToString());
@@ -126,9 +132,9 @@ public IEnumerable<string> GetManifestDirectories()
126132
}
127133
}
128134

129-
if (_knownManifestIds != null && _knownManifestIds.Any(id => !manifestIdsToDirectories.ContainsKey(id)))
135+
if (_knownManifestIdsAndOrder != null && _knownManifestIdsAndOrder.Keys.Any(id => !manifestIdsToDirectories.ContainsKey(id)))
130136
{
131-
var missingManifestIds = _knownManifestIds.Where(id => !manifestIdsToDirectories.ContainsKey(id));
137+
var missingManifestIds = _knownManifestIdsAndOrder.Keys.Where(id => !manifestIdsToDirectories.ContainsKey(id));
132138
foreach (var missingManifestId in missingManifestIds)
133139
{
134140
var manifestDir = FallbackForMissingManifest(missingManifestId);
@@ -139,7 +145,21 @@ public IEnumerable<string> GetManifestDirectories()
139145
}
140146
}
141147

142-
return manifestIdsToDirectories.Values;
148+
// Return manifests in a stable order. Manifests in the IncludedWorkloadManifests.txt file will be first, and in the same order they appear in that file.
149+
// Then the rest of the manifests (if any) will be returned in (ordinal case-insensitive) alphabetical order.
150+
return manifestIdsToDirectories
151+
.OrderBy(kvp =>
152+
{
153+
if (_knownManifestIdsAndOrder != null &&
154+
_knownManifestIdsAndOrder.TryGetValue(kvp.Key, out var order))
155+
{
156+
return order;
157+
}
158+
return int.MaxValue;
159+
})
160+
.ThenBy(kvp => kvp.Key, StringComparer.OrdinalIgnoreCase)
161+
.Select(kvp => kvp.Value)
162+
.ToList();
143163
}
144164

145165
private string FallbackForMissingManifest(string manifestId)

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,20 @@ Copyright (c) .NET Foundation. All rights reserved.
6161
<RuntimeIdentifier Condition="'$(PlatformTarget)' == 'x86' or '$(PlatformTarget)' == ''">win7-x86</RuntimeIdentifier>
6262
</PropertyGroup>
6363

64-
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == 'true' or
65-
(
64+
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == ''">
65+
<UseCurrentRuntimeIdentifier Condition="
6666
'$(RuntimeIdentifier)' == '' and
67-
(
68-
'$(SelfContained)' == 'true' or
69-
'$(PublishReadyToRun)' == 'true' or
70-
'$(PublishSingleFile)' == 'true' or
71-
'$(PublishAot)' == 'true'
72-
)
73-
)">
67+
'$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and
68+
'$(IsRidAgnostic)' != 'true' and
69+
(
70+
'$(SelfContained)' == 'true' or
71+
'$(PublishReadyToRun)' == 'true' or
72+
'$(PublishSingleFile)' == 'true' or
73+
'$(PublishAot)' == 'true'
74+
)">true</UseCurrentRuntimeIdentifier>
75+
</PropertyGroup>
76+
77+
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == 'true'">
7478
<RuntimeIdentifier>$(NETCoreSdkPortableRuntimeIdentifier)</RuntimeIdentifier>
7579
</PropertyGroup>
7680

@@ -221,7 +225,7 @@ Copyright (c) .NET Foundation. All rights reserved.
221225
ResourceName="Prefer32BitIgnoredForNetCoreApp" />
222226

223227
<PropertyGroup>
224-
<Prefer32Bit>false</Prefer32Bit>
228+
<Prefer32Bit>false</Prefer32Bit>
225229
</PropertyGroup>
226230

227231
</Target>
@@ -233,7 +237,7 @@ Copyright (c) .NET Foundation. All rights reserved.
233237
<NETSdkError Condition="'$(PlatformTarget)' != 'AnyCPU' and !$(RuntimeIdentifier.ToUpperInvariant().Contains($(PlatformTarget.ToUpperInvariant())))"
234238
ResourceName="CannotHaveRuntimeIdentifierPlatformMismatchPlatformTarget"
235239
FormatArguments="$(RuntimeIdentifier);$(PlatformTarget)" />
236-
240+
237241
</Target>
238242

239243
<Target Name="_CheckForLanguageAndFeatureCombinationSupport"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.IO;
5+
using FluentAssertions;
6+
using Microsoft.NET.TestFramework;
7+
using Microsoft.NET.TestFramework.Assertions;
8+
using Microsoft.NET.TestFramework.Commands;
9+
using Xunit;
10+
using Xunit.Abstractions;
11+
12+
namespace Microsoft.NET.Publish.Tests
13+
{
14+
public class GivenThatWeWantToPublishASingleFileLibrary : SdkTest
15+
{
16+
public GivenThatWeWantToPublishASingleFileLibrary(ITestOutputHelper log) : base(log)
17+
{
18+
}
19+
20+
[WindowsOnlyFact]
21+
// Tests regression on https://github.com/dotnet/sdk/pull/28484
22+
public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary()
23+
{
24+
var targetFramework = ToolsetInfo.CurrentTargetFramework;
25+
var testAsset = _testAssetsManager
26+
.CopyTestAsset("AppWithLibrarySDKStyleThatPublishesSingleFile")
27+
.WithTargetFramework(targetFramework)
28+
.WithSource();
29+
30+
var publishCommand = new PublishCommand(testAsset);
31+
publishCommand.Execute()
32+
.Should()
33+
.Pass();
34+
35+
// It would be better if we could somehow check the library binlog or something for a RID instead.
36+
var exeFolder = publishCommand.GetOutputDirectory(targetFramework: targetFramework);
37+
// Parent: RID, then TFM, then Debug, then bin, then the test folder
38+
var ridlessLibraryDllPath = Path.Combine(exeFolder.Parent.Parent.Parent.Parent.FullName, "lib", "bin", "Debug", targetFramework, "lib.dll");
39+
Assert.True(File.Exists(ridlessLibraryDllPath));
40+
}
41+
42+
}
43+
44+
}

src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,30 @@ public void PublishWithRuntimeIdentifier(bool publishNoBuild)
194194
}
195195
}
196196

197+
[Fact]
198+
public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut()
199+
{
200+
var targetFramework = ToolsetInfo.CurrentTargetFramework;
201+
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
202+
var testProject = new TestProject()
203+
{
204+
IsExe = true,
205+
TargetFrameworks = targetFramework
206+
};
207+
testProject.AdditionalProperties["SelfContained"] = "true";
208+
testProject.AdditionalProperties["UseCurrentRuntimeIdentifier"] = "false";
209+
210+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
211+
212+
var publishCommand = new PublishCommand(testAsset);
213+
publishCommand
214+
.Execute()
215+
.Should()
216+
.Fail()
217+
.And
218+
.HaveStdOutContaining("NETSDK1191");
219+
}
220+
197221
[Fact]
198222
public void DuplicateRuntimeIdentifiers()
199223
{

src/Tests/Microsoft.NET.Sdk.WorkloadManifestReader.Tests/SdkDirectoryWorkloadManifestProviderTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,43 @@ var sdkDirectoryWorkloadManifestProvider
343343
.BeEquivalentTo("6.0.100-preview.4/iOS", "6.0.100/Android");
344344
}
345345

346+
[Fact]
347+
public void ItReturnsManifestsInOrderFromIncludedWorkloadManifestsFile()
348+
{
349+
var testDirectory = _testAssetsManager.CreateTestDirectory().Path;
350+
var fakeDotnetRootDirectory = Path.Combine(testDirectory, "dotnet");
351+
352+
// microsoft.net.workload.mono.toolchain.net6, microsoft.net.workload.mono.toolchain.net7, microsoft.net.workload.emscripten.net6, microsoft.net.workload.emscripten.net7
353+
354+
var currentSdkVersion = "7.0.100";
355+
var fallbackWorkloadBand = "7.0.100-rc.2";
356+
357+
CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "NotInIncudedWorkloadsFile");
358+
CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "Microsoft.Net.Workload.Mono.Toolchain.net6");
359+
CreateMockManifest(fakeDotnetRootDirectory, fallbackWorkloadBand, "Microsoft.Net.Workload.Mono.Toolchain.net7");
360+
CreateMockManifest(fakeDotnetRootDirectory, fallbackWorkloadBand, "Microsoft.Net.Workload.Emscripten.net6");
361+
CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "Microsoft.Net.Workload.Emscripten.net7");
362+
363+
var knownWorkloadsFilePath = Path.Combine(fakeDotnetRootDirectory, "sdk", currentSdkVersion, "IncludedWorkloadManifests.txt");
364+
Directory.CreateDirectory(Path.GetDirectoryName(knownWorkloadsFilePath)!);
365+
File.WriteAllText(knownWorkloadsFilePath, @"
366+
Microsoft.Net.Workload.Mono.Toolchain.net6
367+
Microsoft.Net.Workload.Mono.Toolchain.net7
368+
Microsoft.Net.Workload.Emscripten.net6
369+
Microsoft.Net.Workload.Emscripten.net7"
370+
.Trim());
371+
372+
var sdkDirectoryWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(sdkRootPath: fakeDotnetRootDirectory, sdkVersion: currentSdkVersion, userProfileDir: null);
373+
374+
GetManifestContents(sdkDirectoryWorkloadManifestProvider)
375+
.Should()
376+
.Equal($"{currentSdkVersion}/Microsoft.Net.Workload.Mono.Toolchain.net6",
377+
$"{fallbackWorkloadBand}/Microsoft.Net.Workload.Mono.Toolchain.net7",
378+
$"{fallbackWorkloadBand}/Microsoft.Net.Workload.Emscripten.net6",
379+
$"{currentSdkVersion}/Microsoft.Net.Workload.Emscripten.net7",
380+
$"{currentSdkVersion}/NotInIncudedWorkloadsFile");
381+
}
382+
346383
private void CreateMockManifest(string rootDir, string version, string manifestId)
347384
{
348385
var manifestDirectory = Path.Combine(rootDir, "sdk-manifests", version);

0 commit comments

Comments
 (0)