示例#1
0
        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;
        }
示例#2
0
        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();
        }
示例#3
0
 internal static void TryRunGarbageCollection(IInstaller workloadInstaller, IReporter reporter, VerbosityOptions verbosity, DirectoryPath?offlineCache = null)
 {
     try
     {
         if (workloadInstaller.GetInstallationUnit().Equals(InstallationUnit.Packs))
         {
             workloadInstaller.GetPackInstaller().GarbageCollectInstalledWorkloadPacks(offlineCache);
         }
     }
     catch (Exception e)
     {
         // Garbage collection failed, warn user
         reporter.WriteLine(string.Format(LocalizableStrings.GarbageCollectionFailed,
                                          verbosity.VerbosityIsDetailedOrDiagnostic() ? e.StackTrace.ToString() : e.Message).Yellow());
     }
 }
示例#4
0
        public override int Execute()
        {
            var avaliableWorkloads = _workloadResolver.GetAvaliableWorkloads();

            if (!string.IsNullOrEmpty(_workloadIdStub))
            {
                avaliableWorkloads = avaliableWorkloads.Where(workload => workload.Id.ToString().Contains(_workloadIdStub, StringComparison.OrdinalIgnoreCase));
            }

            var table = new PrintableTable <WorkloadDefinition>();

            table.AddColumn(LocalizableStrings.WorkloadIdColumnName, workload => workload.Id.ToString());
            table.AddColumn(LocalizableStrings.DescriptionColumnName, workload => workload.Description);
            if (_verbosity.VerbosityIsDetailedOrDiagnostic())
            {
                table.AddColumn(LocalizableStrings.PlatformColumnName, workload => workload.Platforms == null ? string.Empty : string.Join(" ", workload.Platforms));
            }

            _reporter.WriteLine();
            table.PrintRows(avaliableWorkloads, l => _reporter.WriteLine(l));
            _reporter.WriteLine();

            return(0);
        }
示例#5
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);
        }
示例#6
0
 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;
 }