/// <summary> /// Initialize a new instance of <see cref="NugetStore"/>. /// </summary> /// <param name="oldRootDirectory">The location of the Nuget store.</param> public NugetStore(string oldRootDirectory) { // Used only for versions before 3.0 this.oldRootDirectory = oldRootDirectory; settings = NuGet.Configuration.Settings.LoadDefaultSettings(null); // Add dev source CheckPackageSource("Xenko", DefaultPackageSource); InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings); var pathContext = NuGetPathContext.Create(settings); InstalledPathResolver = new FallbackPackagePathResolver(pathContext.UserPackageFolder, oldRootDirectory != null ? pathContext.FallbackPackageFolders.Concat(new[] { oldRootDirectory }) : pathContext.FallbackPackageFolders); var packageSourceProvider = new PackageSourceProvider(settings); var availableSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled); var packageSources = new List <PackageSource>(); packageSources.AddRange(availableSources); PackageSources = packageSources; // Setup source provider as a V3 only. sourceRepositoryProvider = new NugetSourceRepositoryProvider(packageSourceProvider, this); }
/// <summary> /// Initialize a new instance of <see cref="NugetStore"/>. /// </summary> /// <param name="oldRootDirectory">The location of the Nuget store.</param> public NugetStore(string oldRootDirectory) { // Used only for versions before 3.0 this.oldRootDirectory = oldRootDirectory; settings = NuGet.Configuration.Settings.LoadDefaultSettings(null); // Remove obsolete sources RemoveDeletedSources(settings, "Xenko Dev"); // Note the space: we want to keep "Stride Dev" but not "Stride Dev {PATH}\bin\packages" anymore RemoveSources(settings, "Stride Dev "); settings.SaveToDisk(); InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings); var pathContext = NuGetPathContext.Create(settings); InstalledPathResolver = new FallbackPackagePathResolver(pathContext.UserPackageFolder, oldRootDirectory != null ? pathContext.FallbackPackageFolders.Concat(new[] { oldRootDirectory }) : pathContext.FallbackPackageFolders); var packageSourceProvider = new PackageSourceProvider(settings); var availableSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled); var packageSources = new List <PackageSource>(); packageSources.AddRange(availableSources); PackageSources = packageSources; // Setup source provider as a V3 only. sourceRepositoryProvider = new NugetSourceRepositoryProvider(packageSourceProvider, this); }
/// <summary> /// Initialize NugetStore using <paramref name="rootDirectory"/> as location of the local copies, /// and a configuration file <paramref name="configFile"/> as well as an override configuration /// file <paramref name="overrideFile"/> where all settings of <paramref name="overrideFile"/> also /// presents in <paramref name="configFile"/> take precedence. /// </summary> /// <param name="rootDirectory">The location of the Nuget store.</param> public NugetStore(string rootDirectory, string configFile = DefaultConfig) { RootDirectory = rootDirectory ?? throw new ArgumentNullException(nameof(rootDirectory)); settings = NuGet.Configuration.Settings.LoadDefaultSettings(rootDirectory); // Add dev source Directory.CreateDirectory(Environment.ExpandEnvironmentVariables(DevSource)); CheckPackageSource("Xenko Dev", DevSource); CheckPackageSource("Xenko", DefaultPackageSource); // Override file does not exist, fallback to default config file var configFileName = configFile; var configFilePath = Path.Combine(rootDirectory, configFileName); if (File.Exists(configFilePath)) { localSettings = NuGet.Configuration.Settings.LoadDefaultSettings(rootDirectory, configFileName, machineWideSettings: null); // Replicate packageSources in user config so that NuGet restore can find them as well foreach (var x in localSettings.GetSettingValues("packageSources", true)) { CheckPackageSource(x.Key, x.Value); } } InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings); var pathContext = NuGetPathContext.Create(settings); InstalledPathResolver = new FallbackPackagePathResolver(pathContext); var packageSourceProvider = new PackageSourceProvider(settings); var availableSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled); var packageSources = new List <PackageSource>(); packageSources.AddRange(availableSources); PackageSources = packageSources; // Setup source provider as a V3 only. sourceRepositoryProvider = new NugetSourceRepositoryProvider(packageSourceProvider, this); manager = new NuGetPackageManager(sourceRepositoryProvider, settings, InstallPath); // Override PackagePathResolver // Workaround for https://github.com/NuGet/Home/issues/6639 manager.PackagesFolderNuGetProject.GetType().GetProperty("PackagePathResolver", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(manager.PackagesFolderNuGetProject, new PackagePathResolverV3(InstallPath)); // Obsolete (Xenko 2.x support) InstallPathV2 = Path.Combine(RootDirectory, DefaultGamePackagesDirectory); managerV2 = new NuGetPackageManager(sourceRepositoryProvider, settings, InstallPathV2); PathResolverV2 = new PackagePathResolver(InstallPathV2); }
public PackageManagementContext( ISourceRepositoryProvider sourceRepositoryProvider, ISolutionManager solutionManager, NuGet.Configuration.ISettings settings, ISourceControlManagerProvider sourceControlManagerProvider, ICommonOperations commonOperations) { SourceRepositoryProvider = sourceRepositoryProvider; VsSolutionManager = solutionManager; Settings = settings; SourceControlManagerProvider = sourceControlManagerProvider; CommonOperations = commonOperations; }
public static bool CheckPackageSource(ISettings settings, string name) { var packageSources = settings.GetSection("packageSources"); if (packageSources != null) { foreach (var packageSource in packageSources.Items.OfType <SourceItem>().ToList()) { if (packageSource.Key == name) { return(true); } } } return(false); }
public NuGetViewModel() { _settings = Settings.LoadDefaultSettings( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), configFileName: null, machineWideSettings: new CommandLineMachineWideSettings()); _sourceProvider = new PackageSourceProvider(_settings); GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(_settings); _packageSources = GetPackageSources(); _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(_sourceProvider); _initializationTask = new Lazy <Task>(Initialize); }
private static void RemoveSources(ISettings settings, string prefixName) { var packageSources = settings.GetSection("packageSources"); if (packageSources != null) { foreach (var packageSource in packageSources.Items.OfType <SourceItem>().ToList()) { var path = packageSource.GetValueAsPath(); if (packageSource.Key.StartsWith(prefixName)) { // Remove entry from packageSources settings.Remove("packageSources", packageSource); } } } }
public NuGetViewModel() { _settings = Settings.LoadDefaultSettings( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), configFileName: null, machineWideSettings: new CommandLineMachineWideSettings()); _sourceProvider = new PackageSourceProvider(_settings); GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(_settings); _packageSources = GetPackageSources(); _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(_sourceProvider); _initializationTask = new Lazy<Task>(Initialize); }
private static void RemoveDeletedSources(ISettings settings, string prefixName) { var packageSources = settings.GetSection("packageSources"); if (packageSources != null) { foreach (var packageSource in packageSources.Items.OfType <SourceItem>().ToList()) { var path = packageSource.GetValueAsPath(); if (packageSource.Key.StartsWith(prefixName) && Uri.TryCreate(path, UriKind.Absolute, out var uri) && uri.IsFile && // make sure it's a valid file URI !Directory.Exists(path)) // detect if directory has been deleted { // Remove entry from packageSources settings.Remove("packageSources", packageSource); } } } }
/// <summary> /// Initialize a new instance of <see cref="NugetStore"/>. /// </summary> /// <param name="oldRootDirectory">The location of the Nuget store.</param> public NugetStore(string oldRootDirectory) { // Workaround for https://github.com/NuGet/Home/issues/8120 // set timeout to something much higher than 100 sec var defaultRequestTimeoutField = typeof(HttpSourceRequest).GetField(nameof(HttpSourceRequest.DefaultRequestTimeout), BindingFlags.Static | BindingFlags.Public); if (defaultRequestTimeoutField != null) { defaultRequestTimeoutField.SetValue(null, TimeSpan.FromMinutes(60)); } // Used only for versions before 3.0 this.oldRootDirectory = oldRootDirectory; settings = NuGet.Configuration.Settings.LoadDefaultSettings(null); // Remove obsolete sources RemoveDeletedSources(settings, "Xenko Dev"); // Note the space: we want to keep "Stride Dev" but not "Stride Dev {PATH}\bin\packages" anymore RemoveSources(settings, "Stride Dev "); // Add Stride package store (still used for Xenko up to 3.0) CheckPackageSource("Stride", DefaultPackageSource); settings.SaveToDisk(); InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings); var pathContext = NuGetPathContext.Create(settings); InstalledPathResolver = new FallbackPackagePathResolver(pathContext.UserPackageFolder, oldRootDirectory != null ? pathContext.FallbackPackageFolders.Concat(new[] { oldRootDirectory }) : pathContext.FallbackPackageFolders); var packageSourceProvider = new PackageSourceProvider(settings); var availableSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled); var packageSources = new List <PackageSource>(); packageSources.AddRange(availableSources); PackageSources = packageSources; // Setup source provider as a V3 only. sourceRepositoryProvider = new NugetSourceRepositoryProvider(packageSourceProvider, this); }
public NuGetViewModel() { try { _settings = Settings.LoadDefaultSettings( root: null, configFileName: null, machineWideSettings: new CommandLineMachineWideSettings()); _sourceProvider = new PackageSourceProvider(_settings); GlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(_settings); _packageSources = GetPackageSources(); _sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(_sourceProvider); } catch (Exception e) { _initializationException = ExceptionDispatchInfo.Capture(e); } }
public static void UpdatePackageSource(ISettings settings, string name, string url) { settings.AddOrUpdate("packageSources", new SourceItem(name, url)); }
public DefaultSettings() { Instance = Settings.LoadDefaultSettings(null, null, null); }