Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ecfaa75
restore-toolset.sh: remove EOL 1.x versions.
tmds Aug 17, 2021
e190841
Support user local workload installs.
tmds Aug 17, 2021
6b7fdbb
Add back DisplayAsError to CliFolderPathCalculator
tmds Aug 30, 2021
bb7a3a6
Remove handled TODO comment
tmds Aug 30, 2021
cfabaea
Use RuntimeInformation class to detect Windows.
tmds Aug 30, 2021
754715a
Prefer folders specified by envvar.
tmds Aug 30, 2021
782800a
Fix CI compilation failure.
tmds Aug 30, 2021
eb739fc
Update src/Cli/dotnet/commands/dotnet-workload/install/NetSdkManagedI…
tmds Aug 30, 2021
819f446
Fix CI compilation failure.
tmds Aug 30, 2021
610eef4
Limit cleanup to user local packs when SDK does user local install.
tmds Aug 30, 2021
a3bbefe
Remove TODO
tmds Aug 30, 2021
57fd5d5
revert restore-toolset.sh changes
tmds Aug 30, 2021
6a8fd55
Fix test
tmds Aug 31, 2021
d0101a7
NetSdkManagedInstaller: use profile xor dotnet root folder depending …
tmds Aug 31, 2021
64c4e10
Run GivenDotnetWorkloadInstall tests with userlocal
tmds Sep 1, 2021
93ab493
Refactor all the things!
tmds Sep 2, 2021
a056698
revert restore-toolset.sh changes
tmds Sep 2, 2021
7fa8e3c
Fix optional arg order
tmds Sep 2, 2021
8c648e6
cleanup
tmds Sep 3, 2021
a5ed159
Fix GivenMultiplePackRoots_ItUsesTheLastOneIfThePackDoesntExist
tmds Sep 3, 2021
0a5105c
Fix ItCreatesAnAspNetCertificateSentinelFileUnderTheDotDotNetFolder
tmds Sep 3, 2021
8c44c72
Fix project test failures due to random folder names.
tmds Sep 3, 2021
50cc06b
Fix TestPreviewFeatures
tmds Sep 3, 2021
75975f6
Microsoft.NET.Sdk.Razor.Tool: use CliFolderPathCalculatorCore
tmds Sep 3, 2021
0553a70
Fix GetPidFilePath_ReturnsCorrectDefaultPath
tmds Sep 3, 2021
86621e4
Rename GivenMultiplePackRoots_ItUsesTheLastOneIfThePackDoesntExist to…
tmds Sep 6, 2021
287f025
Rename WorkloadInstall to Microsoft.DotNet.Workloads.Workload.Workloa…
tmds Sep 6, 2021
c6bbb67
Refactor GivenDotnetWorkloadInstall
tmds Sep 6, 2021
e4f79a5
Run more GivenDotnetWorkload tests against userlocal install.
tmds Sep 6, 2021
f7ce05f
GivenDotnetWorkload*: pass userProfileDir into Command ctors.
tmds Sep 6, 2021
9f1a39b
Fix compilation
tmds Sep 6, 2021
25fcd8f
Always use sdk feature band for user local detection.
tmds Sep 7, 2021
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
28 changes: 9 additions & 19 deletions src/Cli/Microsoft.DotNet.Configurer/CliFolderPathCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Microsoft.DotNet.Configurer
{
public static class CliFolderPathCalculator
{
public const string DotnetHomeVariableName = "DOTNET_CLI_HOME";
private const string DotnetProfileDirectoryName = ".dotnet";
public const string DotnetHomeVariableName = CliFolderPathCalculatorCore.DotnetHomeVariableName;
private const string DotnetProfileDirectoryName = CliFolderPathCalculatorCore.DotnetProfileDirectoryName;
private const string ToolsShimFolderName = "tools";
private const string ToolsResolverCacheFolderName = "toolResolverCache";

Expand Down Expand Up @@ -45,28 +45,18 @@ public static string WindowsNonExpandedToolsShimPath

public static string ToolsResolverCachePath => Path.Combine(DotnetUserProfileFolderPath, ToolsResolverCacheFolderName);

public static string PlatformHomeVariableName =>
OperatingSystem.IsWindows() ? "USERPROFILE" : "HOME";
public static string PlatformHomeVariableName => CliFolderPathCalculatorCore.PlatformHomeVariableName;

public static string DotnetHomePath
{
get
{
var home = Environment.GetEnvironmentVariable(DotnetHomeVariableName);
if (string.IsNullOrEmpty(home))
{
home = Environment.GetEnvironmentVariable(PlatformHomeVariableName);
if (string.IsNullOrEmpty(home))
{
throw new ConfigurationException(
string.Format(
LocalizableStrings.FailedToDetermineUserHomeDirectory,
DotnetHomeVariableName))
.DisplayAsError();
}
}

return home;
return CliFolderPathCalculatorCore.GetDotnetHomePath()
?? throw new ConfigurationException(
string.Format(
LocalizableStrings.FailedToDetermineUserHomeDirectory,
DotnetHomeVariableName))
.DisplayAsError();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
<ProjectReference Include="..\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)src\Common\CliFolderPathCalculatorCore.cs" LinkBase="Common"/>
</ItemGroup>
</Project>
7 changes: 5 additions & 2 deletions src/Cli/dotnet/commands/RestoringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Workloads.Workload.Install;
Expand All @@ -18,10 +19,12 @@ public class RestoringCommand : MSBuildForwardingApp
public RestoringCommand(
IEnumerable<string> msbuildArgs,
bool noRestore,
string msbuildPath = null)
string msbuildPath = null,
string userProfileDir = null)
: base(GetCommandArguments(msbuildArgs, noRestore), msbuildPath)
{
Task.Run(() => WorkloadManifestUpdater.BackgroundUpdateAdvertisingManifestsAsync());
userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;
Task.Run(() => WorkloadManifestUpdater.BackgroundUpdateAdvertisingManifestsAsync(userProfileDir));
SeparateRestoreCommand = GetSeparateRestoreCommand(msbuildArgs, noRestore, msbuildPath);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Configurer;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Abstractions.TemplatePackage;
using System;
Expand Down Expand Up @@ -35,8 +36,9 @@ public Task<IReadOnlyList<ITemplatePackage>> GetAllTemplatePackagesAsync(Cancell
var sdkDirectory = Path.GetDirectoryName(typeof(DotnetFiles).Assembly.Location);
var sdkVersion = Path.GetFileName(sdkDirectory);
var dotnetRootPath = Path.GetDirectoryName(Path.GetDirectoryName(sdkDirectory));
string userProfileDir = CliFolderPathCalculator.DotnetUserProfileFolderPath;

var packages = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetRootPath);
var packages = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetRootPath, userProfileDir);
var fileSystem = _environmentSettings.Host.FileSystem;
foreach (var packageInfo in packages)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.ToolPackage;
using Microsoft.Extensions.EnvironmentAbstractions;
using Microsoft.NET.Sdk.WorkloadManifestReader;
Expand All @@ -23,8 +24,9 @@ internal class NetSdkManagedInstaller : IWorkloadPackInstaller
{
private readonly IReporter _reporter;
private readonly string _workloadMetadataDir;
private readonly string _installedPacksDir = "InstalledPacks";
private const string InstalledPacksDir = "InstalledPacks";
protected readonly string _dotnetDir;
protected readonly string _userProfileDir;
protected readonly DirectoryPath _tempPackagesDir;
private readonly INuGetPackageDownloader _nugetPackageDownloader;
private readonly IWorkloadResolver _workloadResolver;
Expand All @@ -38,13 +40,15 @@ internal class NetSdkManagedInstaller : IWorkloadPackInstaller
public NetSdkManagedInstaller(IReporter reporter,
SdkFeatureBand sdkFeatureBand,
IWorkloadResolver workloadResolver,
string userProfileDir,
INuGetPackageDownloader nugetPackageDownloader = null,
string dotnetDir = null,
string tempDirPath = null,
VerbosityOptions verbosity = VerbosityOptions.normal,
PackageSourceLocation packageSourceLocation = null,
RestoreActionConfig restoreActionConfig = null)
{
_userProfileDir = userProfileDir;
_dotnetDir = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
_tempPackagesDir = new DirectoryPath(tempDirPath ?? Path.GetTempPath());
ILogger logger = verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger();
Expand All @@ -53,11 +57,12 @@ public NetSdkManagedInstaller(IReporter reporter,
new NuGetPackageDownloader(_tempPackagesDir, filePermissionSetter: null,
new FirstPartyNuGetPackageSigningVerifier(_tempPackagesDir), logger,
restoreActionConfig: _restoreActionConfig);
_workloadMetadataDir = Path.Combine(_dotnetDir, "metadata", "workloads");
bool userLocal = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, sdkFeatureBand.ToString());
_workloadMetadataDir = Path.Combine(userLocal ? _userProfileDir : _dotnetDir, "metadata", "workloads");
_reporter = reporter;
_sdkFeatureBand = sdkFeatureBand;
_workloadResolver = workloadResolver;
_installationRecordRepository = new NetSdkManagedInstallationRecordRepository(_dotnetDir);
_installationRecordRepository = new NetSdkManagedInstallationRecordRepository(_workloadMetadataDir);
_packageSourceLocation = packageSourceLocation;
}

Expand Down Expand Up @@ -190,7 +195,8 @@ public void InstallWorkloadManifest(ManifestId manifestId, ManifestVersion manif
string packagePath = null;
string tempExtractionDir = null;
string tempBackupDir = null;
var manifestPath = Path.Combine(_dotnetDir, "sdk-manifests", sdkFeatureBand.ToString(), manifestId.ToString());
string rootInstallDir = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, sdkFeatureBand.ToString()) ? _userProfileDir : _dotnetDir;
var manifestPath = Path.Combine(rootInstallDir, "sdk-manifests", sdkFeatureBand.ToString(), manifestId.ToString());

_reporter.WriteLine(string.Format(LocalizableStrings.InstallingWorkloadManifest, manifestId, manifestVersion));

Expand Down Expand Up @@ -287,10 +293,10 @@ public void DownloadToOfflineCache(PackInfo packInfo, DirectoryPath cachePath, b

public void GarbageCollectInstalledWorkloadPacks(DirectoryPath? offlineCache = null)
{
var installedPacksDir = Path.Combine(_workloadMetadataDir, _installedPacksDir, "v1");
var installedSdkFeatureBands = _installationRecordRepository.GetFeatureBandsWithInstallationRecords();
_reporter.WriteLine(string.Format(LocalizableStrings.GarbageCollectingSdkFeatureBandsMessage, string.Join(" ", installedSdkFeatureBands)));
var currentBandInstallRecords = GetExpectedPackInstallRecords(_sdkFeatureBand);
string installedPacksDir = Path.Combine(_workloadMetadataDir, InstalledPacksDir, "v1");

if (!Directory.Exists(installedPacksDir))
{
Expand Down Expand Up @@ -346,7 +352,7 @@ public void GarbageCollectInstalledWorkloadPacks(DirectoryPath? offlineCache = n

public IEnumerable<(WorkloadPackId, string)> GetInstalledPacks(SdkFeatureBand sdkFeatureBand)
{
var installedPacksDir = Path.Combine(_workloadMetadataDir, _installedPacksDir, "v1");
var installedPacksDir = Path.Combine(_workloadMetadataDir, InstalledPacksDir, "v1");
if (!Directory.Exists(installedPacksDir))
{
return Enumerable.Empty<(WorkloadPackId, string)>();
Expand Down Expand Up @@ -429,7 +435,7 @@ private void DeletePack(PackInfo packInfo)
}

private string GetPackInstallRecordPath(PackInfo packInfo, SdkFeatureBand featureBand) =>
Path.Combine(_workloadMetadataDir, _installedPacksDir, "v1", packInfo.Id, packInfo.Version, featureBand.ToString());
Path.Combine(_workloadMetadataDir, InstalledPacksDir, "v1", packInfo.Id, packInfo.Version, featureBand.ToString());

private void WritePackInstallationRecord(PackInfo packInfo, SdkFeatureBand featureBand)
{
Expand Down Expand Up @@ -465,7 +471,7 @@ private void DeletePackInstallationRecord(PackInfo packInfo, SdkFeatureBand feat

private bool PackHasInstallRecords(PackInfo packInfo)
{
var packInstallRecordDir = Path.Combine(_workloadMetadataDir, _installedPacksDir, "v1", packInfo.Id, packInfo.Version);
var packInstallRecordDir = Path.Combine(_workloadMetadataDir, InstalledPacksDir, "v1", packInfo.Id, packInfo.Version);
return Directory.Exists(packInstallRecordDir) && Directory.GetFiles(packInstallRecordDir).Any();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class WorkloadInstallCommand : CommandBase
private readonly IWorkloadManifestUpdater _workloadManifestUpdater;
private readonly ReleaseVersion _sdkVersion;
private readonly SdkFeatureBand _sdkFeatureBand;
private readonly string _userHome;
private readonly string _userProfileDir;
private readonly string _tempDirPath;
private readonly string _dotnetPath;

Expand All @@ -54,7 +54,7 @@ public WorkloadInstallCommand(
INuGetPackageDownloader nugetPackageDownloader = null,
IWorkloadManifestUpdater workloadManifestUpdater = null,
string dotnetDir = null,
string userHome = null,
string userProfileDir = null,
string tempDirPath = null,
string version = null,
IReadOnlyCollection<string> workloadIds = null)
Expand All @@ -69,7 +69,8 @@ public WorkloadInstallCommand(
_workloadIds = workloadIds ?? parseResult.ValueForArgument<IEnumerable<string>>(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly();
_verbosity = parseResult.ValueForOption<VerbosityOptions>(WorkloadInstallCommandParser.VerbosityOption);
_dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.ValueForOption<string>(WorkloadInstallCommandParser.VersionOption), version, _dotnetPath);
_userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath;
_sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.ValueForOption<string>(WorkloadInstallCommandParser.VersionOption), version, _dotnetPath, _userProfileDir);
_sdkFeatureBand = new SdkFeatureBand(string.Join('.', _sdkVersion.Major, _sdkVersion.Minor, _sdkVersion.SdkFeatureBand));
_tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.ValueForOption<string>(WorkloadInstallCommandParser.TempDirOption)) ?
Path.GetTempPath() :
Expand All @@ -80,8 +81,8 @@ public WorkloadInstallCommand(
_packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null :
new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption);

var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString());
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _sdkVersion.ToString());
var sdkWorkloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), userProfileDir);
_workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), _userProfileDir);
var sdkFeatureBand = new SdkFeatureBand(_sdkVersion);
var tempPackagesDir = new DirectoryPath(Path.Combine(_tempDirPath, "dotnet-sdk-advertising-temp"));
var restoreActionConfig = _parseResult.ToRestoreActionConfig();
Expand All @@ -92,10 +93,9 @@ public WorkloadInstallCommand(
_verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger(), restoreActionConfig: restoreActionConfig);
_workloadInstaller = workloadInstaller ??
WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand,
_workloadResolver, _verbosity, _nugetPackageDownloader, _dotnetPath, _tempDirPath,
_workloadResolver, _verbosity, _userProfileDir, _nugetPackageDownloader, _dotnetPath, _tempDirPath,
_packageSourceLocation, restoreActionConfig, elevationRequired: !_printDownloadLinkOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption));
_userHome = userHome ?? CliFolderPathCalculator.DotnetHomePath;
_workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter, _workloadResolver, _nugetPackageDownloader, _userHome, _tempDirPath,
_workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter, _workloadResolver, _nugetPackageDownloader, _userProfileDir, _tempDirPath,
_workloadInstaller.GetWorkloadInstallationRecordRepository(), _packageSourceLocation);

ValidateWorkloadIdsInput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Microsoft.DotNet.Workloads.Workload.Install.InstallRecord
internal class NetSdkManagedInstallationRecordRepository : IWorkloadInstallationRecordRepository
{
private readonly string _workloadMetadataDir;
private readonly string _installedWorkloadDir = "InstalledWorkloads";
private const string InstalledWorkloadDir = "InstalledWorkloads";

public NetSdkManagedInstallationRecordRepository(string dotnetDir)
public NetSdkManagedInstallationRecordRepository(string workloadMetadataDir)
{
_workloadMetadataDir = Path.Combine(dotnetDir, "metadata", "workloads");
_workloadMetadataDir = workloadMetadataDir;
}

public IEnumerable<SdkFeatureBand> GetFeatureBandsWithInstallationRecords()
Expand All @@ -25,7 +25,7 @@ public IEnumerable<SdkFeatureBand> GetFeatureBandsWithInstallationRecords()
{
var bands = Directory.EnumerateDirectories(_workloadMetadataDir);
return bands
.Where(band => Directory.Exists(Path.Combine(band, _installedWorkloadDir)) && Directory.GetFiles(Path.Combine(band, _installedWorkloadDir)).Any())
.Where(band => Directory.Exists(Path.Combine(band, InstalledWorkloadDir)) && Directory.GetFiles(Path.Combine(band, InstalledWorkloadDir)).Any())
.Select(path => new SdkFeatureBand(Path.GetFileName(path)));
}
else
Expand All @@ -36,7 +36,7 @@ public IEnumerable<SdkFeatureBand> GetFeatureBandsWithInstallationRecords()

public IEnumerable<WorkloadId> GetInstalledWorkloads(SdkFeatureBand featureBand)
{
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), _installedWorkloadDir);
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), InstalledWorkloadDir);
if (Directory.Exists(path))
{
return Directory.EnumerateFiles(path)
Expand All @@ -50,7 +50,7 @@ public IEnumerable<WorkloadId> GetInstalledWorkloads(SdkFeatureBand featureBand)

public void WriteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBand featureBand)
{
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), _installedWorkloadDir, workloadId.ToString());
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), InstalledWorkloadDir, workloadId.ToString());
if (!File.Exists(path))
{
var pathDir = Path.GetDirectoryName(path);
Expand All @@ -64,7 +64,7 @@ public void WriteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBan

public void DeleteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBand featureBand)
{
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), _installedWorkloadDir, workloadId.ToString());
var path = Path.Combine(_workloadMetadataDir, featureBand.ToString(), InstalledWorkloadDir, workloadId.ToString());
if (File.Exists(path))
{
File.Delete(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.DotNet.Workloads.Workload.Install.InstallRecord;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
using Microsoft.DotNet.Configurer;

namespace Microsoft.DotNet.Workloads.Workload.Install
{
Expand All @@ -18,6 +19,7 @@ public static IInstaller GetWorkloadInstaller(
SdkFeatureBand sdkFeatureBand,
IWorkloadResolver workloadResolver,
VerbosityOptions verbosity,
string userProfileDir,
INuGetPackageDownloader nugetPackageDownloader = null,
string dotnetDir = null,
string tempDirPath = null,
Expand All @@ -40,14 +42,17 @@ public static IInstaller GetWorkloadInstaller(
nugetPackageDownloader, verbosity, packageSourceLocation, reporter, tempDirPath);
}

if (elevationRequired && !CanWriteToDotnetRoot(dotnetDir))
if (elevationRequired && !WorkloadFileBasedInstall.IsUserLocal(dotnetDir, sdkFeatureBand.ToString()) && !CanWriteToDotnetRoot(dotnetDir))
{
throw new GracefulException(LocalizableStrings.InadequatePermissions, isUserError: false);
}

userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath;

return new NetSdkManagedInstaller(reporter,
sdkFeatureBand,
workloadResolver,
userProfileDir,
nugetPackageDownloader,
dotnetDir: dotnetDir,
tempDirPath: tempDirPath,
Expand Down
Loading