public WorkloadRepairCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, string tempDirPath = null, string version = null, string userProfileDir = null) : base(parseResult, reporter: reporter, nugetPackageDownloader: nugetPackageDownloader) { _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath; _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(WorkloadRepairCommandParser.VersionOption), version, _dotnetPath, userProfileDir); var configOption = parseResult.GetValueForOption(WorkloadRepairCommandParser.ConfigOption); var sourceOption = parseResult.GetValueForOption(WorkloadRepairCommandParser.SourceOption); _packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null : new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption); var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), userProfileDir); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(workloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), userProfileDir); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(Reporter, sdkFeatureBand, _workloadResolver, Verbosity, userProfileDir, VerifySignatures, PackageDownloader, dotnetDir, TempDirectoryPath, _packageSourceLocation, _parseResult.ToRestoreActionConfig()); }
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(); _restoreActionConfig = restoreActionConfig; _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(_tempPackagesDir, filePermissionSetter: null, new FirstPartyNuGetPackageSigningVerifier(_tempPackagesDir), logger, restoreActionConfig: _restoreActionConfig); bool userLocal = WorkloadFileBasedInstall.IsUserLocal(_dotnetDir, sdkFeatureBand.ToString()); _workloadMetadataDir = Path.Combine(userLocal ? _userProfileDir : _dotnetDir, "metadata", "workloads"); _reporter = reporter; _sdkFeatureBand = sdkFeatureBand; _workloadResolver = workloadResolver; _installationRecordRepository = new NetSdkManagedInstallationRecordRepository(_workloadMetadataDir); _packageSourceLocation = packageSourceLocation; }
/// <summary> /// Creates a new <see cref="NetSdkMsiInstallerClient"/> instance. If the current host process is not elevated, /// the elevated server process will also be started by running an additional command. /// </summary> /// <param name="nugetPackageDownloader"></param> /// <param name="verbosity"></param> /// <param name="packageSourceLocation"></param> /// <returns></returns> public static NetSdkMsiInstallerClient Create( SdkFeatureBand sdkFeatureBand, IWorkloadResolver workloadResolver, INuGetPackageDownloader nugetPackageDownloader = null, VerbosityOptions verbosity = VerbosityOptions.normal, PackageSourceLocation packageSourceLocation = null, IReporter reporter = null, string tempDirPath = null, RestoreActionConfig restoreActionConfig = null) { TimestampedFileLogger logger = new(Path.Combine(Path.GetTempPath(), $"Microsoft.NET.Workload_{DateTime.Now:yyyyMMdd_HHmmss}.log")); InstallClientElevationContext elevationContext = new(logger); if (nugetPackageDownloader == null) { DirectoryPath tempPackagesDir = new(string.IsNullOrWhiteSpace(tempDirPath) ? Path.GetTempPath() : tempDirPath); nugetPackageDownloader = new NuGetPackageDownloader(tempPackagesDir, filePermissionSetter: null, new FirstPartyNuGetPackageSigningVerifier(tempPackagesDir), new NullLogger(), restoreActionConfig: restoreActionConfig); } return(new NetSdkMsiInstallerClient(elevationContext, logger, workloadResolver, sdkFeatureBand, nugetPackageDownloader, verbosity, packageSourceLocation, reporter)); }
public static IInstaller GetWorkloadInstaller( IReporter reporter, SdkFeatureBand sdkFeatureBand, IWorkloadResolver workloadResolver, VerbosityOptions verbosity, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, PackageSourceLocation packageSourceLocation = null) { var installType = GetWorkloadInstallType(sdkFeatureBand, string.IsNullOrWhiteSpace(dotnetDir) ? Path.GetDirectoryName(Environment.ProcessPath) : dotnetDir); if (installType == InstallType.Msi) { if (!OperatingSystem.IsWindows()) { throw new InvalidOperationException(LocalizableStrings.OSDoesNotSupportMsi); } return(new NetSdkMsiInstaller()); } if (!CanWriteToDotnetRoot(dotnetDir)) { throw new GracefulException(LocalizableStrings.InadequatePermissions); } return(new NetSdkManagedInstaller(reporter, sdkFeatureBand, workloadResolver, nugetPackageDownloader, verbosity: verbosity, dotnetDir: dotnetDir, packageSourceLocation: packageSourceLocation)); }
public NetSdkMsiInstallerClient(InstallElevationContextBase elevationContext, ISetupLogger logger, IWorkloadResolver workloadResolver, SdkFeatureBand sdkFeatureBand, INuGetPackageDownloader nugetPackageDownloader = null, VerbosityOptions verbosity = VerbosityOptions.normal, PackageSourceLocation packageSourceLocation = null, IReporter reporter = null) : base(elevationContext, logger, reporter) { _packageSourceLocation = packageSourceLocation; _nugetPackageDownloader = nugetPackageDownloader; _sdkFeatureBand = sdkFeatureBand; _workloadResolver = workloadResolver; _dependent = $"{DependentPrefix},{sdkFeatureBand},{HostArchitecture}"; Log?.LogMessage($"Executing: {CurrentProcess.GetCommandLine()}, PID: {CurrentProcess.Id}, PPID: {ParentProcess.Id}"); Log?.LogMessage($"{nameof(IsElevated)}: {IsElevated}"); Log?.LogMessage($"{nameof(Is64BitProcess)}: {Is64BitProcess}"); Log?.LogMessage($"{nameof(RebootPending)}: {RebootPending}"); Log?.LogMessage($"{nameof(ProcessorArchitecture)}: {ProcessorArchitecture}"); Log?.LogMessage($"{nameof(HostArchitecture)}: {HostArchitecture}"); Log?.LogMessage($"{nameof(SdkDirectory)}: {SdkDirectory}"); Log?.LogMessage($"SDK feature band: {_sdkFeatureBand}"); if (IsElevated) { // Turn off automatic updates. We don't want MU to potentially patch the SDK // and it also reduces the risk of hitting ERROR_INSTALL_ALREADY_RUNNING. UpdateAgent.Stop(); } }
public WorkloadInstallCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, IWorkloadManifestUpdater workloadManifestUpdater = null, string dotnetDir = null, string userHome = null, string tempDirPath = null, string version = null, IReadOnlyCollection <string> workloadIds = null) : base(parseResult) { _reporter = reporter ?? Reporter.Output; _skipManifestUpdate = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.SkipManifestUpdateOption); _includePreviews = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.IncludePreviewOption); _printDownloadLinkOnly = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.FromCacheOption); _downloadToCacheOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.DownloadToCacheOption); _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); _sdkFeatureBand = new SdkFeatureBand(string.Join('.', _sdkVersion.Major, _sdkVersion.Minor, _sdkVersion.SdkFeatureBand)); _tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.ValueForOption <string>(WorkloadInstallCommandParser.TempDirOption)) ? Path.GetTempPath() : parseResult.ValueForOption <string>(WorkloadInstallCommandParser.TempDirOption)); var configOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.ConfigOption); var sourceOption = parseResult.ValueForOption <string[]>(WorkloadInstallCommandParser.SourceOption); _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 sdkFeatureBand = new SdkFeatureBand(_sdkVersion); var tempPackagesDir = new DirectoryPath(Path.Combine(_tempDirPath, "dotnet-sdk-advertising-temp")); var restoreActionConfig = _parseResult.ToRestoreActionConfig(); _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(tempPackagesDir, filePermissionSetter: null, new FirstPartyNuGetPackageSigningVerifier(tempPackagesDir, _verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger()), _verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger(), restoreActionConfig: restoreActionConfig); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand, _workloadResolver, _verbosity, _nugetPackageDownloader, _dotnetPath, _tempDirPath, _packageSourceLocation, restoreActionConfig, elevationRequired: !_printDownloadLinkOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption)); _userHome = userHome ?? CliFolderPathCalculator.DotnetHomePath; _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter, _workloadResolver, _nugetPackageDownloader, _userHome, _tempDirPath, _workloadInstaller.GetWorkloadInstallationRecordRepository(), _packageSourceLocation); ValidateWorkloadIdsInput(); }
public ShellShimTemplateFinder( INuGetPackageDownloader nugetPackageDownloader, DirectoryPath tempDir, PackageSourceLocation packageSourceLocation) { _tempDir = tempDir; _nugetPackageDownloader = nugetPackageDownloader; _packageSourceLocation = packageSourceLocation; }
public WorkloadUpdateCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, IWorkloadManifestUpdater workloadManifestUpdater = null, string dotnetDir = null, string userProfileDir = null, string tempDirPath = null, string version = null) : base(parseResult) { _printDownloadLinkOnly = parseResult.GetValueForOption(WorkloadUpdateCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromCacheOption); _reporter = reporter ?? Reporter.Output; _includePreviews = parseResult.GetValueForOption(WorkloadUpdateCommandParser.IncludePreviewsOption); _fromPreviousSdk = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromPreviousSdkOption); _adManifestOnlyOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.AdManifestOnlyOption); _downloadToCacheOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.DownloadToCacheOption); _verbosity = parseResult.GetValueForOption(WorkloadUpdateCommandParser.VerbosityOption); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath; _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(WorkloadUpdateCommandParser.VersionOption), version, _dotnetPath, _userProfileDir); _tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.GetValueForOption(WorkloadUpdateCommandParser.TempDirOption)) ? Path.GetTempPath() : parseResult.GetValueForOption(WorkloadUpdateCommandParser.TempDirOption)); _printRollbackDefinitionOnly = parseResult.GetValueForOption(WorkloadUpdateCommandParser.PrintRollbackOption); _fromRollbackDefinition = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromRollbackFileOption); var configOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.ConfigOption); var sourceOption = parseResult.GetValueForOption <string[]>(WorkloadUpdateCommandParser.SourceOption); _packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null : new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption); var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), _userProfileDir); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(workloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), _userProfileDir); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); var restoreActionConfig = _parseResult.ToRestoreActionConfig(); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand, _workloadResolver, _verbosity, _userProfileDir, nugetPackageDownloader, dotnetDir, _tempDirPath, packageSourceLocation: _packageSourceLocation, restoreActionConfig, elevationRequired: !_printDownloadLinkOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption)); var tempPackagesDir = new DirectoryPath(Path.Combine(_tempDirPath, "dotnet-sdk-advertising-temp")); _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(tempPackagesDir, filePermissionSetter: null, new FirstPartyNuGetPackageSigningVerifier(tempPackagesDir, _verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger()), _verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger(), restoreActionConfig: restoreActionConfig); _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter, _workloadResolver, _nugetPackageDownloader, _userProfileDir, _tempDirPath, _workloadInstaller.GetWorkloadInstallationRecordRepository(), _packageSourceLocation); }
public WorkloadInstallCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, IWorkloadManifestUpdater workloadManifestUpdater = null, string dotnetDir = null, string userProfileDir = null, string tempDirPath = null, string version = null, IReadOnlyCollection <string> workloadIds = null) : base(parseResult, reporter: reporter, tempDirPath: tempDirPath, nugetPackageDownloader: nugetPackageDownloader) { _skipManifestUpdate = parseResult.GetValueForOption(WorkloadInstallCommandParser.SkipManifestUpdateOption); _includePreviews = parseResult.GetValueForOption(WorkloadInstallCommandParser.IncludePreviewOption); _printDownloadLinkOnly = parseResult.GetValueForOption(WorkloadInstallCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.GetValueForOption(WorkloadInstallCommandParser.FromCacheOption); _downloadToCacheOption = parseResult.GetValueForOption(WorkloadInstallCommandParser.DownloadToCacheOption); _workloadIds = workloadIds ?? parseResult.GetValueForArgument(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly(); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath; _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(WorkloadInstallCommandParser.VersionOption), version, _dotnetPath, _userProfileDir); _sdkFeatureBand = new SdkFeatureBand(_sdkVersion); _fromRollbackDefinition = parseResult.GetValueForOption(WorkloadInstallCommandParser.FromRollbackFileOption); var configOption = parseResult.GetValueForOption(WorkloadInstallCommandParser.ConfigOption); var sourceOption = parseResult.GetValueForOption(WorkloadInstallCommandParser.SourceOption); _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(), userProfileDir); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(sdkWorkloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), _userProfileDir); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); var tempPackagesDir = new DirectoryPath(Path.Combine(TempDirectoryPath, "dotnet-sdk-advertising-temp")); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(Reporter, sdkFeatureBand, _workloadResolver, Verbosity, _userProfileDir, VerifySignatures, PackageDownloader, _dotnetPath, TempDirectoryPath, _packageSourceLocation, RestoreActionConfiguration, elevationRequired: !_printDownloadLinkOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption)); bool displayManifestUpdates = false; if (Verbosity.VerbosityIsDetailedOrDiagnostic()) { displayManifestUpdates = true; } _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(Reporter, _workloadResolver, PackageDownloader, _userProfileDir, TempDirectoryPath, _workloadInstaller.GetWorkloadInstallationRecordRepository(), _packageSourceLocation, displayManifestUpdates: displayManifestUpdates); ValidateWorkloadIdsInput(); }
public void GivenManagedInstallItHonorsNuGetSources() { var packageSource = new PackageSourceLocation(new FilePath("mock-file")); var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller(packageSourceLocation: packageSource); var packInfo = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk"); var version = "6.0.100"; installer.InstallWorkloadPack(packInfo, new SdkFeatureBand(version)); var mockNugetInstaller = nugetInstaller as MockNuGetPackageDownloader; mockNugetInstaller.DownloadCallParams.Count.Should().Be(1); mockNugetInstaller.DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId(packInfo.Id), new NuGetVersion(packInfo.Version), null as DirectoryPath?, packageSource)); }
public WorkloadManifestUpdater( IReporter reporter, IWorkloadManifestProvider workloadManifestProvider, INuGetPackageDownloader nugetPackageDownloader, string userHome, string tempDirPath, PackageSourceLocation packageSourceLocation = null) { _reporter = reporter; _workloadManifestProvider = workloadManifestProvider; _userHome = userHome; _tempDirPath = tempDirPath; _nugetPackageDownloader = nugetPackageDownloader; _sdkFeatureBand = new SdkFeatureBand(_workloadManifestProvider.GetSdkFeatureBand()); _packageSourceLocation = packageSourceLocation; }
public WorkloadInstallCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, IWorkloadManifestUpdater workloadManifestUpdater = null, string dotnetDir = null, string userHome = null, string tempDirPath = null, string version = null) : base(parseResult) { _reporter = reporter ?? Reporter.Output; _skipManifestUpdate = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.SkipManifestUpdateOption); _includePreviews = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.IncludePreviewOption); _printDownloadLinkOnly = parseResult.ValueForOption <bool>(WorkloadInstallCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.FromCacheOption); _downloadToCacheOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.DownloadToCacheOption); _workloadIds = parseResult.ValueForArgument <IEnumerable <string> >(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly(); _verbosity = parseResult.ValueForOption <VerbosityOptions>(WorkloadInstallCommandParser.VerbosityOption); _sdkVersion = string.IsNullOrEmpty(parseResult.ValueForOption <string>(WorkloadInstallCommandParser.VersionOption)) ? new ReleaseVersion(version ?? Product.Version) : new ReleaseVersion(parseResult.ValueForOption <string>(WorkloadInstallCommandParser.VersionOption)); _tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.ValueForOption <string>(WorkloadInstallCommandParser.TempDirOption)) ? Path.GetTempPath() : parseResult.ValueForOption <string>(WorkloadInstallCommandParser.TempDirOption)); var configOption = parseResult.ValueForOption <string>(WorkloadInstallCommandParser.ConfigOption); var addSourceOption = parseResult.ValueForOption <string[]>(WorkloadInstallCommandParser.AddSourceOption); _packageSourceLocation = string.IsNullOrEmpty(configOption) && (addSourceOption == null || !addSourceOption.Any()) ? null : new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: addSourceOption); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString()); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(_workloadManifestProvider, _dotnetPath, _sdkVersion.ToString()); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand, _workloadResolver, _verbosity, nugetPackageDownloader, _dotnetPath, _packageSourceLocation); _userHome = userHome ?? CliFolderPathCalculator.DotnetHomePath; var tempPackagesDir = new DirectoryPath(Path.Combine(_tempDirPath, "dotnet-sdk-advertising-temp")); _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(tempPackagesDir, filePermissionSetter: null, new NullLogger()); _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter, _workloadManifestProvider, _nugetPackageDownloader, _userHome, _tempDirPath, _packageSourceLocation); }
public static IInstaller GetWorkloadInstaller( IReporter reporter, SdkFeatureBand sdkFeatureBand, IWorkloadResolver workloadResolver, VerbosityOptions verbosity, string userProfileDir, bool verifySignatures, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, string tempDirPath = null, PackageSourceLocation packageSourceLocation = null, RestoreActionConfig restoreActionConfig = null, bool elevationRequired = true) { dotnetDir = string.IsNullOrWhiteSpace(dotnetDir) ? Path.GetDirectoryName(Environment.ProcessPath) : dotnetDir; var installType = GetWorkloadInstallType(sdkFeatureBand, dotnetDir); if (installType == InstallType.Msi) { if (!OperatingSystem.IsWindows()) { throw new InvalidOperationException(LocalizableStrings.OSDoesNotSupportMsi); } return(NetSdkMsiInstallerClient.Create(verifySignatures, sdkFeatureBand, workloadResolver, nugetPackageDownloader, verbosity, packageSourceLocation, reporter, tempDirPath)); } if (elevationRequired && !WorkloadFileBasedInstall.IsUserLocal(dotnetDir, sdkFeatureBand.ToString()) && !CanWriteToDotnetRoot(dotnetDir)) { throw new GracefulException(LocalizableStrings.InadequatePermissions, isUserError: false); } userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath; return(new FileBasedInstaller(reporter, sdkFeatureBand, workloadResolver, userProfileDir, nugetPackageDownloader, dotnetDir: dotnetDir, tempDirPath: tempDirPath, verbosity: verbosity, packageSourceLocation: packageSourceLocation, restoreActionConfig: restoreActionConfig)); }
public WorkloadUpdateCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, IWorkloadManifestUpdater workloadManifestUpdater = null, string dotnetDir = null, string userProfileDir = null, string tempDirPath = null, string version = null) : base(parseResult, reporter: reporter, tempDirPath: tempDirPath, nugetPackageDownloader: nugetPackageDownloader) { _printDownloadLinkOnly = parseResult.GetValueForOption(WorkloadUpdateCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromCacheOption); _includePreviews = parseResult.GetValueForOption(WorkloadUpdateCommandParser.IncludePreviewsOption); _fromPreviousSdk = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromPreviousSdkOption); _adManifestOnlyOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.AdManifestOnlyOption); _downloadToCacheOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.DownloadToCacheOption); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _userProfileDir = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath; _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(WorkloadUpdateCommandParser.VersionOption), version, _dotnetPath, _userProfileDir); _printRollbackDefinitionOnly = parseResult.GetValueForOption(WorkloadUpdateCommandParser.PrintRollbackOption); _fromRollbackDefinition = parseResult.GetValueForOption(WorkloadUpdateCommandParser.FromRollbackFileOption); var configOption = parseResult.GetValueForOption(WorkloadUpdateCommandParser.ConfigOption); var sourceOption = parseResult.GetValueForOption <string[]>(WorkloadUpdateCommandParser.SourceOption); _packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null : new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption); var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), _userProfileDir); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(workloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), _userProfileDir); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(Reporter, sdkFeatureBand, _workloadResolver, Verbosity, _userProfileDir, VerifySignatures, PackageDownloader, dotnetDir, TempDirectoryPath, packageSourceLocation: _packageSourceLocation, RestoreActionConfiguration, elevationRequired: !_printDownloadLinkOnly && !_printRollbackDefinitionOnly && string.IsNullOrWhiteSpace(_downloadToCacheOption)); _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(Reporter, _workloadResolver, PackageDownloader, _userProfileDir, TempDirectoryPath, _workloadInstaller.GetWorkloadInstallationRecordRepository(), _packageSourceLocation); }
public WorkloadRepairCommand( ParseResult parseResult, IReporter reporter = null, IWorkloadResolver workloadResolver = null, IInstaller workloadInstaller = null, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, string tempDirPath = null, string version = null, string userProfileDir = null) : base(parseResult) { _reporter = reporter ?? Reporter.Output; _verbosity = parseResult.GetValueForOption(WorkloadRepairCommandParser.VerbosityOption); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath; _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.GetValueForOption(WorkloadRepairCommandParser.VersionOption), version, _dotnetPath, userProfileDir); var configOption = parseResult.GetValueForOption(WorkloadRepairCommandParser.ConfigOption); var sourceOption = parseResult.GetValueForOption(WorkloadRepairCommandParser.SourceOption); _packageSourceLocation = string.IsNullOrEmpty(configOption) && (sourceOption == null || !sourceOption.Any()) ? null : new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), sourceFeedOverrides: sourceOption); var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(_dotnetPath, _sdkVersion.ToString(), userProfileDir); _workloadResolver = workloadResolver ?? WorkloadResolver.Create(workloadManifestProvider, _dotnetPath, _sdkVersion.ToString(), userProfileDir); var sdkFeatureBand = new SdkFeatureBand(_sdkVersion); tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.GetValueForOption(WorkloadInstallCommandParser.TempDirOption)) ? Path.GetTempPath() : parseResult.GetValueForOption(WorkloadInstallCommandParser.TempDirOption)); var tempPackagesDir = new DirectoryPath(Path.Combine(tempDirPath, "dotnet-sdk-advertising-temp")); NullLogger nullLogger = new NullLogger(); nugetPackageDownloader ??= new NuGetPackageDownloader( tempPackagesDir, filePermissionSetter: null, new FirstPartyNuGetPackageSigningVerifier(tempPackagesDir, nullLogger), nullLogger, restoreActionConfig: _parseResult.ToRestoreActionConfig()); _workloadInstaller = workloadInstaller ?? WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand, _workloadResolver, _verbosity, userProfileDir, nugetPackageDownloader, dotnetDir, tempDirPath, _packageSourceLocation, _parseResult.ToRestoreActionConfig()); }
public WorkloadManifestUpdater(IReporter reporter, IWorkloadManifestProvider workloadManifestProvider, IWorkloadResolver workloadResolver, INuGetPackageDownloader nugetPackageDownloader, string userHome, string tempDirPath, PackageSourceLocation packageSourceLocation = null, Func <string, string> getEnvironmentVariable = null) { _reporter = reporter; _workloadManifestProvider = workloadManifestProvider; _workloadResolver = workloadResolver; _userHome = userHome; _tempDirPath = tempDirPath; _nugetPackageDownloader = nugetPackageDownloader; _sdkFeatureBand = new SdkFeatureBand(_workloadManifestProvider.GetSdkFeatureBand()); _packageSourceLocation = packageSourceLocation; _getEnvironmentVariable = getEnvironmentVariable ?? Environment.GetEnvironmentVariable; }
public WorkloadManifestUpdater(IReporter reporter, IWorkloadResolver workloadResolver, INuGetPackageDownloader nugetPackageDownloader, string userProfileDir, string tempDirPath, IWorkloadInstallationRecordRepository workloadRecordRepo, PackageSourceLocation packageSourceLocation = null, Func <string, string> getEnvironmentVariable = null) { _reporter = reporter; _workloadResolver = workloadResolver; _userProfileDir = userProfileDir; _tempDirPath = tempDirPath; _nugetPackageDownloader = nugetPackageDownloader; _sdkFeatureBand = new SdkFeatureBand(_workloadResolver.GetSdkFeatureBand()); _packageSourceLocation = packageSourceLocation; _getEnvironmentVariable = getEnvironmentVariable ?? Environment.GetEnvironmentVariable; _workloadRecordRepo = workloadRecordRepo; }
public NetSdkManagedInstaller( IReporter reporter, SdkFeatureBand sdkFeatureBand, IWorkloadResolver workloadResolver, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, VerbosityOptions verbosity = VerbosityOptions.normal, PackageSourceLocation packageSourceLocation = null) { _dotnetDir = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _tempPackagesDir = new DirectoryPath(Path.Combine(_dotnetDir, "metadata", "temp")); _nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(_tempPackagesDir, filePermissionSetter: null, verbosity.VerbosityIsDetailedOrDiagnostic() ? new NuGetConsoleLogger() : new NullLogger()); _workloadMetadataDir = Path.Combine(_dotnetDir, "metadata", "workloads"); _reporter = reporter; _sdkFeatureBand = sdkFeatureBand; _workloadResolver = workloadResolver; _installationRecordRepository = new NetSdkManagedInstallationRecordRepository(_dotnetDir); _packageSourceLocation = packageSourceLocation; }
public ToolInstallGlobalOrToolPathCommand( ParseResult parseResult, CreateToolPackageStoresAndInstaller createToolPackageStoreAndInstaller = null, CreateShellShimRepository createShellShimRepository = null, IEnvironmentPathInstruction environmentPathInstruction = null, IReporter reporter = null, INuGetPackageDownloader nugetPackageDownloader = null) : base(parseResult) { _packageId = new PackageId(parseResult.ValueForArgument <string>(ToolInstallCommandParser.PackageIdArgument)); _packageVersion = parseResult.ValueForOption <string>(ToolInstallCommandParser.VersionOption); _configFilePath = parseResult.ValueForOption <string>(ToolInstallCommandParser.ConfigOption); _framework = parseResult.ValueForOption <string>(ToolInstallCommandParser.FrameworkOption); _source = parseResult.ValueForOption <string[]>(ToolInstallCommandParser.AddSourceOption); _global = parseResult.ValueForOption <bool>(ToolAppliedOption.GlobalOptionAliases.First()); _verbosity = Enum.GetName(parseResult.ValueForOption <VerbosityOptions>(ToolInstallCommandParser.VerbosityOption)); _toolPath = parseResult.ValueForOption <string>(ToolAppliedOption.ToolPathOptionAlias); _architectureOption = parseResult.ValueForOption <string>(ToolInstallCommandParser.ArchitectureOption); _createToolPackageStoresAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoresAndInstaller; _forwardRestoreArguments = parseResult.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()); _environmentPathInstruction = environmentPathInstruction ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction(); _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository; var tempDir = new DirectoryPath(Path.Combine(Path.GetTempPath(), "dotnet-tool-install")); var configOption = parseResult.ValueForOption(ToolInstallCommandParser.ConfigOption); var sourceOption = parseResult.ValueForOption(ToolInstallCommandParser.AddSourceOption); var packageSourceLocation = new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), additionalSourceFeeds: sourceOption); var restoreAction = new RestoreActionConfig(DisableParallel: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.DisableParallelOption), NoCache: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.NoCacheOption), IgnoreFailedSources: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption), Interactive: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption)); nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction); _shellShimTemplateFinder = new ShellShimTemplateFinder(nugetPackageDownloader, tempDir, packageSourceLocation); _reporter = (reporter ?? Reporter.Output); _errorReporter = (reporter ?? Reporter.Error); }
private (string, FileBasedInstaller, INuGetPackageDownloader) GetTestInstaller([CallerMemberName] string testName = "", bool failingInstaller = false, string identifier = "", bool manifestDownload = false, PackageSourceLocation packageSourceLocation = null) { var testDirectory = _testAssetsManager.CreateTestDirectory(testName, identifier: identifier).Path; var dotnetRoot = Path.Combine(testDirectory, "dotnet"); INuGetPackageDownloader nugetInstaller = failingInstaller ? new FailingNuGetPackageDownloader(testDirectory) : new MockNuGetPackageDownloader(dotnetRoot, manifestDownload); var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), dotnetRoot); var sdkFeatureBand = new SdkFeatureBand("6.0.100"); return(dotnetRoot, new FileBasedInstaller(_reporter, sdkFeatureBand, workloadResolver, userProfileDir: testDirectory, nugetInstaller, dotnetRoot, packageSourceLocation: packageSourceLocation), nugetInstaller); }