public NuGetPackageDownloader(DirectoryPath packageInstallDir, IFilePermissionSetter filePermissionSetter = null, IFirstPartyNuGetPackageSigningVerifier firstPartyNuGetPackageSigningVerifier = null, ILogger verboseLogger = null, IReporter reporter = null, RestoreActionConfig restoreActionConfig = null, Func <IEnumerable <Task> > timer = null) { _packageInstallDir = packageInstallDir; _reporter = reporter ?? Reporter.Output; _verboseLogger = verboseLogger ?? new NuGetConsoleLogger(); _firstPartyNuGetPackageSigningVerifier = firstPartyNuGetPackageSigningVerifier ?? new FirstPartyNuGetPackageSigningVerifier( tempDirectory: packageInstallDir, logger: _verboseLogger); _filePermissionSetter = filePermissionSetter ?? new FilePermissionSetter(); _restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig(); _retryTimer = timer; _sourceRepositories = new Dictionary <PackageSource, SourceRepository>(); _cacheSettings = new SourceCacheContext { NoCache = _restoreActionConfig.NoCache, DirectDownload = true, IgnoreFailedSources = _restoreActionConfig.IgnoreFailedSources, }; DefaultCredentialServiceUtility.SetupDefaultCredentialService(new NuGetConsoleLogger(), !_restoreActionConfig.Interactive); }
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, 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 static IInstaller GetWorkloadInstaller( IReporter reporter, SdkFeatureBand sdkFeatureBand, IWorkloadResolver workloadResolver, VerbosityOptions verbosity, INuGetPackageDownloader nugetPackageDownloader = null, string dotnetDir = null, string tempDirPath = null, PackageSourceLocation packageSourceLocation = null, RestoreActionConfig restoreActionConfig = null, bool elevationRequired = true) { 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(NetSdkMsiInstallerClient.Create(sdkFeatureBand, workloadResolver, nugetPackageDownloader, verbosity, packageSourceLocation, reporter, tempDirPath)); } if (elevationRequired && !CanWriteToDotnetRoot(dotnetDir)) { throw new GracefulException(LocalizableStrings.InadequatePermissions); } return(new NetSdkManagedInstaller(reporter, sdkFeatureBand, workloadResolver, nugetPackageDownloader, dotnetDir: dotnetDir, tempDirPath: tempDirPath, verbosity: verbosity, packageSourceLocation: packageSourceLocation, restoreActionConfig: restoreActionConfig)); }
public NuGetPackageDownloader(DirectoryPath packageInstallDir, IFilePermissionSetter filePermissionSetter = null, IFirstPartyNuGetPackageSigningVerifier firstPartyNuGetPackageSigningVerifier = null, ILogger verboseLogger = null, IReporter reporter = null, RestoreActionConfig restoreActionConfig = null) { _packageInstallDir = packageInstallDir; _reporter = reporter ?? Reporter.Output; _verboseLogger = verboseLogger ?? new NuGetConsoleLogger(); _firstPartyNuGetPackageSigningVerifier = firstPartyNuGetPackageSigningVerifier ?? new FirstPartyNuGetPackageSigningVerifier( tempDirectory: packageInstallDir, logger: _verboseLogger); _filePermissionSetter = filePermissionSetter ?? new FilePermissionSetter(); _restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig(); _cacheSettings = new SourceCacheContext { NoCache = _restoreActionConfig.NoCache, DirectDownload = true, IgnoreFailedSources = _restoreActionConfig.IgnoreFailedSources, }; }
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); }