Skip to content

Instantly share code, notes, and snippets.

@emgarten
Created November 4, 2015 04:00
Show Gist options
  • Save emgarten/9681ea4edb90982e7db2 to your computer and use it in GitHub Desktop.
Save emgarten/9681ea4edb90982e7db2 to your computer and use it in GitHub Desktop.
NuGet.Core example of reading nuget.config restore settings
using System;
using NuGet;
namespace ConsoleApplication25
{
class Program
{
static void Main(string[] args)
{
// Create a new file system using the root directory of the solution or project.
// All nuget.config files from that directory and up will be checked.
var fileSystem = new PhysicalFileSystem(@"D:\tmp\test\ConsoleApplication1");
var settings = new Settings(fileSystem);
// Restore settings reader
var restoreSettings = new PackageRestoreConsent(settings);
// Check if automatic restore is enabled AND consent is granted
// Both of these default to true if they are not set.
var canRestore = restoreSettings.IsAutomatic && restoreSettings.IsGranted;
Console.WriteLine($"Automatic restore allowed: {canRestore.ToString()}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment