Skip to content

Commit

Permalink
[automated] Merge branch 'release/8.0.3xx' => 'main' (#39786)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiYanni authored Apr 19, 2024
2 parents c36eda5 + a147448 commit edc51ee
Show file tree
Hide file tree
Showing 153 changed files with 3,713 additions and 391 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftNETCoreAppRefPackageVersion)"/>
<PackageVersion Include="Microsoft.FSharp.Compiler" Version="$(MicrosoftFSharpCompilerPackageVersion)" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset.Framework" Version="$(MicrosoftNetCompilersToolsetVersion)" />
<PackageVersion Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
<PackageVersion Include="Microsoft.NET.HostModel" Version="$(MicrosoftNETHostModelVersion)" />
<PackageVersion Include="Microsoft.NET.Sdk.Razor.SourceGenerators.Transport" Version="$(MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion)" />
<PackageVersion Include="Microsoft.NETCore.DotNetHostResolver" Version="$(MicrosoftNETCoreDotNetHostResolverPackageVersion)" />
Expand Down
1 change: 1 addition & 0 deletions documentation/general/workloads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Other documentation for workloads is in this repo:
- [Grouping multiple packs into one MSI](https://github.com/dotnet/sdk/issues/21741)
- [Handling workload assets across major .NET versions](cross-version-workloads.md)
- [Workload Clean Command](workload-clean.md)
- [Workload MSI Installation Tests](/test/dotnet-MsiInstallation.Tests/README.md)
7 changes: 7 additions & 0 deletions sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NET.Build.Contain
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDDLTests", "test\SDDLTests\SDDLTests.csproj", "{FEA8B7B5-901B-4A3A-948F-7E5F54F09FF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-MsiInstallation.Tests", "test\dotnet-MsiInstallation.Tests\dotnet-MsiInstallation.Tests.csproj", "{36975025-857B-45F0-AB39-904B521A6713}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compatibility", "Compatibility", "{44E564E1-AE0D-4313-A4E9-CBF2109397E3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compatibility", "Compatibility", "{3AD322BF-405B-4A53-9858-51CF66E8509F}"
Expand Down Expand Up @@ -913,6 +915,10 @@ Global
{D7495CE7-64E5-4715-9304-799A41EC1D71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7495CE7-64E5-4715-9304-799A41EC1D71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7495CE7-64E5-4715-9304-799A41EC1D71}.Release|Any CPU.Build.0 = Release|Any CPU
{36975025-857B-45F0-AB39-904B521A6713}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36975025-857B-45F0-AB39-904B521A6713}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36975025-857B-45F0-AB39-904B521A6713}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36975025-857B-45F0-AB39-904B521A6713}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1081,6 +1087,7 @@ Global
{85A01ACB-CC90-45EF-8F6C-AFC2B9F31126} = {3AD322BF-405B-4A53-9858-51CF66E8509F}
{7382A1CB-AA9A-4136-A548-17D7A67C6B0C} = {71A9F549-0EB6-41F9-BC16-4A6C5007FC91}
{D7495CE7-64E5-4715-9304-799A41EC1D71} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
{36975025-857B-45F0-AB39-904B521A6713} = {580D1AE7-AA8F-4912-8B76-105594E00B3B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FB8F26CE-4DE6-433F-B32A-79183020BBD6}
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public static class Constants
public static readonly string AnyRid = "any";

public static readonly string RestoreInteractiveOption = "--interactive";
public static readonly string workloadSetVersionFileName = "workloadVersion.txt";
}
}
24 changes: 24 additions & 0 deletions src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ public static bool TryDeleteDirectory(string directoryPath)
}
}

/// <summary>
/// Deletes the provided file. Then deletes the parent directory if empty
/// and continues to its parent until it fails. Returns whether it succeeded
/// in deleting the file it was intended to delete.
/// </summary>
public static bool DeleteFileAndEmptyParents(string path)
{
if (!File.Exists(path))
{
return false;
}

File.Delete(path);
var dir = Path.GetDirectoryName(path);

while (!Directory.EnumerateFileSystemEntries(dir).Any())
{
Directory.Delete(dir);
dir = Path.GetDirectoryName(dir);
}

return !File.Exists(path);
}

/// <summary>
/// Returns childItem relative to directory, with Path.DirectorySeparatorChar as separator
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Cli/dotnet/Installer/Windows/InstallMessageDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,21 @@ public InstallResponseMessage SendUpdateWorkloadModeRequest(SdkFeatureBand sdkFe
UseWorkloadSets = newMode,
});
}

/// <summary>
/// Send an <see cref="InstallRequestMessage"/> to adjust the workload set version used for installing and updating workloads
/// </summary>
/// <param name="sdkFeatureBand">The SDK feature band of the install state file to write</param>
/// <param name="newVersion">The workload set version</param>
/// <returns></returns>
public InstallResponseMessage SendUpdateWorkloadSetRequest(SdkFeatureBand sdkFeatureBand, string newVersion)
{
return Send(new InstallRequestMessage
{
RequestType = InstallRequestType.AdjustWorkloadSetVersion,
SdkFeatureBand = sdkFeatureBand.ToString(),
WorkloadSetVersion = newVersion,
});
}
}
}
8 changes: 8 additions & 0 deletions src/Cli/dotnet/Installer/Windows/InstallRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public bool UseWorkloadSets
get; set;
}

/// <summary>
/// The workload set version
/// </summary>
public string WorkloadSetVersion
{
get; set;
}

/// <summary>
/// Converts a deserialized array of bytes into an <see cref="InstallRequestMessage"/>.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Cli/dotnet/Installer/Windows/InstallRequestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public enum InstallRequestType
/// Changes the workload mode
/// </summary>
AdjustWorkloadMode,

/// <summary>
/// Changes the workload set version
/// </summary>
AdjustWorkloadSetVersion,
}
}
5 changes: 5 additions & 0 deletions src/Cli/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static int Main(string[] args)

bool perfLogEnabled = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_PERF_LOG", false);

if (string.IsNullOrEmpty(Env.GetEnvironmentVariable("MSBUILDFAILONDRIVEENUMERATINGWILDCARD")))
{
Environment.SetEnvironmentVariable("MSBUILDFAILONDRIVEENUMERATINGWILDCARD", "1");
}

// Avoid create temp directory with root permission and later prevent access in non sudo
if (SudoEnvironmentDirectoryOverride.IsRunningUnderSudo())
{
Expand Down
53 changes: 53 additions & 0 deletions src/Cli/dotnet/commands/InstallingWorkloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
protected readonly SdkFeatureBand _sdkFeatureBand;
protected readonly ReleaseVersion _targetSdkVersion;
protected readonly string _fromRollbackDefinition;
protected string _workloadSetVersion;
protected readonly PackageSourceLocation _packageSourceLocation;
protected readonly IWorkloadResolverFactory _workloadResolverFactory;
protected IWorkloadResolver _workloadResolver;
Expand Down Expand Up @@ -96,6 +97,53 @@ protected static Dictionary<string, string> GetInstallStateContents(IEnumerable<
manifestVersionUpdates.Select(update => new WorkloadManifestInfo(update.ManifestId.ToString(), update.NewVersion.ToString(), /* We don't actually use the directory here */ string.Empty, update.NewFeatureBand))
).ToDictionaryForJson();

public static bool ShouldUseWorkloadSetMode(SdkFeatureBand sdkFeatureBand, string dotnetDir)
{
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(sdkFeatureBand, dotnetDir), "default.json");
var installStateContents = File.Exists(path) ? InstallStateContents.FromString(File.ReadAllText(path)) : new InstallStateContents();
return installStateContents.UseWorkloadSets ?? false;
}

protected IEnumerable<ManifestVersionUpdate> HandleWorkloadUpdateFromVersion(ITransactionContext context, DirectoryPath? offlineCache)
{
// Ensure workload set mode is set to 'workloadset'
// Do not skip checking the mode first, as setting it triggers
// an admin authorization popup for MSI-based installs.
if (!ShouldUseWorkloadSetMode(_sdkFeatureBand, _dotnetPath))
{
_workloadInstaller.UpdateInstallMode(_sdkFeatureBand, true);
}

_workloadManifestUpdater.DownloadWorkloadSet(_workloadSetVersion, offlineCache);
return InstallWorkloadSet(context);
}

public IEnumerable<ManifestVersionUpdate> InstallWorkloadSet(ITransactionContext context)
{
var advertisingPackagePath = Path.Combine(_userProfileDir, "sdk-advertising", _sdkFeatureBand.ToString(), "microsoft.net.workloads");
if (File.Exists(Path.Combine(advertisingPackagePath, Constants.workloadSetVersionFileName)))
{
// This file isn't created in tests.
PrintWorkloadSetTransition(File.ReadAllText(Path.Combine(advertisingPackagePath, Constants.workloadSetVersionFileName)));
}
var workloadSetPath = _workloadInstaller.InstallWorkloadSet(context, advertisingPackagePath);
var files = Directory.EnumerateFiles(workloadSetPath, "*.workloadset.json");
return _workloadManifestUpdater.ParseRollbackDefinitionFiles(files);
}

private void PrintWorkloadSetTransition(string newVersion)
{
var currentVersion = _workloadResolver.GetWorkloadVersion();
if (currentVersion == null)
{
Reporter.WriteLine(string.Format(Strings.NewWorkloadSet, newVersion));
}
else
{
Reporter.WriteLine(string.Format(Strings.WorkloadSetUpgrade, currentVersion, newVersion));
}
}

protected async Task<List<WorkloadDownload>> GetDownloads(IEnumerable<WorkloadId> workloadIds, bool skipManifestUpdate, bool includePreview, string downloadFolder = null,
IReporter reporter = null, INuGetPackageDownloader packageDownloader = null)
{
Expand Down Expand Up @@ -204,6 +252,11 @@ internal static class InstallingWorkloadCommandParser
Hidden = true
};

public static readonly CliOption<string> WorkloadSetVersionOption = new("--version")
{
Description = Strings.WorkloadSetVersionOptionDescription
};

public static readonly CliOption<bool> PrintDownloadLinkOnlyOption = new("--print-download-link-only")
{
Description = Strings.PrintDownloadLinkOnlyDescription,
Expand Down
14 changes: 11 additions & 3 deletions src/Cli/dotnet/commands/dotnet-workload/InstallStateContents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;

#pragma warning disable CS8632

namespace Microsoft.DotNet.Workloads.Workload
{
internal class InstallStateContents
Expand All @@ -12,17 +14,21 @@ internal class InstallStateContents
public bool? UseWorkloadSets { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, string> Manifests { get; set; }
public Dictionary<string, string>? Manifests { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? WorkloadVersion { get; set; }

private static readonly JsonSerializerOptions s_options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
AllowTrailingCommas = true,
};

public static InstallStateContents FromString(string contents)
{
return JsonSerializer.Deserialize<InstallStateContents>(contents, s_options);
return JsonSerializer.Deserialize<InstallStateContents>(contents, s_options) ?? new InstallStateContents();
}

public static InstallStateContents FromPath(string path)
Expand All @@ -35,4 +41,6 @@ public override string ToString()
return JsonSerializer.Serialize<InstallStateContents>(this, s_options);
}
}
}
}

#pragma warning restore CS8632
7 changes: 4 additions & 3 deletions src/Cli/dotnet/commands/dotnet-workload/WorkloadInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class WorkloadInfoHelper : IWorkloadInfoHelper
{
public readonly SdkFeatureBand _currentSdkFeatureBand;
private readonly string _targetSdkVersion;
public string DotnetPath { get; }

public WorkloadInfoHelper(
bool isInteractive,
Expand All @@ -30,20 +31,20 @@ public WorkloadInfoHelper(
string userProfileDir = null,
IWorkloadResolver workloadResolver = null)
{
string dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
DotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
ReleaseVersion currentSdkReleaseVersion = new(currentSdkVersion ?? Product.Version);
_currentSdkFeatureBand = new SdkFeatureBand(currentSdkReleaseVersion);

_targetSdkVersion = targetSdkVersion;
userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath;
ManifestProvider =
new SdkDirectoryWorkloadManifestProvider(dotnetPath,
new SdkDirectoryWorkloadManifestProvider(DotnetPath,
string.IsNullOrWhiteSpace(_targetSdkVersion)
? currentSdkReleaseVersion.ToString()
: _targetSdkVersion,
userProfileDir, SdkDirectoryWorkloadManifestProvider.GetGlobalJsonPath(Environment.CurrentDirectory));
WorkloadResolver = workloadResolver ?? NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(
ManifestProvider, dotnetPath,
ManifestProvider, DotnetPath,
currentSdkReleaseVersion.ToString(), userProfileDir);

var restoreConfig = new RestoreActionConfig(Interactive: isInteractive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override int Execute()

private void ExecuteGarbageCollection()
{
_workloadInstaller.GarbageCollect(workloadSetVersion => _workloadResolverFactory.CreateForWorkloadSet(_dotnetPath, _sdkVersion.ToString(), _userProfileDir, workloadSetVersion),
_workloadInstaller.GarbageCollect(workloadVersion => _workloadResolverFactory.CreateForWorkloadSet(_dotnetPath, _sdkVersion.ToString(), _userProfileDir, workloadVersion),
cleanAllPacks: _cleanAll);

DisplayUninstallableVSWorkloads();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using NuGet.Common;
using NuGet.Versioning;
using static Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver;

using PathUtility = Microsoft.DotNet.Tools.Common.PathUtility;

namespace Microsoft.DotNet.Workloads.Workload.Install
{
Expand Down Expand Up @@ -85,6 +85,31 @@ IEnumerable<PackInfo> GetPacksInWorkloads(IEnumerable<WorkloadId> workloadIds)
return packs;
}

public string InstallWorkloadSet(ITransactionContext context, string advertisingPackagePath)
{
var workloadVersion = File.ReadAllText(Path.Combine(advertisingPackagePath, Constants.workloadSetVersionFileName));
var workloadSetPath = Path.Combine(_dotnetDir, "sdk-manifests", _sdkFeatureBand.ToString(), "workloadsets", workloadVersion);
context.Run(
action: () =>
{
Directory.CreateDirectory(workloadSetPath);

foreach (var file in Directory.EnumerateFiles(advertisingPackagePath))
{
File.Copy(file, Path.Combine(workloadSetPath, Path.GetFileName(file)), overwrite: true);
}
},
rollback: () =>
{
foreach (var file in Directory.EnumerateFiles(workloadSetPath))
{
PathUtility.DeleteFileAndEmptyParents(file);
}
});

return workloadSetPath;
}

public void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, ITransactionContext transactionContext, DirectoryPath? offlineCache = null)
{
var packInfos = GetPacksInWorkloads(workloadIds);
Expand Down Expand Up @@ -452,6 +477,15 @@ public void GarbageCollect(Func<string, IWorkloadResolver> getResolverForWorkloa

}

public void AdjustWorkloadSetInInstallState(SdkFeatureBand sdkFeatureBand, string workloadVersion)
{
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json");
Directory.CreateDirectory(Path.GetDirectoryName(path));
var installStateContents = InstallStateContents.FromPath(path);
installStateContents.WorkloadVersion = workloadVersion;
File.WriteAllText(path, installStateContents.ToString());
}

public void RemoveManifestsFromInstallState(SdkFeatureBand sdkFeatureBand)
{
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(_sdkFeatureBand, _dotnetDir), "default.json");
Expand Down Expand Up @@ -509,7 +543,14 @@ public void Shutdown()

public PackageId GetManifestPackageId(ManifestId manifestId, SdkFeatureBand featureBand)
{
return new PackageId($"{manifestId}.Manifest-{featureBand}");
if (manifestId.ToString().Equals("Microsoft.NET.Workloads", StringComparison.OrdinalIgnoreCase))
{
return new PackageId($"{manifestId}.{featureBand}");
}
else
{
return new PackageId($"{manifestId}.Manifest-{featureBand}");
}
}

public async Task ExtractManifestAsync(string nupkgPath, string targetPath)
Expand Down
4 changes: 4 additions & 0 deletions src/Cli/dotnet/commands/dotnet-workload/install/IInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ internal interface IInstaller : IWorkloadManifestInstaller
{
int ExitCode { get; }

string InstallWorkloadSet(ITransactionContext context, string advertisingPackagePath);

void InstallWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, ITransactionContext transactionContext, DirectoryPath? offlineCache = null);

void RepairWorkloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, DirectoryPath? offlineCache = null);
Expand All @@ -25,6 +27,8 @@ internal interface IInstaller : IWorkloadManifestInstaller

IEnumerable<WorkloadDownload> GetDownloads(IEnumerable<WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand, bool includeInstalledItems);

void AdjustWorkloadSetInInstallState(SdkFeatureBand sdkFeatureBand, string workloadVersion);

/// <summary>
/// Replace the workload resolver used by this installer. Typically used to call <see cref="GetDownloads(IEnumerable{WorkloadId}, SdkFeatureBand, bool)"/>
/// for a set of workload manifests that isn't currently installed
Expand Down
Loading

0 comments on commit edc51ee

Please sign in to comment.