Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public WorkloadListCommand(
            ParseResult result,
            IReporter reporter = null,
            IWorkloadInstallationRecordRepository workloadRecordRepo = null,
            string currentSdkVersion = null,
            string dotnetDir         = null,
            string userProfileDir    = null,
            string tempDirPath       = null,
            INuGetPackageDownloader nugetPackageDownloader   = null,
            IWorkloadManifestUpdater workloadManifestUpdater = null,
            IWorkloadResolver workloadResolver = null
            ) : base(result)
        {
            _reporter = reporter ?? Reporter.Output;
            _machineReadableOption = result.GetValueForOption(WorkloadListCommandParser.MachineReadableOption);
            _verbosity             = result.GetValueForOption(WorkloadListCommandParser.VerbosityOption);

            _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
            ReleaseVersion currentSdkReleaseVersion = new(currentSdkVersion ?? Product.Version);

            _currentSdkFeatureBand = new SdkFeatureBand(currentSdkReleaseVersion);

            _includePreviews = result.GetValueForOption(WorkloadListCommandParser.IncludePreviewsOption);
            _tempDirPath     = tempDirPath ??
                               (string.IsNullOrWhiteSpace(
                                    result.GetValueForOption(WorkloadListCommandParser.TempDirOption))
                               ? Path.GetTempPath()
                               : result.GetValueForOption(WorkloadListCommandParser.TempDirOption));
            _targetSdkVersion = result.GetValueForOption(WorkloadListCommandParser.VersionOption);
            _userProfileDir   = userProfileDir ?? CliFolderPathCalculator.DotnetUserProfileFolderPath;
            var workloadManifestProvider =
                new SdkDirectoryWorkloadManifestProvider(_dotnetPath,
                                                         string.IsNullOrWhiteSpace(_targetSdkVersion)
                        ? currentSdkReleaseVersion.ToString()
                        : _targetSdkVersion,
                                                         _userProfileDir);
            DirectoryPath tempPackagesDir =
                new(Path.Combine(_userProfileDir, "sdk-advertising-temp"));
            NullLogger nullLogger = new NullLogger();

            _nugetPackageDownloader = nugetPackageDownloader ??
                                      new NuGetPackageDownloader(tempPackagesDir, null,
                                                                 new FirstPartyNuGetPackageSigningVerifier(tempPackagesDir, nullLogger),
                                                                 verboseLogger: nullLogger,
                                                                 restoreActionConfig: _parseResult.ToRestoreActionConfig());
            workloadResolver ??= WorkloadResolver.Create(workloadManifestProvider, _dotnetPath, currentSdkReleaseVersion.ToString(), _userProfileDir);

            _workloadRecordRepo = workloadRecordRepo ??
                                  WorkloadInstallerFactory.GetWorkloadInstaller(reporter, _currentSdkFeatureBand, workloadResolver, _verbosity, _userProfileDir,
                                                                                elevationRequired: false).GetWorkloadInstallationRecordRepository();

            _workloadManifestUpdater = workloadManifestUpdater ?? new WorkloadManifestUpdater(_reporter,
                                                                                              workloadResolver, _nugetPackageDownloader, _userProfileDir, _tempDirPath, _workloadRecordRepo);
        }
Ejemplo n.º 3
0
        public WorkloadUpdateCommand(
            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)
        {
            _printDownloadLinkOnly =
                parseResult.ValueForOption <bool>(WorkloadUpdateCommandParser.PrintDownloadLinkOnlyOption);
            _fromCacheOption       = parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.FromCacheOption);
            _reporter              = reporter ?? Reporter.Output;
            _includePreviews       = parseResult.ValueForOption <bool>(WorkloadUpdateCommandParser.IncludePreviewsOption);
            _downloadToCacheOption = parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.DownloadToCacheOption);
            _verbosity             = parseResult.ValueForOption <VerbosityOptions>(WorkloadUpdateCommandParser.VerbosityOption);
            _sdkVersion            = string.IsNullOrEmpty(parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.VersionOption)) ?
                                     new ReleaseVersion(version ?? Product.Version) :
                                     new ReleaseVersion(parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.VersionOption));
            _tempDirPath = tempDirPath ?? (string.IsNullOrWhiteSpace(parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.TempDirOption)) ?
                                           Path.GetTempPath() :
                                           parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.TempDirOption));

            var configOption    = parseResult.ValueForOption <string>(WorkloadUpdateCommandParser.ConfigOption);
            var addSourceOption = parseResult.ValueForOption <string[]>(WorkloadUpdateCommandParser.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,
                                                                                                    dotnetDir, packageSourceLocation: _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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        public WorkloadListCommand(
            ParseResult result,
            IReporter reporter = null,
            IWorkloadInstallationRecordRepository workloadRecordRepo = null,
            string version = null) : base(result)
        {
            _reporter = reporter ?? Reporter.Output;
            _machineReadableOption = result.ValueForOption <bool>(WorkloadListCommandParser.MachineReadableOption);
            _verbosity             = result.ValueForOption <VerbosityOptions>(WorkloadListCommandParser.VerbosityOption);

            var sdkVersion = new ReleaseVersion(version ?? Product.Version);
            var dotnetPath = Path.GetDirectoryName(Environment.ProcessPath);
            var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(dotnetPath, sdkVersion.ToString());
            var workloadResolver         = WorkloadResolver.Create(workloadManifestProvider, dotnetPath, sdkVersion.ToString());

            _sdkFeatureBand     = new SdkFeatureBand(sdkVersion);
            _workloadRecordRepo = workloadRecordRepo ??
                                  WorkloadInstallerFactory
                                  .GetWorkloadInstaller(_reporter, _sdkFeatureBand, workloadResolver, _verbosity)
                                  .GetWorkloadInstallationRecordRepository();
            _sdkVersion = result.ValueForOption <string>(WorkloadUpdateCommandParser.SdkVersionOption);
        }
Ejemplo n.º 7
0
        public WorkloadUninstallCommand(
            ParseResult parseResult,
            IReporter reporter = null,
            IWorkloadResolver workloadResolver             = null,
            INuGetPackageDownloader nugetPackageDownloader = null,
            string dotnetDir = null,
            string version   = null)
            : base(parseResult)
        {
            _reporter    = reporter ?? Reporter.Output;
            _workloadIds = parseResult.ValueForArgument <IEnumerable <string> >(WorkloadUninstallCommandParser.WorkloadIdArgument)
                           .Select(workloadId => new WorkloadId(workloadId)).ToList().AsReadOnly();
            var dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);

            _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.ValueForOption <string>(WorkloadUninstallCommandParser.VersionOption), version, dotnetPath);
            var verbosity = parseResult.ValueForOption <VerbosityOptions>(WorkloadUninstallCommandParser.VerbosityOption);
            var workloadManifestProvider = new SdkDirectoryWorkloadManifestProvider(dotnetPath, _sdkVersion.ToString());

            workloadResolver ??= WorkloadResolver.Create(workloadManifestProvider, dotnetPath, _sdkVersion.ToString());
            nugetPackageDownloader ??= new NuGetPackageDownloader(new DirectoryPath(Path.GetTempPath()), filePermissionSetter: null, verboseLogger: new NullLogger());
            var sdkFeatureBand = new SdkFeatureBand(_sdkVersion);

            _workloadInstaller = WorkloadInstallerFactory.GetWorkloadInstaller(_reporter, sdkFeatureBand, workloadResolver, verbosity, nugetPackageDownloader, dotnetPath);
        }
Ejemplo n.º 8
0
        public WorkloadListHelper(
            VerbosityOptions verbosity = VerbosityOptions.normal,
            string targetSdkVersion    = null,
            bool?verifySignatures      = null,
            IReporter reporter         = null,
            IWorkloadInstallationRecordRepository workloadRecordRepo = null,
            string currentSdkVersion           = null,
            string dotnetDir                   = null,
            string userProfileDir              = null,
            IWorkloadResolver workloadResolver = null
            )
        {
            string         dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath);
            ReleaseVersion currentSdkReleaseVersion = new(currentSdkVersion ?? Product.Version);

            _currentSdkFeatureBand = new SdkFeatureBand(currentSdkReleaseVersion);

            _targetSdkVersion = targetSdkVersion;
            userProfileDir ??= CliFolderPathCalculator.DotnetUserProfileFolderPath;
            var workloadManifestProvider =
                new SdkDirectoryWorkloadManifestProvider(dotnetPath,
                                                         string.IsNullOrWhiteSpace(_targetSdkVersion)
                        ? currentSdkReleaseVersion.ToString()
                        : _targetSdkVersion,
                                                         userProfileDir);

            WorkloadResolver = workloadResolver ?? NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(
                workloadManifestProvider, dotnetPath,
                currentSdkReleaseVersion.ToString(), userProfileDir);

            WorkloadRecordRepo = workloadRecordRepo ??
                                 WorkloadInstallerFactory.GetWorkloadInstaller(reporter, _currentSdkFeatureBand,
                                                                               WorkloadResolver, verbosity, userProfileDir,
                                                                               verifySignatures ?? !SignCheck.IsDotNetSigned(),
                                                                               elevationRequired: false).GetWorkloadInstallationRecordRepository();
        }