Esempio n. 1
0
        private void AddPackageReferenceToNuGetAwareProject(IPackage package)
        {
            INuGetPackageManager        project = this.Project as INuGetPackageManager;
            Dictionary <string, object> options = new Dictionary <string, object>();

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                IEnumerable <FrameworkName>         packageSupportedFrameworks = package.GetSupportedFrameworks();
                IReadOnlyCollection <FrameworkName> result = project.GetSupportedFrameworksAsync(source.Token).Result;
                options["Frameworks"] = (from projectFramework in result
                                         where VersionUtility.IsCompatible(projectFramework, packageSupportedFrameworks)
                                         select projectFramework).ToArray <FrameworkName>();
                NuGetPackageMoniker moniker1 = new NuGetPackageMoniker();
                moniker1.Id      = package.Id;
                moniker1.Version = package.Version.ToString();
                project.InstallPackageAsync(moniker1, options, null, null, source.Token).Wait();
            }
        }
Esempio n. 2
0
        private void RemovePackageReferenceFromNuGetAwareProject(IPackage package)
        {
            INuGetPackageManager project = this.Project as INuGetPackageManager;
            string fullName = package.GetFullName();

            object[] args = new object[] { fullName, this.Project.ProjectName };
            this.Logger.Log(MessageLevel.Info, NuGetResources.Log_BeginRemovePackageReference, args);
            Dictionary <string, object> options = new Dictionary <string, object>();

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                NuGetPackageMoniker moniker1 = new NuGetPackageMoniker();
                moniker1.Id      = package.Id;
                moniker1.Version = package.Version.ToString();
                project.UninstallPackageAsync(moniker1, options, null, null, source.Token).Wait();
            }
            object[] objArray2 = new object[] { fullName, this.Project.ProjectName };
            this.Logger.Log(MessageLevel.Info, NuGetResources.Log_SuccessfullyRemovedPackageReference, objArray2);
        }