public override async Task <bool> UninstallPackageAsync( PackageIdentity packageIdentity, INuGetProjectContext nuGetProjectContext, CancellationToken token) { return(await Runtime.RunInMainThread(() => { PackageReference packageReference = project.FindPackageReference(packageIdentity); if (packageReference != null) { project.PackageReferences.Remove(packageReference); SaveProject(); } return true; })); }
public override async Task <bool> InstallPackageAsync( PackageIdentity packageIdentity, DownloadResourceResult downloadResourceResult, INuGetProjectContext nuGetProjectContext, CancellationToken token) { return(await Runtime.RunInMainThread(async() => { // Check if this NuGet package is already installed and should be removed. PackageReference existingPackageReference = project.FindPackageReference(packageIdentity); if (existingPackageReference != null) { if (ShouldRemoveExistingPackageReference(existingPackageReference, packageIdentity)) { project.PackageReferences.Remove(existingPackageReference); } else { nuGetProjectContext.Log( MessageLevel.Info, GettextCatalog.GetString("Package '{0}' already installed.", packageIdentity)); return true; } } bool developmentDependency = false; if (IsNuGetBuildPackagingPackage(packageIdentity)) { await GlobalPackagesExtractor.Extract(project.ParentSolution, packageIdentity, downloadResourceResult, token); developmentDependency = true; GenerateNuGetBuildPackagingTargets(packageIdentity); } var packageReference = new PackageReference(packageIdentity); if (developmentDependency) { packageReference.PrivateAssets = "All"; } project.PackageReferences.Add(packageReference); await SaveProject(); return true; })); }
bool IsNuGetBuildPackagingReference (PackageReference packageReference) { return StringComparer.OrdinalIgnoreCase.Equals (packageReference.Include, "NuGet.Build.Packaging"); }
bool IsMatch (PackageReference packageReference, PackageIdentity packageIdentity) { return String.Equals (packageReference.Include, packageIdentity.Id, StringComparison.OrdinalIgnoreCase); }
bool IsNuGetBuildPackagingReference(PackageReference packageReference) { return(StringComparer.OrdinalIgnoreCase.Equals(packageReference.Include, "NuGet.Build.Packaging")); }
bool IsMatch(PackageReference packageReference, PackageIdentity packageIdentity) { return(String.Equals(packageReference.Include, packageIdentity.Id, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// If the package version is already installed then there is no need to install the /// NuGet package. /// </summary> bool ShouldRemoveExistingPackageReference(PackageReference packageReference, PackageIdentity packageIdentity) { var existingPackageReference = packageReference.ToNuGetPackageReference(); return(!VersionComparer.Default.Equals(existingPackageReference.PackageIdentity.Version, packageIdentity.Version)); }