Пример #1
0
 private void InitForBindingRedirects()
 {
     if (!BindingRedirectsRelatedInitialized)
     {
         var solutionManager = ServiceLocator.GetInstanceSafe <ISolutionManager>();
         VSSolutionManager         = (solutionManager != null) ? (solutionManager as VSSolutionManager) : null;
         VSFrameworkMultiTargeting = ServiceLocator.GetGlobalService <SVsFrameworkMultiTargeting, IVsFrameworkMultiTargeting>();
     }
 }
Пример #2
0
        /// <summary>
        /// Removes a new package source.
        /// </summary>
        /// <param name="name">Name of the source.</param>
        public static void RemoveSource(string name)
        {
            var sourceRepositoryProvider = ServiceLocator.GetInstanceSafe <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);
        }
Пример #3
0
        /// <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.GetInstanceSafe <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);
        }
Пример #4
0
        public void AddBindingRedirects()
        {
            var settings = ServiceLocator.GetInstanceSafe <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,
                                                                          EnvDTEProject,
                                                                          VSFrameworkMultiTargeting,
                                                                          NuGetProjectContext);
                        }
                    }
                    catch (Exception ex)
                    {
                        var fileName = EnvDTEProjectUtility.GetFullPath(EnvDTEProject);

                        var level = behavior.FailOperations ?
                                    ProjectManagement.MessageLevel.Error :
                                    ProjectManagement.MessageLevel.Warning;

                        NuGetProjectContext.Log(level,
                                                Strings.FailedToUpdateBindingRedirects,
                                                fileName,
                                                ex.Message);

                        if (behavior.FailOperations)
                        {
                            throw;
                        }
                    }
                });
            }
        }