Skip to content

Commit

Permalink
Merge pull request #28668 from dotnet-maestro-bot/merge/release/7.0.1…
Browse files Browse the repository at this point in the history
…xx-to-release/7.0.2xx

[automated] Merge branch 'release/7.0.1xx' => 'release/7.0.2xx'
  • Loading branch information
dsplaisted authored Nov 1, 2022
2 parents 4200cb1 + 2939b90 commit 32c6ffa
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace newc;

static class Program
{
static void Main()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace lib;
public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="lib\lib.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

public SdkDirectoryWorkloadManifestProvider(string sdkRootPath, string sdkVersion, string? userProfileDir)
: this(sdkRootPath, sdkVersion, Environment.GetEnvironmentVariable, userProfileDir)
Expand All @@ -44,7 +45,12 @@ internal SdkDirectoryWorkloadManifestProvider(string sdkRootPath, string sdkVers
var knownManifestIdsFilePath = Path.Combine(_sdkRootPath, "sdk", sdkVersion, "IncludedWorkloadManifests.txt");
if (File.Exists(knownManifestIdsFilePath))
{
_knownManifestIds = File.ReadAllLines(knownManifestIdsFilePath).Where(l => !string.IsNullOrEmpty(l)).ToHashSet();
_knownManifestIdsAndOrder = new Dictionary<string, int>();
int lineNumber = 0;
foreach (var manifestId in File.ReadAllLines(knownManifestIdsFilePath).Where(l => !string.IsNullOrEmpty(l)))
{
_knownManifestIdsAndOrder[manifestId] = lineNumber++;
}
}

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

if (_knownManifestIds != null && _knownManifestIds.Any(id => !manifestIdsToDirectories.ContainsKey(id)))
if (_knownManifestIdsAndOrder != null && _knownManifestIdsAndOrder.Keys.Any(id => !manifestIdsToDirectories.ContainsKey(id)))
{
var missingManifestIds = _knownManifestIds.Where(id => !manifestIdsToDirectories.ContainsKey(id));
var missingManifestIds = _knownManifestIdsAndOrder.Keys.Where(id => !manifestIdsToDirectories.ContainsKey(id));
foreach (var missingManifestId in missingManifestIds)
{
var manifestDir = FallbackForMissingManifest(missingManifestId);
Expand All @@ -139,7 +145,21 @@ public IEnumerable<string> GetManifestDirectories()
}
}

return manifestIdsToDirectories.Values;
// 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.
// Then the rest of the manifests (if any) will be returned in (ordinal case-insensitive) alphabetical order.
return manifestIdsToDirectories
.OrderBy(kvp =>
{
if (_knownManifestIdsAndOrder != null &&
_knownManifestIdsAndOrder.TryGetValue(kvp.Key, out var order))
{
return order;
}
return int.MaxValue;
})
.ThenBy(kvp => kvp.Key, StringComparer.OrdinalIgnoreCase)
.Select(kvp => kvp.Value)
.ToList();
}

private string FallbackForMissingManifest(string manifestId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ Copyright (c) .NET Foundation. All rights reserved.
<RuntimeIdentifier Condition="'$(PlatformTarget)' == 'x86' or '$(PlatformTarget)' == ''">win7-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == 'true' or
(
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == ''">
<UseCurrentRuntimeIdentifier Condition="
'$(RuntimeIdentifier)' == '' and
(
'$(SelfContained)' == 'true' or
'$(PublishReadyToRun)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true'
)
)">
'$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and
'$(IsRidAgnostic)' != 'true' and
(
'$(SelfContained)' == 'true' or
'$(PublishReadyToRun)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true'
)">true</UseCurrentRuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == 'true'">
<RuntimeIdentifier>$(NETCoreSdkPortableRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

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

<PropertyGroup>
<Prefer32Bit>false</Prefer32Bit>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>

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

</Target>

<Target Name="_CheckForLanguageAndFeatureCombinationSupport"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.NET.Publish.Tests
{
public class GivenThatWeWantToPublishASingleFileLibrary : SdkTest
{
public GivenThatWeWantToPublishASingleFileLibrary(ITestOutputHelper log) : base(log)
{
}

[WindowsOnlyFact]
// Tests regression on https://github.com/dotnet/sdk/pull/28484
public void ItPublishesSuccessfullyWithRIDAndPublishSingleFileLibrary()
{
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var testAsset = _testAssetsManager
.CopyTestAsset("AppWithLibrarySDKStyleThatPublishesSingleFile")
.WithTargetFramework(targetFramework)
.WithSource();

var publishCommand = new PublishCommand(testAsset);
publishCommand.Execute()
.Should()
.Pass();

// It would be better if we could somehow check the library binlog or something for a RID instead.
var exeFolder = publishCommand.GetOutputDirectory(targetFramework: targetFramework);
// Parent: RID, then TFM, then Debug, then bin, then the test folder
var ridlessLibraryDllPath = Path.Combine(exeFolder.Parent.Parent.Parent.Parent.FullName, "lib", "bin", "Debug", targetFramework, "lib.dll");
Assert.True(File.Exists(ridlessLibraryDllPath));
}

}

}
24 changes: 24 additions & 0 deletions src/Tests/Microsoft.NET.Publish.Tests/RuntimeIdentifiersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ public void PublishWithRuntimeIdentifier(bool publishNoBuild)
}
}

[Fact]
public void ImplicitRuntimeIdentifierOptOutCorrecltyOptsOut()
{
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
var testProject = new TestProject()
{
IsExe = true,
TargetFrameworks = targetFramework
};
testProject.AdditionalProperties["SelfContained"] = "true";
testProject.AdditionalProperties["UseCurrentRuntimeIdentifier"] = "false";

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var publishCommand = new PublishCommand(testAsset);
publishCommand
.Execute()
.Should()
.Fail()
.And
.HaveStdOutContaining("NETSDK1191");
}

[Fact]
public void DuplicateRuntimeIdentifiers()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,43 @@ var sdkDirectoryWorkloadManifestProvider
.BeEquivalentTo("6.0.100-preview.4/iOS", "6.0.100/Android");
}

[Fact]
public void ItReturnsManifestsInOrderFromIncludedWorkloadManifestsFile()
{
var testDirectory = _testAssetsManager.CreateTestDirectory().Path;
var fakeDotnetRootDirectory = Path.Combine(testDirectory, "dotnet");

// microsoft.net.workload.mono.toolchain.net6, microsoft.net.workload.mono.toolchain.net7, microsoft.net.workload.emscripten.net6, microsoft.net.workload.emscripten.net7

var currentSdkVersion = "7.0.100";
var fallbackWorkloadBand = "7.0.100-rc.2";

CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "NotInIncudedWorkloadsFile");
CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "Microsoft.Net.Workload.Mono.Toolchain.net6");
CreateMockManifest(fakeDotnetRootDirectory, fallbackWorkloadBand, "Microsoft.Net.Workload.Mono.Toolchain.net7");
CreateMockManifest(fakeDotnetRootDirectory, fallbackWorkloadBand, "Microsoft.Net.Workload.Emscripten.net6");
CreateMockManifest(fakeDotnetRootDirectory, currentSdkVersion, "Microsoft.Net.Workload.Emscripten.net7");

var knownWorkloadsFilePath = Path.Combine(fakeDotnetRootDirectory, "sdk", currentSdkVersion, "IncludedWorkloadManifests.txt");
Directory.CreateDirectory(Path.GetDirectoryName(knownWorkloadsFilePath)!);
File.WriteAllText(knownWorkloadsFilePath, @"
Microsoft.Net.Workload.Mono.Toolchain.net6
Microsoft.Net.Workload.Mono.Toolchain.net7
Microsoft.Net.Workload.Emscripten.net6
Microsoft.Net.Workload.Emscripten.net7"
.Trim());

var sdkDirectoryWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(sdkRootPath: fakeDotnetRootDirectory, sdkVersion: currentSdkVersion, userProfileDir: null);

GetManifestContents(sdkDirectoryWorkloadManifestProvider)
.Should()
.Equal($"{currentSdkVersion}/Microsoft.Net.Workload.Mono.Toolchain.net6",
$"{fallbackWorkloadBand}/Microsoft.Net.Workload.Mono.Toolchain.net7",
$"{fallbackWorkloadBand}/Microsoft.Net.Workload.Emscripten.net6",
$"{currentSdkVersion}/Microsoft.Net.Workload.Emscripten.net7",
$"{currentSdkVersion}/NotInIncudedWorkloadsFile");
}

private void CreateMockManifest(string rootDir, string version, string manifestId)
{
var manifestDirectory = Path.Combine(rootDir, "sdk-manifests", version);
Expand Down

0 comments on commit 32c6ffa

Please sign in to comment.