Exemplo n.º 1
0
        public int Install(FilePath manifestFile)
        {
            IToolPackage toolDownloadedPackage =
                _toolLocalPackageInstaller.Install(manifestFile);

            _toolManifestEditor.Add(
                manifestFile,
                toolDownloadedPackage.Id,
                toolDownloadedPackage.Version,
                toolDownloadedPackage.Commands.Select(c => c.Name).ToArray());

            _localToolsResolverCache.SaveToolPackage(
                toolDownloadedPackage,
                _toolLocalPackageInstaller.TargetFrameworkToInstall);

            _reporter.WriteLine(
                string.Format(
                    LocalizableStrings.LocalToolInstallationSucceeded,
                    string.Join(", ", toolDownloadedPackage.Commands.Select(c => c.Name)),
                    toolDownloadedPackage.Id,
                    toolDownloadedPackage.Version.ToNormalizedString(),
                    manifestFile.Value).Green());

            return(0);
        }
Exemplo n.º 2
0
        public override int Execute()
        {
            if (_configFilePath != null && !File.Exists(_configFilePath))
            {
                throw new GracefulException(
                          string.Format(
                              LocalizableStrings.NuGetConfigurationFileDoesNotExist,
                              Path.GetFullPath(_configFilePath)));
            }

            VersionRange versionRange = null;

            if (!string.IsNullOrEmpty(_packageVersion) && !VersionRange.TryParse(_packageVersion, out versionRange))
            {
                throw new GracefulException(
                          string.Format(
                              LocalizableStrings.InvalidNuGetVersionRange,
                              _packageVersion));
            }

            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            string targetFramework = BundledTargetFramework.GetTargetFrameworkMoniker();

            try
            {
                FilePath manifestFile = GetManifestFilePath();

                IToolPackage toolDownloadedPackage =
                    _toolPackageInstaller.InstallPackageToExternalManagedLocation(
                        new PackageLocation(
                            nugetConfig: configFile,
                            additionalFeeds: _sources,
                            rootConfigDirectory: manifestFile.GetDirectoryPath()),
                        _packageId,
                        versionRange,
                        targetFramework,
                        verbosity: _verbosity);

                _toolManifestEditor.Add(
                    manifestFile,
                    toolDownloadedPackage.Id,
                    toolDownloadedPackage.Version,
                    toolDownloadedPackage.Commands.Select(c => c.Name).ToArray());

                foreach (var restoredCommand in toolDownloadedPackage.Commands)
                {
                    _localToolsResolverCache.Save(
                        new Dictionary <RestoredCommandIdentifier, RestoredCommand>
                    {
                        [new RestoredCommandIdentifier(
                             toolDownloadedPackage.Id,
                             toolDownloadedPackage.Version,
                             NuGetFramework.Parse(targetFramework),
                             Constants.AnyRid,
                             restoredCommand.Name)] =
                            restoredCommand
                    });
                }

                _reporter.WriteLine(
                    string.Format(
                        LocalizableStrings.LocalToolInstallationSucceeded,
                        string.Join(", ", toolDownloadedPackage.Commands.Select(c => c.Name)),
                        toolDownloadedPackage.Id,
                        toolDownloadedPackage.Version.ToNormalizedString(),
                        manifestFile.Value).Green());

                return(0);
            }
            catch (Exception ex) when(InstallToolCommandLowLevelErrorConverter.ShouldConvertToUserFacingError(ex))
            {
                throw new GracefulException(
                          messages: InstallToolCommandLowLevelErrorConverter.GetUserFacingMessages(ex, _packageId),
                          verboseMessages: new[] { ex.ToString() },
                          isUserError: false);
            }
        }