public static int Main(string[] args)
{
string exeDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet");
string exePath = Path.Combine(exeDir, @"NuGet.exe");
try
{
var processInfo = new ProcessStartInfo(exePath)
{
UseShellExecute = false,
WorkingDirectory = Environment.CurrentDirectory
};
if (!File.Exists(exePath))
{
var document = GetConfigDocument();
EnsurePackageRestoreConsent(document);
ProxyCache.Instance = new ProxyCache(document);
// Register a console based credentials provider so that the user get's prompted if a password
// is required for the proxy
// Setup IHttpClient for the Gallery to locate packages
if (!Directory.Exists(exeDir))
{
Directory.CreateDirectory(exeDir);
}
new HttpClient().DownloadData(exePath);
}
else if ((DateTime.UtcNow - File.GetLastWriteTimeUtc(exePath)).TotalDays > 10)
{
// Check for updates to the exe every 10 days
processInfo.Arguments = "update -self";
RunProcess(processInfo);
File.SetLastWriteTimeUtc(exePath, DateTime.UtcNow);
}
processInfo.Arguments = ParseArgs();
RunProcess(processInfo);
return 0;
}
catch (Exception e)
{
WriteError(e);
}
return 1;
}