NuGet.Settings.LoadDefaultSettings C# (CSharp) Method

LoadDefaultSettings() public static method

public static LoadDefaultSettings ( ) : ISettings
return ISettings
        public static ISettings LoadDefaultSettings()
        {
            string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            if (!String.IsNullOrEmpty(appDataPath))
            {
                var defaultSettingsPath = Path.Combine(appDataPath, "NuGet");
                var fileSystem = new PhysicalFileSystem(defaultSettingsPath);
                try
                {
                    return new Settings(fileSystem);
                }
                catch (XmlException)
                {
                    // Work Item 1531: If the config file is malformed and the constructor throws, NuGet fails to load in VS. 
                    // Returning a null instance prevents us from silently failing.
                }
            }

            // If there is no AppData folder, use a null file system to make the Settings object do nothing
            return NullSettings.Instance;
        }

Usage Example

Esempio n. 1
0
        private void Initialize(IFileSystem fileSystem, IConsole console)
        {
            using (var catalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly)))
            {
                if (!IgnoreExtensions)
                {
                    AddExtensionsToCatalog(catalog, console);
                }
                using (var container = new CompositionContainer(catalog))
                {
                    var settings             = Settings.LoadDefaultSettings(fileSystem);
                    var defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl);

                    var officialPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl, NuGetResources.OfficialPackageSourceName);
                    var v1PackageSource       = new PackageSource(NuGetConstants.V1FeedUrl, NuGetResources.OfficialPackageSourceName);
                    var legacyV2PackageSource = new PackageSource(NuGetConstants.V2LegacyFeedUrl, NuGetResources.OfficialPackageSourceName);

                    var packageSourceProvider = new PackageSourceProvider(
                        settings,
                        new[] { defaultPackageSource },
                        new Dictionary <PackageSource, PackageSource> {
                        { v1PackageSource, officialPackageSource },
                        { legacyV2PackageSource, officialPackageSource }
                    }
                        );

                    // Register an additional provider for the console specific application so that the user
                    // will be prompted if a proxy is set and credentials are required
                    var credentialProvider = new SettingsCredentialProvider(new ConsoleCredentialProvider(console), packageSourceProvider, console);
                    HttpClient.DefaultCredentialProvider = credentialProvider;

                    container.ComposeExportedValue <IConsole>(console);
                    container.ComposeExportedValue <ISettings>(settings);
                    container.ComposeExportedValue <IPackageRepositoryFactory>(new NuGet.Common.CommandLineRepositoryFactory());
                    container.ComposeExportedValue <IPackageSourceProvider>(packageSourceProvider);
                    container.ComposeExportedValue <ICredentialProvider>(credentialProvider);
                    container.ComposeExportedValue <IFileSystem>(fileSystem);
                    container.ComposeParts(this);
                }
            }
        }