public void Initialize() { var path = Environment.GetEnvironmentVariable("TEAMCITY_NUGET_FEEDS"); if (string.IsNullOrWhiteSpace(path)) { return; } if (!File.Exists(path)) { Console.Out.WriteLine("Failed to load NuGet feed credentials file: " + path); return; } new AssemblyResolver(GetType().Assembly.GetAssemblyDirectory()); INuGetSources sources = XmlSerializerHelper.Load <NuGetSources>(path); var actual = sources.Sources.Where(x => x.HasCredentials).ToArray(); if (actual.Any()) { myState = actual.Aggregate("ENABLED:", (acc, next) => acc + "feed=" + next.Source + ",user="******"<null>") + "; "); UpdateCredentials(actual); } }
public static int Main(string[] args) { try { var request = Args.Parse <CredentialProviderArgs>(args); if (request == null) { Console.Error.WriteLine("Invalid request arguments"); return((int)ExitCode.UnknownError); } var response = new CredentialProviderResponse(); ExitCode exitCode; var path = Environment.GetEnvironmentVariable(TEAMCITY_NUGET_FEEDS); if (string.IsNullOrWhiteSpace(path)) { response.Message = "Failed to load NuGet feed credentials file on path " + path; Console.Error.WriteLine("Failed to find {0} var in environment", TEAMCITY_NUGET_FEEDS); exitCode = ExitCode.ProviderNotApplicable; } else if (!File.Exists(path)) { response.Message = "Failed to load NuGet feed credentials file on path " + path; exitCode = ExitCode.Failure; } else { INuGetSources nuGetSources = XmlSerializerHelper.Load <NuGetSources>(path); var targetSource = nuGetSources.FindSource(request.Uri); if (targetSource == null) { response.Message = "NuGet feed credentials file contains no credentials for URL " + request.Uri; exitCode = ExitCode.ProviderNotApplicable; } else { response.Username = targetSource.Username; response.Password = targetSource.Password; response.Message = "Success"; exitCode = ExitCode.Success; } } Console.Out.WriteLine(response.ToString()); return((int)exitCode); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); return((int)ExitCode.UnknownError); } }