/// <summary> /// Sets a NuGet user settings property. /// </summary> /// <param name="property">The name of the settings property to set.</param> /// <param name="value"> /// The value of the settings property. /// If null, the settings property will be deleted. /// </param> public static void Set(string property, string value) { var settings = ServiceLocator.GetComponentModelService <ISettings>(); var packageRestoreConsent = new PackageRestoreConsent(settings); if (string.Equals(property, "PackageRestoreConsentGranted", StringComparison.OrdinalIgnoreCase)) { packageRestoreConsent.IsGrantedInSettings = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase); } else if (string.Equals(property, "PackageRestoreIsAutomatic", StringComparison.OrdinalIgnoreCase)) { packageRestoreConsent.IsAutomatic = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase); } else { if (value == null) { SettingsUtility.DeleteConfigValue(settings, property); } else { SettingsUtility.SetConfigValue(settings, property, value); } } }
private void InitForBindingRedirects() { if (!_bindingRedirectsRelatedInitialized) { var solutionManager = ServiceLocator.GetComponentModelService <ISolutionManager>(); VSSolutionManager = (solutionManager != null) ? (solutionManager as VSSolutionManager) : null; VSFrameworkMultiTargeting = ServiceLocator.GetGlobalService <SVsFrameworkMultiTargeting, IVsFrameworkMultiTargeting>(); } }
/// <summary> /// Removes a new package source. /// </summary> /// <param name="name">Name of the source.</param> public static void RemoveSource(string name) { var sourceRepositoryProvider = ServiceLocator.GetComponentModelService <ISourceRepositoryProvider>(); if (sourceRepositoryProvider == null) { throw new ArgumentException("sourceRepositoryProvider"); } var packageSourceProvider = sourceRepositoryProvider.PackageSourceProvider; var sources = packageSourceProvider.LoadPackageSources(); sources = sources.Where(s => s.Name != name).ToList(); packageSourceProvider.SavePackageSources(sources); }
/// <summary> /// Adds a new package source. /// </summary> /// <param name="name">Name of the new source.</param> /// <param name="source">Value (uri) of the new source.</param> public static void AddSource(string name, string source) { var sourceRepositoryProvider = ServiceLocator.GetComponentModelService <ISourceRepositoryProvider>(); if (sourceRepositoryProvider == null) { throw new ArgumentException("sourceRepositoryProvider"); } var packageSourceProvider = sourceRepositoryProvider.PackageSourceProvider; var sources = packageSourceProvider.LoadPackageSources().ToList(); sources.Add(new Configuration.PackageSource(source, name)); packageSourceProvider.SavePackageSources(sources); }
public void AddBindingRedirects() { var settings = ServiceLocator.GetComponentModelService <Configuration.ISettings>(); var behavior = new BindingRedirectBehavior(settings); if (!behavior.IsSkipped) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { try { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); InitForBindingRedirects(); if (IsBindingRedirectSupported && VSSolutionManager != null) { await RuntimeHelpers.AddBindingRedirectsAsync(VSSolutionManager, VsProjectAdapter, VSFrameworkMultiTargeting, NuGetProjectContext); } } catch (Exception ex) { var fileName = VsProjectAdapter.UniqueName; var level = behavior.FailOperations ? ProjectManagement.MessageLevel.Error : ProjectManagement.MessageLevel.Warning; NuGetProjectContext.Log(level, Strings.FailedToUpdateBindingRedirects, fileName, ex.Message); if (behavior.FailOperations) { throw; } } }); } }
/// <summary> /// Gets the VsSettings singleton object. /// </summary> /// <returns>The VsSettings object in the system.</returns> public static ISettings GetVsSettings() { return(ServiceLocator.GetComponentModelService <ISettings>()); }