public static int Main(string[] args) { try { Console.WriteLine("NuGet bootstrapper {0}", typeof(Program).Assembly.GetName().Version); // Setup the proxy for gallery requests Uri galleryUri = new Uri(GalleryUrl); // Register a console based credentials provider so that the user get's prompted if a password // is required for the proxy HttpClient.DefaultCredentialProvider = new ConsoleCredentialProvider(); // Setup IHttpClient for the Gallery to locate packages var httpClient = new HttpClient(galleryUri); // Get the package from the feed var repository = new DataServicePackageRepository(httpClient); var packageMetadata = repository.GetPackages().Where(p => p.Id.ToLower() == NuGetCommandLinePackageId) .AsEnumerable() .OrderByDescending(p => Version.Parse(p.Version)) .FirstOrDefault(); if (packageMetadata != null) { Console.WriteLine("Found NuGet.exe version {0}.", packageMetadata.Version); Console.WriteLine("Downloading..."); Uri uri = repository.GetReadStreamUri(packageMetadata); var downloadClient = new HttpClient(uri); var packageStream = new MemoryStream(downloadClient.DownloadData()); using (Package package = Package.Open(packageStream)) { var fileUri = PackUriHelper.CreatePartUri(new Uri(NuGetExeFilePath, UriKind.Relative)); PackagePart nugetExePart = package.GetPart(fileUri); if (nugetExePart != null) { // Get the exe path and move it to a temp file (NuGet.exe.old) so we can replace the running exe with the bits we got // from the package repository string exePath = typeof(Program).Assembly.Location; string renamedPath = exePath + ".old"; Move(exePath, renamedPath); // Update the file UpdateFile(exePath, nugetExePart); Console.WriteLine("Update complete."); } } } return 0; } catch (Exception e) { WriteError(e); } return 1; }
private static DataServiceMetadata GetDataServiceMetadata(Uri metadataUri) { if (metadataUri == null) { return(null); } HttpClient client = new HttpClient(metadataUri); using (MemoryStream stream = new MemoryStream()) { client.DownloadData(stream); stream.Seek(0L, SeekOrigin.Begin); return(ExtractMetadataFromSchema(stream)); } }
private static DataServiceMetadata GetDataServiceMetadata(Uri metadataUri) { if (metadataUri == null) { return(null); } // Make a request to the metadata uri and get the schema var client = new HttpClient(metadataUri); using (MemoryStream stream = new MemoryStream()) { client.DownloadData(stream); stream.Seek(0, SeekOrigin.Begin); return(ExtractMetadataFromSchema(stream)); } }
public static int Main(string[] args) { string _exePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"NuGet\NuGet.exe"); try { var processInfo = new ProcessStartInfo(_exePath) { UseShellExecute = false, WorkingDirectory = Environment.CurrentDirectory }; if (!File.Exists(_exePath)) { // Register a console based credentials provider so that the user get's prompted if a password // is required for the proxy HttpClient.DefaultCredentialProvider = new ConsoleCredentialProvider(); // Setup IHttpClient for the Gallery to locate packages var httpClient = new HttpClient(new Uri("http://nuget.org/NuGet.exe")); httpClient.UserAgent = "Bootstrapper/" + typeof(Program).Assembly.GetName().Version; File.WriteAllBytes(_exePath, httpClient.DownloadData()); } else if ((DateTime.UtcNow - File.GetLastWriteTime(_exePath)).TotalDays > 10) { // Check for updates to the exe every 10 days processInfo.Arguments = "update -self"; RunProcess(processInfo); File.SetLastAccessTimeUtc(_exePath, DateTime.UtcNow); } processInfo.Arguments = ParseArgs(); RunProcess(processInfo); return 0; } catch (Exception e) { WriteError(e); } return 1; }
private static DataServiceMetadata GetDataServiceMetadata(Uri metadataUri) { if (metadataUri == null) { return(null); } // Make a request to the metadata uri and get the schema var client = new HttpClient(metadataUri); byte[] data = client.DownloadData(); if (data == null) { return(null); } string schema = Encoding.UTF8.GetString(data); return(ExtractMetadataFromSchema(schema)); }