Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
513a744
Refactor workload update and install commands
dsplaisted Apr 5, 2024
a571bba
Handle different workload update / install scenarios
dsplaisted Apr 10, 2024
c10f8df
Add Aspire test
dsplaisted May 13, 2024
5c6bf09
Roll back install state changes on workload install / update failures
dsplaisted May 14, 2024
b2ed34c
Fix workload set version prerelease handling
dsplaisted May 14, 2024
80557a6
Move WorkloadSetVersionToWorkloadSetPackageVersion to WorkloadSet class
dsplaisted May 14, 2024
45d2e5b
Support loading workload sets from different feature bands
dsplaisted May 14, 2024
22452a2
Fix issue where on some machines, VM snapshots couldn't be found
dsplaisted May 21, 2024
e47104b
Fix some tests not to skip manifest updates when installing workloads
dsplaisted May 21, 2024
e2b177f
Don't try to roll back installation of workload set package that wasn…
dsplaisted May 21, 2024
d316d96
Don't update pinned workload set on install, refactor InstallingWorkl…
dsplaisted May 21, 2024
768ec44
Fix some cases of pinning / unpinning workload version in global inst…
dsplaisted May 28, 2024
42019de
Add message for workload set installation failure
dsplaisted May 28, 2024
1d87f96
Remove unused isRollback parameter
dsplaisted May 28, 2024
515544c
Resolve TODOs in WorkloadInstallCommand
dsplaisted May 30, 2024
4bb9d50
Refactor ManifestVersionUpdate
dsplaisted Jun 13, 2024
d826178
Update dependencies from https://github.com/dotnet/fsharp build 20240…
dotnet-maestro[bot] Jun 26, 2024
b419c50
Update dependencies from https://github.com/dotnet/razor build 202406…
dotnet-maestro[bot] Jun 26, 2024
c01c637
[release/8.0.4xx] Update dependencies from dotnet/razor (#41807)
joeloff Jun 26, 2024
cb8ea35
[release/8.0.4xx] Update dependencies from dotnet/fsharp (#41806)
joeloff Jun 26, 2024
49a9b98
Fix tests
dsplaisted Jun 26, 2024
b1a15ae
[release/8.0.4xx] rename SDK_CONTAINER_* to DOTNET_CONTAINER (#41808)
github-actions[bot] Jun 26, 2024
0742587
Apply code review feedback
dsplaisted Jun 26, 2024
e6e20ad
Fix tests
dsplaisted Jun 26, 2024
d2f4e3a
Update dependencies from https://github.com/dotnet/templating build 2…
dotnet-maestro[bot] Jun 27, 2024
f13e440
Update dependencies from https://github.com/dotnet/roslyn build 20240…
dotnet-maestro[bot] Jun 27, 2024
f45498b
Update dependencies from https://github.com/dotnet/msbuild build 2024…
dotnet-maestro[bot] Jun 27, 2024
7f7ebc6
Update dependencies from https://github.com/dotnet/razor build 202406…
dotnet-maestro[bot] Jun 27, 2024
6ad9010
[release/8.0.4xx] Update dependencies from dotnet/razor (#41825)
joeloff Jun 27, 2024
73c3ac5
[release/8.0.4xx] Update dependencies from dotnet/templating (#41822)
joeloff Jun 27, 2024
708f383
Add tests for --skip-manifest-update, switch to robocopy for VM direc…
dsplaisted Jun 27, 2024
904eb64
Fix issue garbage collecting cross-feature band workload set, add err…
dsplaisted Jun 27, 2024
e65f698
[release/8.0.4xx] Update dependencies from dotnet/msbuild (#41824)
Jun 28, 2024
62c9743
Apply code review feedback and fix test
dsplaisted Jun 28, 2024
6625d27
[release/8.0.4xx] Update dependencies from dotnet/roslyn (#41823)
Jun 28, 2024
cc8f1ce
Update dependencies from https://github.com/dotnet/roslyn build 20240…
dotnet-maestro[bot] Jun 28, 2024
15b9293
Update dependencies from https://github.com/dotnet/fsharp build 20240…
dotnet-maestro[bot] Jun 28, 2024
b4aa6a8
Update dependencies from https://github.com/dotnet/razor build 202406…
dotnet-maestro[bot] Jun 28, 2024
86567a2
[release/8.0.4xx] Update dependencies from dotnet/razor (#41848)
joeloff Jun 28, 2024
d3dc04e
[release/8.0.4xx] Update dependencies from dotnet/fsharp (#41847)
joeloff Jun 28, 2024
d23e160
[release/8.0.4xx] Update dependencies from dotnet/roslyn (#41846)
joeloff Jun 28, 2024
4c8d4e7
Update dependencies from https://github.com/dotnet/roslyn build 20240…
dotnet-maestro[bot] Jun 29, 2024
ed6a5f5
Update dependencies from https://github.com/dotnet/fsharp build 20240…
dotnet-maestro[bot] Jun 29, 2024
6bb2e02
Update dependencies from https://github.com/nuget/nuget.client build …
dotnet-maestro[bot] Jun 29, 2024
782844e
Update dependencies from https://github.com/dotnet/arcade build 20240…
dotnet-maestro[bot] Jun 29, 2024
34a8ace
[release/8.0.4xx] Update dependencies from nuget/nuget.client (#41866)
joeloff Jun 29, 2024
3133c55
[release/8.0.4xx] Update dependencies from dotnet/fsharp (#41865)
joeloff Jun 29, 2024
ca54448
[release/8.0.4xx] Update dependencies from dotnet/roslyn (#41864)
joeloff Jun 29, 2024
f579ccd
Update dependencies from https://github.com/dotnet/arcade build 20240…
dotnet-maestro[bot] Jun 30, 2024
f9b4d89
[release/8.0.4xx] Update dependencies from dotnet/arcade (#41867)
Jul 1, 2024
979ac00
Fix combinations of workload install, global install state, and globa…
dsplaisted Jul 1, 2024
4dd638a
Update dependencies from https://github.com/dotnet/templating build 2…
dotnet-maestro[bot] Jul 1, 2024
cd61ea8
Update dependencies from https://github.com/dotnet/arcade build 20240…
dotnet-maestro[bot] Jul 1, 2024
4f90ed8
Refactor workload set and workload install/update logic (#39991)
marcpopMSFT Jul 1, 2024
e96475e
[release/8.0.4xx] Update dependencies from dotnet/templating (#41876)
joeloff Jul 1, 2024
3878491
[release/8.0.4xx] Update dependencies from dotnet/arcade (#41877)
marcpopMSFT Jul 1, 2024
777c82b
Merge branch 'release/8.0.4xx'
Jul 2, 2024
3345506
Workaround
Forgind Jul 10, 2024
f6f8c9d
Real fix
Forgind Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static bool TryDeleteDirectory(string directoryPath)
/// 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)
public static bool DeleteFileAndEmptyParents(string path, int maxDirectoriesToDelete = int.MaxValue)
{
if (!File.Exists(path))
{
Expand All @@ -112,9 +112,13 @@ public static bool DeleteFileAndEmptyParents(string path)
File.Delete(path);
var dir = Path.GetDirectoryName(path);

while (!Directory.EnumerateFileSystemEntries(dir).Any())
int directoriesDeleted = 0;

while (!Directory.EnumerateFileSystemEntries(dir).Any() &&
directoriesDeleted < maxDirectoriesToDelete)
{
Directory.Delete(dir);
directoriesDeleted++;
dir = Path.GetDirectoryName(dir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public InstallResponseMessage SendSaveInstallStateManifestVersions(SdkFeatureBan
/// <param name="sdkFeatureBand">The SDK feature band of the install state file to write</param>
/// <param name="newMode">Whether to use workload sets or not</param>
/// <returns></returns>
public InstallResponseMessage SendUpdateWorkloadModeRequest(SdkFeatureBand sdkFeatureBand, bool newMode)
public InstallResponseMessage SendUpdateWorkloadModeRequest(SdkFeatureBand sdkFeatureBand, bool? newMode)
{
return Send(new InstallRequestMessage
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Installer/Windows/InstallRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public string WorkloadId
/// <summary>
/// The new mode to use: workloadset or loosemanifests
/// </summary>
public bool UseWorkloadSets
public bool? UseWorkloadSets
{
get; set;
}
Expand Down
189 changes: 150 additions & 39 deletions src/Cli/dotnet/commands/InstallingWorkloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ToolPackage;
using Microsoft.DotNet.Workloads.Workload.Install;
using Microsoft.DotNet.Workloads.Workload.Update;
using Microsoft.Extensions.EnvironmentAbstractions;
using Microsoft.NET.Sdk.WorkloadManifestReader;
using NuGet.Versioning;
Expand All @@ -34,7 +35,8 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
protected readonly SdkFeatureBand _sdkFeatureBand;
protected readonly ReleaseVersion _targetSdkVersion;
protected readonly string _fromRollbackDefinition;
protected string _workloadSetVersion;
protected string _workloadSetVersionFromCommandLine;
protected string _globalJsonPath;
protected string _workloadSetVersionFromGlobalJson;
protected readonly PackageSourceLocation _packageSourceLocation;
protected readonly IWorkloadResolverFactory _workloadResolverFactory;
Expand All @@ -44,6 +46,10 @@ internal abstract class InstallingWorkloadCommand : WorkloadCommandBase
protected IInstaller _workloadInstaller;
protected IWorkloadManifestUpdater _workloadManifestUpdater;

protected bool UseRollback => !string.IsNullOrWhiteSpace(_fromRollbackDefinition);
protected bool SpecifiedWorkloadSetVersionOnCommandLine => !string.IsNullOrWhiteSpace(_workloadSetVersionFromCommandLine);
protected bool SpecifiedWorkloadSetVersionInGlobalJson => !string.IsNullOrWhiteSpace(_workloadSetVersionFromGlobalJson);

public InstallingWorkloadCommand(
ParseResult parseResult,
IReporter reporter,
Expand All @@ -60,6 +66,8 @@ public InstallingWorkloadCommand(
_downloadToCacheOption = parseResult.GetValue(InstallingWorkloadCommandParser.DownloadToCacheOption);

_fromRollbackDefinition = parseResult.GetValue(InstallingWorkloadCommandParser.FromRollbackFileOption);
_workloadSetVersionFromCommandLine = parseResult.GetValue(InstallingWorkloadCommandParser.WorkloadSetVersionOption);

var configOption = parseResult.GetValue(InstallingWorkloadCommandParser.ConfigOption);
var sourceOption = parseResult.GetValue(InstallingWorkloadCommandParser.SourceOption);
_packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null :
Expand Down Expand Up @@ -91,70 +99,162 @@ public InstallingWorkloadCommand(

_workloadInstallerFromConstructor = workloadInstaller;
_workloadManifestUpdaterFromConstructor = workloadManifestUpdater;

_globalJsonPath = SdkDirectoryWorkloadManifestProvider.GetGlobalJsonPath(Environment.CurrentDirectory);
_workloadSetVersionFromGlobalJson = SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.GetWorkloadVersionFromGlobalJson(_globalJsonPath);

if (SpecifiedWorkloadSetVersionInGlobalJson && (SpecifiedWorkloadSetVersionOnCommandLine || UseRollback))
{
throw new GracefulException(string.Format(Strings.CannotSpecifyVersionOnCommandLineAndInGlobalJson, _globalJsonPath), isUserError: true);
}

if (SpecifiedWorkloadSetVersionOnCommandLine && UseRollback)
{
throw new GracefulException(string.Format(Update.LocalizableStrings.CannotCombineOptions,
InstallingWorkloadCommandParser.FromRollbackFileOption.Name,
InstallingWorkloadCommandParser.WorkloadSetVersionOption.Name), isUserError: true);
}

// At this point, at most one of SpecifiedWorkloadSetVersionOnCommandLine, UseRollback, and SpecifiedWorkloadSetVersionInGlobalJson is true
}

protected static Dictionary<string, string> GetInstallStateContents(IEnumerable<ManifestVersionUpdate> manifestVersionUpdates) =>
WorkloadSet.FromManifests(
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)
InstallStateContents GetCurrentInstallState()
{
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;
return GetCurrentInstallState(_sdkFeatureBand, _dotnetPath);
}

protected void ErrorIfGlobalJsonAndCommandLineMismatch(string globaljsonPath)
static InstallStateContents GetCurrentInstallState(SdkFeatureBand sdkFeatureBand, string dotnetDir)
{
if (!string.IsNullOrWhiteSpace(_workloadSetVersionFromGlobalJson) && !string.IsNullOrWhiteSpace(_workloadSetVersion) && !_workloadSetVersion.Equals(_workloadSetVersionFromGlobalJson))
{
throw new Exception(string.Format(Strings.CannotSpecifyVersionOnCommandLineAndInGlobalJson, globaljsonPath));
}
string path = Path.Combine(WorkloadInstallType.GetInstallStateFolder(sdkFeatureBand, dotnetDir), "default.json");
return InstallStateContents.FromPath(path);
}

protected bool TryHandleWorkloadUpdateFromVersion(ITransactionContext context, DirectoryPath? offlineCache, out IEnumerable<ManifestVersionUpdate> updates)
public static bool ShouldUseWorkloadSetMode(SdkFeatureBand sdkFeatureBand, string dotnetDir)
{
// 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(_workloadSetVersionFromGlobalJson ?? _workloadSetVersion, offlineCache);
return TryInstallWorkloadSet(context, out updates, throwOnFailure: true);
return GetCurrentInstallState(sdkFeatureBand, dotnetDir).UseWorkloadSets ?? false;
}

public bool TryInstallWorkloadSet(ITransactionContext context, out IEnumerable<ManifestVersionUpdate> updates, bool throwOnFailure = false)
protected void UpdateWorkloadManifests(ITransactionContext context, DirectoryPath? offlineCache)
{
var advertisingPackagePath = Path.Combine(_userProfileDir, "sdk-advertising", _sdkFeatureBand.ToString(), "microsoft.net.workloads");
if (File.Exists(Path.Combine(advertisingPackagePath, Constants.workloadSetVersionFileName)))
var updateToLatestWorkloadSet = ShouldUseWorkloadSetMode(_sdkFeatureBand, _dotnetPath);
if (UseRollback && updateToLatestWorkloadSet)
{
// This file isn't created in tests.
var version = File.ReadAllText(Path.Combine(advertisingPackagePath, Constants.workloadSetVersionFileName));
PrintWorkloadSetTransition(version);
// Rollback files are only for loose manifests. Update the mode to be loose manifests.
Reporter.WriteLine(Update.LocalizableStrings.UpdateFromRollbackSwitchesModeToLooseManifests);
_workloadInstaller.UpdateInstallMode(_sdkFeatureBand, false);
updateToLatestWorkloadSet = false;
}
else if (_workloadInstaller is FileBasedInstaller || _workloadInstaller is NetSdkMsiInstallerClient)

if (SpecifiedWorkloadSetVersionOnCommandLine)
{
// No workload sets found
if (throwOnFailure)
updateToLatestWorkloadSet = false;

// If a workload set version is specified, then switch to workload set update mode
// Check to make sure the value needs to be changed, as updating triggers a UAC prompt
// for MSI-based installs.
if (!ShouldUseWorkloadSetMode(_sdkFeatureBand, _dotnetPath))
{
throw new NuGetPackageNotFoundException(string.Format(Update.LocalizableStrings.WorkloadVersionRequestedNotFound, _workloadSetVersionFromGlobalJson ?? _workloadSetVersion));
_workloadInstaller.UpdateInstallMode(_sdkFeatureBand, true);
}
else
}

string resolvedWorkloadSetVersion = _workloadSetVersionFromGlobalJson ??_workloadSetVersionFromCommandLine;
if (string.IsNullOrWhiteSpace(resolvedWorkloadSetVersion) && !UseRollback)
{
_workloadManifestUpdater.UpdateAdvertisingManifestsAsync(_includePreviews, updateToLatestWorkloadSet, offlineCache).Wait();
if (updateToLatestWorkloadSet)
{
Reporter.WriteLine(Update.LocalizableStrings.NoWorkloadUpdateFound);
resolvedWorkloadSetVersion = _workloadManifestUpdater.GetAdvertisedWorkloadSetVersion();
}
updates = null;
return false;
}

var workloadSetPath = _workloadInstaller.InstallWorkloadSet(context, advertisingPackagePath);
var files = Directory.EnumerateFiles(workloadSetPath, "*.workloadset.json");
updates = _workloadManifestUpdater.ParseRollbackDefinitionFiles(files);
return true;
if (updateToLatestWorkloadSet && resolvedWorkloadSetVersion == null)
{
Reporter.WriteLine(Update.LocalizableStrings.NoWorkloadUpdateFound);
return;
}

IEnumerable<ManifestVersionUpdate> manifestsToUpdate;
if (resolvedWorkloadSetVersion != null)
{
manifestsToUpdate = InstallWorkloadSet(context, resolvedWorkloadSetVersion);
}
else
{
manifestsToUpdate = UseRollback ? _workloadManifestUpdater.CalculateManifestRollbacks(_fromRollbackDefinition) :
_workloadManifestUpdater.CalculateManifestUpdates().Select(m => m.ManifestUpdate);
}

InstallStateContents oldInstallState = GetCurrentInstallState();

context.Run(
action: () =>
{
foreach (var manifestUpdate in manifestsToUpdate)
{
_workloadInstaller.InstallWorkloadManifest(manifestUpdate, context, offlineCache);
}

if (!SpecifiedWorkloadSetVersionInGlobalJson)
{
if (UseRollback)
{
_workloadInstaller.SaveInstallStateManifestVersions(_sdkFeatureBand, GetInstallStateContents(manifestsToUpdate));
}
else if (SpecifiedWorkloadSetVersionOnCommandLine)
{
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, resolvedWorkloadSetVersion);
}
else if (this is WorkloadUpdateCommand)
{
// For workload updates, if you don't specify a rollback file, or a workload version then we should update to a new version of the manifests or workload set, and
// should remove the install state that pins to the other version
_workloadInstaller.RemoveManifestsFromInstallState(_sdkFeatureBand);
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, null);
}
}

_workloadResolver.RefreshWorkloadManifests();
},
rollback: () =>
{
// Reset install state
var currentInstallState = GetCurrentInstallState();
if (currentInstallState.UseWorkloadSets != oldInstallState.UseWorkloadSets)
{
_workloadInstaller.UpdateInstallMode(_sdkFeatureBand, oldInstallState.UseWorkloadSets);
}

if ((currentInstallState.Manifests == null && oldInstallState.Manifests != null) ||
(currentInstallState.Manifests != null && oldInstallState.Manifests == null) ||
(currentInstallState.Manifests != null && oldInstallState.Manifests != null &&
(currentInstallState.Manifests.Count != oldInstallState.Manifests.Count ||
!currentInstallState.Manifests.All(m => oldInstallState.Manifests.TryGetValue(m.Key, out var val) && val.Equals(m.Value)))))
{
_workloadInstaller.SaveInstallStateManifestVersions(_sdkFeatureBand, oldInstallState.Manifests);
}

if (currentInstallState.WorkloadVersion != oldInstallState.WorkloadVersion)
{
_workloadInstaller.AdjustWorkloadSetInInstallState(_sdkFeatureBand, oldInstallState.WorkloadVersion);
}

// We will refresh the workload manifests to make sure that the resolver has the updated state after the rollback
_workloadResolver.RefreshWorkloadManifests();
});
}

private IEnumerable<ManifestVersionUpdate> InstallWorkloadSet(ITransactionContext context, string workloadSetVersion)
{
PrintWorkloadSetTransition(workloadSetVersion);
var workloadSet = _workloadInstaller.InstallWorkloadSet(context, workloadSetVersion);

return _workloadManifestUpdater.CalculateManifestUpdatesForWorkloadSet(workloadSet);
}

private void PrintWorkloadSetTransition(string newVersion)
Expand Down Expand Up @@ -260,6 +360,17 @@ protected IEnumerable<WorkloadId> GetInstalledWorkloads(bool fromPreviousSdk)
return workloads ?? Enumerable.Empty<WorkloadId>();
}
}

protected IEnumerable<WorkloadId> WriteSDKInstallRecordsForVSWorkloads(IEnumerable<WorkloadId> workloadsWithExistingInstallRecords)
{
#if !DOT_NET_BUILD_FROM_SOURCE
if (OperatingSystem.IsWindows())
{
return VisualStudioWorkloads.WriteSDKInstallRecordsForVSWorkloads(_workloadInstaller, _workloadResolver, workloadsWithExistingInstallRecords, Reporter);
}
#endif
return workloadsWithExistingInstallRecords;
}
}

internal static class InstallingWorkloadCommandParser
Expand Down
Loading