private void UpdatePackageSource() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired")); } var existingSource = SourceProvider.GetPackageSourceByName(Name); if (existingSource == null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name); } if (!string.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase)) { if (!PathValidator.IsValidSource(Source)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource")); } // If the user is updating the source, verify we don't have a duplicate. var duplicateSource = SourceProvider.GetPackageSourceBySource(Source); if (duplicateSource != null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource")); } existingSource = new Configuration.PackageSource(Source, existingSource.Name); } ValidateCredentials(); if (!string.IsNullOrEmpty(Username)) { var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false; if (hasExistingAuthTypes && string.IsNullOrEmpty(ValidAuthenticationTypes)) { Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandClearingExistingAuthTypes"), Name); } var credentials = Configuration.PackageSourceCredential.FromUserInput( Name, Username, Password, StorePasswordInClearText, ValidAuthenticationTypes); existingSource.Credentials = credentials; } SourceProvider.UpdatePackageSource(existingSource, updateCredentials: existingSource.Credentials != null, updateEnabled: false); Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name); }