public override int Execute() { if (!_global) { throw new GracefulException(LocalizableStrings.InstallToolCommandOnlySupportGlobal); } var toolConfigurationAndExecutablePath = ObtainPackage(); var commandName = toolConfigurationAndExecutablePath.Configuration.CommandName; _shellShimMaker.EnsureCommandNameUniqueness(commandName); _shellShimMaker.CreateShim( toolConfigurationAndExecutablePath.Executable.Value, commandName); _environmentPathInstruction .PrintAddPathInstructionIfPathDoesNotExist(); _reporter.WriteLine( string.Format(LocalizableStrings.InstallationSucceeded, commandName)); return(0); }
public override int Execute() { if (!_global) { throw new GracefulException(LocalizableStrings.InstallToolCommandOnlySupportGlobal); } try { FilePath?configFile = null; if (_configFilePath != null) { configFile = new FilePath(_configFilePath); } using (var transactionScope = new TransactionScope()) { var toolConfigurationAndExecutablePath = _toolPackageObtainer.ObtainAndReturnExecutablePath( packageId: _packageId, packageVersion: _packageVersion, nugetconfig: configFile, targetframework: _framework, source: _source, verbosity: _verbosity); var commandName = toolConfigurationAndExecutablePath.Configuration.CommandName; _shellShimMaker.CreateShim( toolConfigurationAndExecutablePath.Executable, commandName); _environmentPathInstruction .PrintAddPathInstructionIfPathDoesNotExist(); _reporter.WriteLine( string.Format(LocalizableStrings.InstallationSucceeded, commandName)); transactionScope.Complete(); } } catch (PackageObtainException ex) { _errorReporter.WriteLine(ex.Message.Red()); _errorReporter.WriteLine(string.Format(LocalizableStrings.ToolInstallationFailed, _packageId).Red()); return(1); } catch (ToolConfigurationException ex) { _errorReporter.WriteLine( string.Format( LocalizableStrings.InvalidToolConfiguration, ex.Message).Red()); _errorReporter.WriteLine(string.Format(LocalizableStrings.ToolInstallationFailedContactAuthor, _packageId).Red()); return(1); } return(0); }