public RepositorySettings(ISolutionManager solutionManager, IFileSystemProvider fileSystemProvider, IVsSourceControlTracker sourceControlTracker, IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }

            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }

            if (sourceControlTracker == null)
            {
                throw new ArgumentNullException("sourceControlTracker");
            }

            _solutionManager     = solutionManager;
            _fileSystemProvider  = fileSystemProvider;
            _settings            = null;
            _machineWideSettings = machineWideSettings;

            EventHandler resetConfiguration = (sender, e) =>
            {
                // Kill our configuration cache when someone closes the solution
                _configurationPath = null;
                _fileSystem        = null;
                _settings          = null;
            };

            _solutionManager.SolutionClosing += resetConfiguration;
            sourceControlTracker.SolutionBoundToSourceControl += resetConfiguration;
        }
Esempio n. 2
0
 public VSSettings(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings)
 {
     SolutionManager                  = solutionManager ?? throw new ArgumentNullException(nameof(solutionManager));
     MachineWideSettings              = machineWideSettings;
     SolutionManager.SolutionOpening += OnSolutionOpenedOrClosed;
     SolutionManager.SolutionClosed  += OnSolutionOpenedOrClosed;
 }
Esempio n. 3
0
 /// <summary>
 /// Loads user settings from the NuGet configuration files. The method walks the directory
 /// tree in <paramref name="root" /> up to its root, and reads each NuGet.config file
 /// it finds in the directories. It then reads the user specific settings,
 /// which is file <paramref name="configFileName" />
 /// in <paramref name="root" /> if <paramref name="configFileName" /> is not null,
 /// If <paramref name="configFileName" /> is null, the user specific settings file is
 /// %AppData%\NuGet\NuGet.config.
 /// After that, the machine wide settings files are added.
 /// </summary>
 /// <remarks>
 /// For example, if <paramref name="root" /> is c:\dir1\dir2, <paramref name="configFileName" />
 /// is "userConfig.file", the files loaded are (in the order that they are loaded):
 /// c:\dir1\dir2\nuget.config
 /// c:\dir1\nuget.config
 /// c:\nuget.config
 /// c:\dir1\dir2\userConfig.file
 /// machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
 /// </remarks>
 /// <param name="root">
 /// The file system to walk to find configuration files.
 /// Can be null.
 /// </param>
 /// <param name="configFileName">The user specified configuration file.</param>
 /// <param name="machineWideSettings">
 /// The machine wide settings. If it's not null, the
 /// settings files in the machine wide settings are added after the user specific
 /// config file.
 /// </param>
 /// <returns>The settings object loaded.</returns>
 public static ISettings LoadDefaultSettings(
     string root,
     string configFileName,
     IMachineWideSettings machineWideSettings)
 {
     return(LoadDefaultSettings(root, configFileName, machineWideSettings, settingsLoadingContext: null));
 }
Esempio n. 4
0
        /// <summary>
        /// For internal use only
        /// </summary>
        internal static ISettings LoadSettings(
            string root,
            string configFileName,
            IMachineWideSettings machineWideSettings,
            bool loadUserWideSettings,
            bool useTestingGlobalPath,
            SettingsLoadingContext settingsLoadingContext = null)
        {
            // Walk up the tree to find a config file; also look in .nuget subdirectories
            // If a configFile is passed, don't walk up the tree. Only use that single config file.
            var validSettingFiles = new List <SettingsFile>();

            if (root != null && string.IsNullOrEmpty(configFileName))
            {
                validSettingFiles.AddRange(
                    GetSettingsFilesFullPath(root)
                    .Select(f =>
                {
                    if (settingsLoadingContext == null)
                    {
                        return(ReadSettings(root, f));
                    }
                    return(settingsLoadingContext.GetOrCreateSettingsFile(f));
                })
                    .Where(f => f != null));
            }

            return(LoadSettingsForSpecificConfigs(
                       root,
                       configFileName,
                       validSettingFiles,
                       machineWideSettings,
                       loadUserWideSettings,
                       useTestingGlobalPath));
        }
Esempio n. 5
0
        /// <summary>
        /// For internal use only.
        /// Finds and loads all configuration files within <paramref name="root" />.
        /// Does not load configuration files outside of <paramref name="root" />.
        /// </summary>
        internal static ISettings LoadSettings(
            DirectoryInfo root,
            IMachineWideSettings machineWideSettings,
            bool loadUserWideSettings,
            bool useTestingGlobalPath,
            SettingsLoadingContext settingsLoadingContext = null)
        {
            var validSettingFiles = new List <SettingsFile>();
            var comparer          = PathUtility.GetStringComparisonBasedOnOS();
            var settingsFiles     = root.GetFileSystemInfos("*.*", SearchOption.AllDirectories)
                                    .OfType <FileInfo>()
                                    .OrderByDescending(file => file.FullName.Count(c => c == Path.DirectorySeparatorChar))
                                    .Where(file => OrderedSettingsFileNames.Any(fileName => fileName.Equals(file.Name, comparer)));

            validSettingFiles.AddRange(
                settingsFiles
                .Select(file => ReadSettings(file.DirectoryName, file.FullName, settingsLoadingContext: settingsLoadingContext))
                .Where(file => file != null));

            return(LoadSettingsForSpecificConfigs(
                       root.FullName,
                       configFileName: null,
                       validSettingFiles,
                       machineWideSettings,
                       loadUserWideSettings,
                       useTestingGlobalPath,
                       settingsLoadingContext));
        }
Esempio n. 6
0
        public RepositorySettings(ISolutionManager solutionManager, IFileSystemProvider fileSystemProvider, IVsSourceControlTracker sourceControlTracker, IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }

            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }

            if (sourceControlTracker == null)
            {
                throw new ArgumentNullException("sourceControlTracker");
            }

            _solutionManager = solutionManager;
            _fileSystemProvider = fileSystemProvider;
            _settings = null;
            _machineWideSettings = machineWideSettings;

            EventHandler resetConfiguration = (sender, e) =>
            {
                // Kill our configuration cache when someone closes the solution
                _configurationPath = null;
                _fileSystem = null;
                _settings = null;
            };

            _solutionManager.SolutionClosing += resetConfiguration;
            sourceControlTracker.SolutionBoundToSourceControl += resetConfiguration;
        }
Esempio n. 7
0
        /// <summary>
        /// Loads user settings from the NuGet configuration files. The method walks the directory
        /// tree in <paramref name="fileSystem"/> up to its root, and reads each NuGet.config file
        /// it finds in the directories. It then reads the user specific settings,
        /// which is file <paramref name="configFileName"/>
        /// in <paramref name="fileSystem"/> if <paramref name="configFileName"/> is not null,
        /// If <paramref name="configFileName"/> is null, the user specific settings file is
        /// %AppData%\NuGet\NuGet.config.
        /// After that, the machine wide settings files are added.
        /// </summary>
        /// <remarks>
        /// For example, if <paramref name="fileSystem"/> is c:\dir1\dir2, <paramref name="configFileName"/>
        /// is "userConfig.file", the files loaded are (in the order that they are loaded):
        ///     c:\dir1\dir2\nuget.config
        ///     c:\dir1\nuget.config
        ///     c:\nuget.config
        ///     c:\dir1\dir2\userConfig.file
        ///     machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
        /// </remarks>
        /// <param name="fileSystem">The file system to walk to find configuration files.</param>
        /// <param name="configFileName">The user specified configuration file.</param>
        /// <param name="machineWideSettings">The machine wide settings. If it's not null, the
        /// settings files in the machine wide settings are added after the user sepcific
        /// config file.</param>
        /// <returns>The settings object loaded.</returns>
        public static ISettings LoadDefaultSettings(
            IFileSystem fileSystem,
            string configFileName,
            IMachineWideSettings machineWideSettings)
        {
            // Walk up the tree to find a config file; also look in .nuget subdirectories
            var validSettingFiles    = new List <Settings>();
            var userSettingsDir      = DnuEnvironment.GetFolderPath(DnuFolderPath.UserSettingsDirectory);
            var redirectSettingsPath = Path.Combine(userSettingsDir,
                                                    "nuget.redirect.config");

            Settings redirectSettings = null;

            if (fileSystem != null)
            {
                validSettingFiles.AddRange(
                    GetSettingsFileNames(fileSystem)
                    .Select(f => ReadSettings(fileSystem, f))
                    .Where(f => f != null));

                if (fileSystem.FileExists(redirectSettingsPath))
                {
                    redirectSettings = ReadSettings(fileSystem, redirectSettingsPath);
                }
            }

            LoadUserSpecificSettings(validSettingFiles, fileSystem, configFileName);

            if (machineWideSettings != null)
            {
                validSettingFiles.AddRange(
                    machineWideSettings.Settings.Select(
                        s => new Settings(s._fileSystem, s._fileName, s._isMachineWideSettings)));
            }

            if (validSettingFiles.IsEmpty())
            {
                // This means we've failed to load all config files and also failed to load or create the one in %AppData%
                // 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 and also from picking up the wrong config
                return(NullSettings.Instance);
            }

            validSettingFiles[0]._redirect = redirectSettings;

            // if multiple setting files were loaded, chain them in a linked list
            for (int i = 1; i < validSettingFiles.Count; ++i)
            {
                validSettingFiles[i]._next     = validSettingFiles[i - 1];
                validSettingFiles[i]._redirect = redirectSettings;
            }

            // return the linked list head. Typicall, it's either the config file in %ProgramData%\NuGet\Config,
            // or the user specific config (%APPDATA%\NuGet\nuget.config) if there are no machine
            // wide config files. The head file is the one we want to read first, while the user specific config
            // is the one that we want to write to.
            // TODO: add UI to allow specifying which one to write to
            return(validSettingFiles.Last());
        }
Esempio n. 8
0
        /// <summary>
        /// For internal use only
        /// </summary>
        public static ISettings LoadDefaultSettings(
            string root,
            string configFileName,
            IMachineWideSettings machineWideSettings,
            bool loadAppDataSettings,
            bool useTestingGlobalPath)
        {
            {
                // Walk up the tree to find a config file; also look in .nuget subdirectories
                // If a configFile is passed, don't walk up the tree. Only use that single config file.
                var validSettingFiles = new List <Settings>();
                if (root != null && string.IsNullOrEmpty(configFileName))
                {
                    validSettingFiles.AddRange(
                        GetSettingsFileNames(root)
                        .Select(f => ReadSettings(root, f))
                        .Where(f => f != null));
                }

                if (loadAppDataSettings)
                {
                    LoadUserSpecificSettings(validSettingFiles, root, configFileName, machineWideSettings, useTestingGlobalPath);
                }

                if (machineWideSettings != null && string.IsNullOrEmpty(configFileName))
                {
                    validSettingFiles.AddRange(
                        machineWideSettings.Settings.Select(
                            s => new Settings(s.Root, s.FileName, s.IsMachineWideSettings)));
                }

                if (validSettingFiles == null ||
                    !validSettingFiles.Any())
                {
                    // This means we've failed to load all config files and also failed to load or create the one in %AppData%
                    // 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 and also from picking up the wrong config
                    return(NullSettings.Instance);
                }

                SetClearTagForSettings(validSettingFiles);

                validSettingFiles[0]._priority = validSettingFiles.Count;

                // if multiple setting files were loaded, chain them in a linked list
                for (var i = 1; i < validSettingFiles.Count; ++i)
                {
                    validSettingFiles[i]._next     = validSettingFiles[i - 1];
                    validSettingFiles[i]._priority = validSettingFiles[i - 1]._priority - 1;
                }

                // return the linked list head. Typicall, it's either the config file in %ProgramData%\NuGet\Config,
                // or the user specific config (%APPDATA%\NuGet\nuget.config) if there are no machine
                // wide config files. The head file is the one we want to read first, while the user specific config
                // is the one that we want to write to.
                // TODO: add UI to allow specifying which one to write to
                return(validSettingFiles.Last());
            }
        }
		ISettings LoadDefaultSettings (IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings)
		{
			fileSystemUsedToLoadSettings = fileSystem;
			configFileUsedToLoadSettings = configFile;
			machinesettingsUsedToLoadSettings = machineSettings;

			return fakeSettings;
		}
        ISettings LoadDefaultSettings(IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings)
        {
            fileSystemUsedToLoadSettings      = fileSystem;
            configFileUsedToLoadSettings      = configFile;
            machinesettingsUsedToLoadSettings = machineSettings;

            return(fakeSettings);
        }
Esempio n. 11
0
 public VsSettings(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings)
     : this(solutionManager,
         Settings.LoadDefaultSettings(
             GetSolutionSettingsFileSystem(solutionManager), 
             null,
             machineWideSettings), 
         new PhysicalFileSystemProvider(),
         machineWideSettings)
 {
     // Review: Do we need to pass in the VsFileSystemProvider here instead of hardcoding PhysicalFileSystems?
 }
 private static void AssertExpectedConfigFilesLoaded(IMachineWideSettings actual, string baseDir, params string[] relativeConfigFilePaths)
 {
     Assert.IsNotNull(actual, "MachineWideSettings should not be null");
     foreach (string relativePath in relativeConfigFilePaths)
     {
         string fullPath = Path.Combine(baseDir, relativePath);
         Assert.IsTrue(actual.Settings.Any(s => string.Equals(s.ConfigFilePath, fullPath, StringComparison.OrdinalIgnoreCase)),
             "Expected config file was not loaded: {0}", relativePath);
     }
     Assert.AreEqual(relativeConfigFilePaths.Length, actual.Settings.Count(), "Too many config files loaded");
 }
Esempio n. 13
0
        public VsPackageManagerFactory(ISolutionManager solutionManager,
                                       IPackageRepositoryFactory repositoryFactory,
                                       IVsPackageSourceProvider packageSourceProvider,
                                       IFileSystemProvider fileSystemProvider,
                                       IRepositorySettings repositorySettings,
                                       VsPackageInstallerEvents packageEvents,
                                       IPackageRepository activePackageSourceRepository,
                                       IVsFrameworkMultiTargeting frameworkMultiTargeting,
                                       IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }
            if (repositoryFactory == null)
            {
                throw new ArgumentNullException("repositoryFactory");
            }
            if (packageSourceProvider == null)
            {
                throw new ArgumentNullException("packageSourceProvider");
            }
            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }
            if (repositorySettings == null)
            {
                throw new ArgumentNullException("repositorySettings");
            }
            if (packageEvents == null)
            {
                throw new ArgumentNullException("packageEvents");
            }
            if (activePackageSourceRepository == null)
            {
                throw new ArgumentNullException("activePackageSourceRepository");
            }

            _fileSystemProvider            = fileSystemProvider;
            _repositorySettings            = repositorySettings;
            _solutionManager               = solutionManager;
            _repositoryFactory             = repositoryFactory;
            _packageSourceProvider         = packageSourceProvider;
            _packageEvents                 = packageEvents;
            _activePackageSourceRepository = activePackageSourceRepository;
            _frameworkMultiTargeting       = frameworkMultiTargeting;
            _machineWideSettings           = machineWideSettings;

            _solutionManager.SolutionClosing += (sender, e) =>
            {
                _repositoryInfo = null;
            };
        }
 private static void AssertExpectedConfigFilesLoaded(IMachineWideSettings actual, string baseDir, params string[] relativeConfigFilePaths)
 {
     actual.Should().NotBeNull("MachineWideSettings should not be null");
     foreach (string relativePath in relativeConfigFilePaths)
     {
         string fullPath = Path.Combine(baseDir, relativePath);
         actual.Settings.Any(s => string.Equals(s.ConfigFilePath, fullPath, StringComparison.OrdinalIgnoreCase)).Should()
         .BeTrue("Expected config file was not loaded: {0}", relativePath);
     }
     actual.Settings.Count().Should().Be(relativeConfigFilePaths.Length, "Too many config files loaded");
 }
        public VsPackageManagerFactory(ISolutionManager solutionManager,
                                       IPackageRepositoryFactory repositoryFactory,
                                       IVsPackageSourceProvider packageSourceProvider,
                                       IFileSystemProvider fileSystemProvider,
                                       IRepositorySettings repositorySettings,
                                       VsPackageInstallerEvents packageEvents,
                                       IPackageRepository activePackageSourceRepository,
                                       IVsFrameworkMultiTargeting frameworkMultiTargeting,
									   IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }
            if (repositoryFactory == null)
            {
                throw new ArgumentNullException("repositoryFactory");
            }
            if (packageSourceProvider == null)
            {
                throw new ArgumentNullException("packageSourceProvider");
            }
            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }
            if (repositorySettings == null)
            {
                throw new ArgumentNullException("repositorySettings");
            }
            if (packageEvents == null)
            {
                throw new ArgumentNullException("packageEvents");
            }
            if (activePackageSourceRepository == null)
            {
                throw new ArgumentNullException("activePackageSourceRepository");
            }

            _fileSystemProvider = fileSystemProvider;
            _repositorySettings = repositorySettings;
            _solutionManager = solutionManager;
            _repositoryFactory = repositoryFactory;
            _packageSourceProvider = packageSourceProvider;
            _packageEvents = packageEvents;
            _activePackageSourceRepository = activePackageSourceRepository;
            _frameworkMultiTargeting = frameworkMultiTargeting;
			_machineWideSettings = machineWideSettings;

            _solutionManager.SolutionClosing += (sender, e) =>
            {
                _repositoryInfo = null;
            };
        }
Esempio n. 16
0
 /// <summary>
 /// Loads user settings from the NuGet configuration files. The method walks the directory
 /// tree in <paramref name="fileSystem"/> up to its root, and reads each NuGet.config file
 /// it finds in the directories. It then reads the user specific settings,
 /// which is file <paramref name="configFileName"/>
 /// in <paramref name="fileSystem"/> if <paramref name="configFileName"/> is not null,
 /// If <paramref name="configFileName"/> is null, the user specific settings file is
 /// %AppData%\NuGet\NuGet.config.
 /// After that, the machine wide settings files are added.
 /// </summary>
 /// <remarks>
 /// For example, if <paramref name="fileSystem"/> is c:\dir1\dir2, <paramref name="configFileName"/>
 /// is "userConfig.file", the files loaded are (in the order that they are loaded):
 ///     c:\dir1\dir2\nuget.config
 ///     c:\dir1\nuget.config
 ///     c:\nuget.config
 ///     c:\dir1\dir2\userConfig.file
 ///     machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
 /// </remarks>
 /// <param name="fileSystem">The file system to walk to find configuration files.
 /// Can be null.</param>
 /// <param name="configFileName">The user specified configuration file.</param>
 /// <param name="machineWideSettings">The machine wide settings. If it's not null, the
 /// settings files in the machine wide settings are added after the user sepcific
 /// config file.</param>
 /// <returns>The settings object loaded.</returns>
 public static ISettings LoadDefaultSettings(
     string root,
     string configFileName,
     IMachineWideSettings machineWideSettings)
 {
     return(LoadDefaultSettings(
                root,
                configFileName,
                machineWideSettings,
                loadAppDataSettings: true));
 }
Esempio n. 17
0
 public VsSettings(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings)
     : this(solutionManager,
            Settings.LoadDefaultSettings(
                GetSolutionSettingsFileSystem(solutionManager),
                null,
                machineWideSettings),
            new PhysicalFileSystemProvider(),
            machineWideSettings)
 {
     // Review: Do we need to pass in the VsFileSystemProvider here instead of hardcoding PhysicalFileSystems?
 }
Esempio n. 18
0
 /// <summary>
 /// Loads user settings from the NuGet configuration files. The method walks the directory
 /// tree in <paramref name="root" /> up to its root, and reads each NuGet.config file
 /// it finds in the directories. It then reads the user specific settings,
 /// which is file <paramref name="configFileName" />
 /// in <paramref name="root" /> if <paramref name="configFileName" /> is not null,
 /// If <paramref name="configFileName" /> is null, the user specific settings file is
 /// %AppData%\NuGet\NuGet.config.
 /// After that, the machine wide settings files are added.
 /// </summary>
 /// <remarks>
 /// For example, if <paramref name="root" /> is c:\dir1\dir2, <paramref name="configFileName" />
 /// is "userConfig.file", the files loaded are (in the order that they are loaded):
 /// c:\dir1\dir2\nuget.config
 /// c:\dir1\nuget.config
 /// c:\nuget.config
 /// c:\dir1\dir2\userConfig.file
 /// machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
 /// </remarks>
 /// <param name="root">
 /// The file system to walk to find configuration files.
 /// Can be null.
 /// </param>
 /// <param name="configFileName">The user specified configuration file.</param>
 /// <param name="machineWideSettings">
 /// The machine wide settings. If it's not null, the
 /// settings files in the machine wide settings are added after the user sepcific
 /// config file.
 /// </param>
 /// <returns>The settings object loaded.</returns>
 public static ISettings LoadDefaultSettings(
     string root,
     string configFileName,
     IMachineWideSettings machineWideSettings)
 {
     return(LoadSettings(
                root,
                configFileName,
                machineWideSettings,
                loadUserWideSettings: true,
                useTestingGlobalPath: false));
 }
        public VSSettings(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings)
        {
            if(solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }

            SolutionManager = solutionManager;
            MachineWideSettings = machineWideSettings;
            ResetSolutionSettings();
            SolutionManager.SolutionOpening += OnSolutionOpenedOrClosed;
            SolutionManager.SolutionClosed += OnSolutionOpenedOrClosed;
        }        
 public TestVsPackageManagerFactory(
     ISolutionManager solutionManager,
     IPackageRepositoryFactory repositoryFactory,
     IVsPackageSourceProvider packageSourceProvider,
     IFileSystemProvider fileSystemProvider,
     IRepositorySettings repositorySettings,
     VsPackageInstallerEvents packageEvents,
     IPackageRepository activePackageSourceRepository,
     IVsFrameworkMultiTargeting frameworkMultiTargeting,
     IMachineWideSettings machineWideSettings)
     : base(solutionManager, repositoryFactory, packageSourceProvider, fileSystemProvider, repositorySettings, packageEvents, activePackageSourceRepository, frameworkMultiTargeting, machineWideSettings)
 {
 }
Esempio n. 21
0
        public VSSettings(ISolutionManager solutionManager, IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }

            SolutionManager     = solutionManager;
            MachineWideSettings = machineWideSettings;
            ResetSolutionSettings();
            SolutionManager.SolutionOpening += OnSolutionOpenedOrClosed;
            SolutionManager.SolutionClosed  += OnSolutionOpenedOrClosed;
        }
        public VsPackageManagerFactory(ISolutionManager solutionManager,
                                       IPackageRepositoryFactory repositoryFactory,
                                       IVsPackageSourceProvider packageSourceProvider,
                                       IFileSystemProvider fileSystemProvider,
                                       IRepositorySettings repositorySettings,
                                       VsPackageInstallerEvents packageEvents,
                                       IPackageRepository activePackageSourceRepository,
									   IMachineWideSettings machineWideSettings) :
            this(solutionManager, 
                 repositoryFactory, 
                 packageSourceProvider, 
                 fileSystemProvider, 
                 repositorySettings, 
                 packageEvents,
                 activePackageSourceRepository,
                 ServiceLocator.GetGlobalService<SVsFrameworkMultiTargeting, IVsFrameworkMultiTargeting>(),
				 machineWideSettings)
        {
        }
Esempio n. 23
0
 public VsPackageManagerFactory(ISolutionManager solutionManager,
                                IPackageRepositoryFactory repositoryFactory,
                                IVsPackageSourceProvider packageSourceProvider,
                                IFileSystemProvider fileSystemProvider,
                                IRepositorySettings repositorySettings,
                                VsPackageInstallerEvents packageEvents,
                                IPackageRepository activePackageSourceRepository,
                                IMachineWideSettings machineWideSettings) :
     this(solutionManager,
          repositoryFactory,
          packageSourceProvider,
          fileSystemProvider,
          repositorySettings,
          packageEvents,
          activePackageSourceRepository,
          ServiceLocator.GetGlobalService <SVsFrameworkMultiTargeting, IVsFrameworkMultiTargeting>(),
          machineWideSettings)
 {
 }
Esempio n. 24
0
        private static ISettings LoadSettingsForSpecificConfigs(
            string root,
            string configFileName,
            List <SettingsFile> validSettingFiles,
            IMachineWideSettings machineWideSettings,
            bool loadUserWideSettings,
            bool useTestingGlobalPath)
        {
            if (loadUserWideSettings)
            {
                var userSpecific = LoadUserSpecificSettings(root, configFileName, useTestingGlobalPath);
                if (userSpecific != null)
                {
                    validSettingFiles.Add(userSpecific);
                }
            }

            if (machineWideSettings != null && machineWideSettings.Settings is Settings mwSettings && string.IsNullOrEmpty(configFileName))
            {
                // Priority gives you the settings file in the order you want to start reading them
                validSettingFiles.AddRange(
                    mwSettings.Priority.Select(
                        s => new SettingsFile(s.DirectoryPath, s.FileName, s.IsMachineWide)));
            }

            if (validSettingFiles?.Any() != true)
            {
                // This means we've failed to load all config files and also failed to load or create the one in %AppData%
                // 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 and also from picking up the wrong config
                return(NullSettings.Instance);
            }

            SettingsFile.ConnectSettingsFilesLinkedList(validSettingFiles);

            // Create a settings object with the linked list head. Typically, it's either the config file in %ProgramData%\NuGet\Config,
            // or the user wide config (%APPDATA%\NuGet\nuget.config) if there are no machine
            // wide config files. The head file is the one we want to read first, while the user wide config
            // is the one that we want to write to.
            // TODO: add UI to allow specifying which one to write to
            return(new Settings(validSettingFiles.Last()));
        }
Esempio n. 25
0
        public static ISettings ReadSettings(string solutionDir, string nugetConfigFile, IFileSystem fileSystem,
            IMachineWideSettings machineWideSettings)
        {
            // Read the solution-level settings
            var solutionSettingsFile = Path.Combine(solutionDir, NuGetConstants.NuGetSolutionSettingsFolder);
            var fullPath = fileSystem.GetFullPath(solutionSettingsFile);
            var solutionSettingsFileSystem = new PhysicalFileSystem(fullPath);

            if (nugetConfigFile != null)
            {
                nugetConfigFile = fileSystem.GetFullPath(nugetConfigFile);
            }

            var settings = Settings.LoadDefaultSettings(
                fileSystem: solutionSettingsFileSystem,
                configFileName: nugetConfigFile,
                machineWideSettings: machineWideSettings);

            return settings;
        }
Esempio n. 26
0
        public static ISettings ReadSettings(string solutionDir, string nugetConfigFile, IFileSystem fileSystem,
                                             IMachineWideSettings machineWideSettings)
        {
            // Read the solution-level settings
            var solutionSettingsFile       = Path.Combine(solutionDir, NuGetConstants.NuGetSolutionSettingsFolder);
            var fullPath                   = fileSystem.GetFullPath(solutionSettingsFile);
            var solutionSettingsFileSystem = new PhysicalFileSystem(fullPath);

            if (nugetConfigFile != null)
            {
                nugetConfigFile = fileSystem.GetFullPath(nugetConfigFile);
            }

            var settings = Settings.LoadDefaultSettings(
                fileSystem: solutionSettingsFileSystem,
                configFileName: nugetConfigFile,
                machineWideSettings: machineWideSettings);

            return(settings);
        }
Esempio n. 27
0
        /// <summary>
        /// For internal use only
        /// </summary>
        public static ISettings LoadDefaultSettings(
            string root,
            string configFileName,
            IMachineWideSettings machineWideSettings,
            bool loadAppDataSettings,
            bool useTestingGlobalPath)
        {
            {
                // Walk up the tree to find a config file; also look in .nuget subdirectories
                // If a configFile is passed, don't walk up the tree. Only use that single config file.
                var validSettingFiles = new List <Settings>();
                if (root != null && string.IsNullOrEmpty(configFileName))
                {
                    validSettingFiles.AddRange(
                        GetSettingsFileNames(root)
                        .Select(f => ReadSettings(root, f))
                        .Where(f => f != null));
                }

                return(LoadSettingsForSpecificConfigs(root, configFileName, validSettingFiles, machineWideSettings, loadAppDataSettings, useTestingGlobalPath));
            }
        }
Esempio n. 28
0
        public VsSettings(ISolutionManager solutionManager, ISettings defaultSettings, IFileSystemProvider fileSystemProvider, IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }
            if (defaultSettings == null)
            {
                throw new ArgumentNullException("defaultSettings");
            }
            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }

            _solutionManager     = solutionManager;
            _defaultSettings     = defaultSettings;
            _machineWideSettings = machineWideSettings;
            _fileSystemProvider  = fileSystemProvider;

            _solutionManager.SolutionOpened += OnSolutionOpenedOrClosed;
            _solutionManager.SolutionClosed += OnSolutionOpenedOrClosed;
        }
Esempio n. 29
0
        public VsSettings(ISolutionManager solutionManager, ISettings defaultSettings, IFileSystemProvider fileSystemProvider, IMachineWideSettings machineWideSettings)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solutionManager");
            }
            if (defaultSettings == null)
            {
                throw new ArgumentNullException("defaultSettings");
            }
            if (fileSystemProvider == null)
            {
                throw new ArgumentNullException("fileSystemProvider");
            }

            _solutionManager = solutionManager;
            _defaultSettings = defaultSettings;
            _machineWideSettings = machineWideSettings;
            _fileSystemProvider = fileSystemProvider;            

            _solutionManager.SolutionOpened += OnSolutionOpenedOrClosed;
            _solutionManager.SolutionClosed += OnSolutionOpenedOrClosed;
        }
Esempio n. 30
0
 public PackageAgentProvider(IMachineWideSettings settings) : this(settings.Settings)
 {
 }
Esempio n. 31
0
        /// <summary>
        /// Loads user settings from the NuGet configuration files. The method walks the directory
        /// tree in <paramref name="fileSystem"/> up to its root, and reads each NuGet.config file
        /// it finds in the directories. It then reads the user specific settings,
        /// which is file <paramref name="configFileName"/>
        /// in <paramref name="fileSystem"/> if <paramref name="configFileName"/> is not null,
        /// If <paramref name="configFileName"/> is null, the user specific settings file is
        /// %AppData%\NuGet\NuGet.config.
        /// After that, the machine wide settings files are added.
        /// </summary>
        /// <remarks>
        /// For example, if <paramref name="fileSystem"/> is c:\dir1\dir2, <paramref name="configFileName"/> 
        /// is "userConfig.file", the files loaded are (in the order that they are loaded):
        ///     c:\dir1\dir2\nuget.config
        ///     c:\dir1\nuget.config
        ///     c:\nuget.config
        ///     c:\dir1\dir2\userConfig.file
        ///     machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
        /// </remarks>
        /// <param name="fileSystem">The file system to walk to find configuration files.</param>
        /// <param name="configFileName">The user specified configuration file.</param>
        /// <param name="machineWideSettings">The machine wide settings. If it's not null, the
        /// settings files in the machine wide settings are added after the user sepcific 
        /// config file.</param>
        /// <returns>The settings object loaded.</returns>
        public static ISettings LoadDefaultSettings(
            IFileSystem fileSystem,
            string configFileName,
            IMachineWideSettings machineWideSettings)
        {
            // Walk up the tree to find a config file; also look in .nuget subdirectories
            var validSettingFiles = new List<Settings>();
            if (fileSystem != null)
            {
                validSettingFiles.AddRange(
                    GetSettingsFileNames(fileSystem)
                        .Select(f => ReadSettings(fileSystem, f))
                        .Where(f => f != null));
            }

            LoadUserSpecificSettings(validSettingFiles, fileSystem, configFileName);

            if (machineWideSettings != null)
            {
                validSettingFiles.AddRange(machineWideSettings.Settings);
            }

            if (validSettingFiles.IsEmpty())
            {
                // This means we've failed to load all config files and also failed to load or create the one in %AppData%
                // 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 and also from picking up the wrong config
                return NullSettings.Instance;
            }

            // if multiple setting files were loaded, chain them in a linked list
            for (int i = 1; i < validSettingFiles.Count; ++i)
            {
                validSettingFiles[i]._next = validSettingFiles[i - 1];
            }

            // return the linked list head. Typicall, it's either the config file in %ProgramData%\NuGet\Config,
            // or the user specific config (%APPDATA%\NuGet\nuget.config) if there are no machine
            // wide config files. The head file is the one we want to read first, while the user specific config 
            // is the one that we want to write to.
            // TODO: add UI to allow specifying which one to write to
            return validSettingFiles.Last();
        }
Esempio n. 32
0
 public TestVsPackageManagerFactory(
     ISolutionManager solutionManager,
     IPackageRepositoryFactory repositoryFactory,
     IVsPackageSourceProvider packageSourceProvider,
     IFileSystemProvider fileSystemProvider,
     IRepositorySettings repositorySettings,
     VsPackageInstallerEvents packageEvents,
     IPackageRepository activePackageSourceRepository,
     IVsFrameworkMultiTargeting frameworkMultiTargeting,
     IMachineWideSettings machineWideSettings)
     : base(solutionManager, repositoryFactory, packageSourceProvider, fileSystemProvider, repositorySettings, packageEvents, activePackageSourceRepository, frameworkMultiTargeting, machineWideSettings)
 {
 }
Esempio n. 33
0
        private static void LoadUserSpecificSettings(
            List <Settings> validSettingFiles,
            string root,
            string configFileName,
            IMachineWideSettings machineWideSettings,
            bool useTestingGlobalPath
            )
        {
            if (root == null)
            {
                // Path.Combine is performed with root so it should not be null
                // However, it is legal for it be empty in this method
                root = String.Empty;
            }
            // for the default location, allow case where file does not exist, in which case it'll end
            // up being created if needed
            Settings appDataSettings = null;

            if (configFileName == null)
            {
                var defaultSettingsFilePath = String.Empty;
                if (useTestingGlobalPath)
                {
                    defaultSettingsFilePath = Path.Combine(root, "TestingGlobalPath", DefaultSettingsFileName);
                }
                else
                {
                    var userSettingsDir = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);

                    // If there is no user settings directory, return no appdata settings
                    if (userSettingsDir == null)
                    {
                        return;
                    }
                    defaultSettingsFilePath = Path.Combine(userSettingsDir, DefaultSettingsFileName);
                }

                if (!File.Exists(defaultSettingsFilePath) && machineWideSettings != null)
                {
                    // Since defaultSettingsFilePath is a full path, so it doesn't matter what value is
                    // used as root for the PhysicalFileSystem.
                    appDataSettings = ReadSettings(
                        root,
                        defaultSettingsFilePath);

                    // Disable machinewide sources to improve perf
                    var disabledSources = new List <SettingValue>();
                    foreach (var setting in machineWideSettings.Settings)
                    {
                        var values = setting.GetSettingValues(ConfigurationConstants.PackageSources, isPath: true);
                        foreach (var value in values)
                        {
                            var packageSource = new PackageSource(value.Value);

                            // if the machine wide package source is http source, disable it by default
                            if (packageSource.IsHttp)
                            {
                                disabledSources.Add(new SettingValue(value.Key, "true", origin: setting, isMachineWide: true, priority: 0));
                            }
                        }
                    }
                    appDataSettings.UpdateSections(ConfigurationConstants.DisabledPackageSources, disabledSources);
                }
                else
                {
                    appDataSettings = ReadSettings(root, defaultSettingsFilePath);
                    bool IsEmptyConfig = !appDataSettings.GetSettingValues(ConfigurationConstants.PackageSources).Any();

                    if (IsEmptyConfig)
                    {
                        var trackFilePath = Path.Combine(Path.GetDirectoryName(defaultSettingsFilePath), NuGetConstants.AddV3TrackFile);

                        if (!File.Exists(trackFilePath))
                        {
                            File.Create(trackFilePath).Dispose();
                            var defaultPackageSource = new SettingValue(NuGetConstants.FeedName, NuGetConstants.V3FeedUrl, isMachineWide: false);
                            defaultPackageSource.AdditionalData.Add(ConfigurationConstants.ProtocolVersionAttribute, "3");
                            appDataSettings.UpdateSections(ConfigurationConstants.PackageSources, new List <SettingValue> {
                                defaultPackageSource
                            });
                        }
                    }
                }
            }
            else
            {
                if (!FileSystemUtility.DoesFileExistIn(root, configFileName))
                {
                    var message = String.Format(CultureInfo.CurrentCulture,
                                                Resources.FileDoesNotExist,
                                                Path.Combine(root, configFileName));
                    throw new InvalidOperationException(message);
                }

                appDataSettings = ReadSettings(root, configFileName);
            }

            if (appDataSettings != null)
            {
                validSettingFiles.Add(appDataSettings);
            }
        }
Esempio n. 34
0
 /// <summary>
 /// Loads user settings from the NuGet configuration files. The method walks the directory
 /// tree in <paramref name="fileSystem" /> up to its root, and reads each NuGet.config file
 /// it finds in the directories. It then reads the user specific settings,
 /// which is file <paramref name="configFileName" />
 /// in <paramref name="fileSystem" /> if <paramref name="configFileName" /> is not null,
 /// If <paramref name="configFileName" /> is null, the user specific settings file is
 /// %AppData%\NuGet\NuGet.config.
 /// After that, the machine wide settings files are added.
 /// </summary>
 /// <remarks>
 /// For example, if <paramref name="fileSystem" /> is c:\dir1\dir2, <paramref name="configFileName" />
 /// is "userConfig.file", the files loaded are (in the order that they are loaded):
 /// c:\dir1\dir2\nuget.config
 /// c:\dir1\nuget.config
 /// c:\nuget.config
 /// c:\dir1\dir2\userConfig.file
 /// machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
 /// </remarks>
 /// <param name="fileSystem">
 /// The file system to walk to find configuration files.
 /// Can be null.
 /// </param>
 /// <param name="configFileName">The user specified configuration file.</param>
 /// <param name="machineWideSettings">
 /// The machine wide settings. If it's not null, the
 /// settings files in the machine wide settings are added after the user sepcific
 /// config file.
 /// </param>
 /// <returns>The settings object loaded.</returns>
 public static ISettings LoadDefaultSettings(
     string root,
     string configFileName,
     IMachineWideSettings machineWideSettings)
 {
     return LoadDefaultSettings(
         root,
         configFileName,
         machineWideSettings,
         loadAppDataSettings: true);
 }
Esempio n. 35
0
        /// <summary>
        /// Loads user settings from the NuGet configuration files. The method walks the directory
        /// tree in <paramref name="fileSystem"/> up to its root, and reads each NuGet.config file
        /// it finds in the directories. It then reads the user specific settings,
        /// which is file <paramref name="configFileName"/>
        /// in <paramref name="fileSystem"/> if <paramref name="configFileName"/> is not null,
        /// If <paramref name="configFileName"/> is null, the user specific settings file is
        /// %AppData%\NuGet\NuGet.config.
        /// After that, the machine wide settings files are added.
        /// </summary>
        /// <remarks>
        /// For example, if <paramref name="fileSystem"/> is c:\dir1\dir2, <paramref name="configFileName"/> 
        /// is "userConfig.file", the files loaded are (in the order that they are loaded):
        ///     c:\dir1\dir2\nuget.config
        ///     c:\dir1\nuget.config
        ///     c:\nuget.config
        ///     c:\dir1\dir2\userConfig.file
        ///     machine wide settings (e.g. c:\programdata\NuGet\Config\*.config)
        /// </remarks>
        /// <param name="fileSystem">The file system to walk to find configuration files.</param>
        /// <param name="configFileName">The user specified configuration file.</param>
        /// <param name="machineWideSettings">The machine wide settings. If it's not null, the
        /// settings files in the machine wide settings are added after the user sepcific 
        /// config file.</param>
        /// <returns>The settings object loaded.</returns>
        public static ISettings LoadDefaultSettings(
            IFileSystem fileSystem,
            string configFileName,
            IMachineWideSettings machineWideSettings)
        {
            // Walk up the tree to find a config file; also look in .nuget subdirectories
            var validSettingFiles = new List<Settings>();
            #if DNX451
            var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            #else
            var appData = Environment.GetEnvironmentVariable("APPDATA");
            #endif
            var redirectSettingsPath = Path.Combine(appData,
                                                    "nuget",
                                                    "nuget.redirect.config");

            Settings redirectSettings = null;
            if (fileSystem != null)
            {
                validSettingFiles.AddRange(
                    GetSettingsFileNames(fileSystem)
                        .Select(f => ReadSettings(fileSystem, f))
                        .Where(f => f != null));

                if (fileSystem.FileExists(redirectSettingsPath))
                {
                    redirectSettings = ReadSettings(fileSystem, redirectSettingsPath);
                }
            }

            LoadUserSpecificSettings(validSettingFiles, fileSystem, configFileName);

            if (machineWideSettings != null)
            {
                validSettingFiles.AddRange(
                    machineWideSettings.Settings.Select(
                        s => new Settings(s._fileSystem, s._fileName, s._isMachineWideSettings)));
            }

            if (validSettingFiles.IsEmpty())
            {
                // This means we've failed to load all config files and also failed to load or create the one in %AppData%
                // 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 and also from picking up the wrong config
                return NullSettings.Instance;
            }

            validSettingFiles[0]._redirect = redirectSettings;

            // if multiple setting files were loaded, chain them in a linked list
            for (int i = 1; i < validSettingFiles.Count; ++i)
            {
                validSettingFiles[i]._next = validSettingFiles[i - 1];
                validSettingFiles[i]._redirect = redirectSettings;
            }

            // return the linked list head. Typicall, it's either the config file in %ProgramData%\NuGet\Config,
            // or the user specific config (%APPDATA%\NuGet\nuget.config) if there are no machine
            // wide config files. The head file is the one we want to read first, while the user specific config
            // is the one that we want to write to.
            // TODO: add UI to allow specifying which one to write to
            return validSettingFiles.Last();
        }