/// <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 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); }
/// <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); // Add dev source RemoveDeletedSources(settings, "Xenko"); CheckPackageSource("Xenko", 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); }