bool AddPackageReference(PackageIdentity packageIdentity, INuGetProjectContext context, BuildIntegratedInstallationContext installationContext) { ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity, matchVersion: false); if (packageReference?.Equals(packageIdentity, matchVersion: true) == true) { context.Log(MessageLevel.Warning, GettextCatalog.GetString("Package '{0}' already exists in project '{1}'", packageIdentity, project.Name)); return(false); } if (packageReference != null) { packageReference.Version = packageIdentity.Version.ToNormalizedString(); } else { packageReference = ProjectPackageReference.Create(packageIdentity); project.Items.Add(packageReference); } if (installationContext.IncludeType != LibraryIncludeFlags.All && installationContext.SuppressParent != LibraryIncludeFlagUtils.DefaultSuppressParent) { packageReference.SetMetadataValue(ProjectItemProperties.IncludeAssets, installationContext.IncludeType); packageReference.SetMetadataValue(ProjectItemProperties.PrivateAssets, installationContext.SuppressParent); } return(true); }
static ProjectPackageReference CreateImportedPackageReference(IMSBuildItemEvaluated item, DotNetProject project) { var packageReference = ProjectPackageReference.Create(item); ModifyImportedPackageReference?.Invoke(packageReference, project); return(packageReference); }
static void ApplyIncludeFlags(LibraryDependency dependency, ProjectPackageReference packageReference) { var includeFlags = GetIncludeFlags(packageReference.Metadata.GetValue("IncludeAssets"), LibraryIncludeFlags.All); var excludeFlags = GetIncludeFlags(packageReference.Metadata.GetValue("ExcludeAssets"), LibraryIncludeFlags.None); dependency.IncludeType = includeFlags & ~excludeFlags; dependency.SuppressParent = GetIncludeFlags(packageReference.Metadata.GetValue("PrivateAssets"), LibraryIncludeFlagUtils.DefaultSuppressParent); }
static void ApplyIncludeFlags(LibraryDependency dependency, ProjectPackageReference packageReference) { MSBuildRestoreUtility.ApplyIncludeFlags( dependency, packageReference.Metadata.GetValue("IncludeAssets"), packageReference.Metadata.GetValue("ExcludeAssets"), packageReference.Metadata.GetValue("PrivateAssets")); }
void RemoveExistingPackageReference(PackageIdentity packageIdentity) { ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity, matchVersion: false); if (packageReference != null) { project.Items.Remove(packageReference); } }
void OnModifyPackageReference(ProjectPackageReference item) { if (!string.IsNullOrEmpty(item.Version)) { return; } ModifyImplicitPackageReferenceVersion?.Invoke(item, DotNetProject); }
internal static ProjectPackageReference Create(string packageId, string version) { var packageReference = new ProjectPackageReference { Include = packageId }; packageReference.Metadata.SetValue("Version", version); return(packageReference); }
static VersionRange GetVersionRange(ProjectPackageReference packageReference) { string versionRange = packageReference.Metadata.GetValue("Version"); if (!string.IsNullOrEmpty(versionRange)) { return(VersionRange.Parse(versionRange)); } return(VersionRange.All); }
bool RemovePackageReference(PackageIdentity packageIdentity, INuGetProjectContext context) { ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity, matchVersion: false); if (packageReference == null) { context.Log(MessageLevel.Warning, GettextCatalog.GetString("Package '{0}' does not exist in project '{1}'", packageIdentity.Id, project.Name)); return(false); } project.Items.Remove(packageReference); return(true); }
bool AddPackageReference(PackageIdentity packageIdentity, INuGetProjectContext context) { ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity); if (packageReference != null) { context.Log(MessageLevel.Warning, GettextCatalog.GetString("Package '{0}' already exists in project '{1}'", packageIdentity, project.Name)); return(false); } RemoveExistingPackageReference(packageIdentity); packageReference = ProjectPackageReference.Create(packageIdentity); project.Items.Add(packageReference); return(true); }
bool AddPackageReference(PackageIdentity packageIdentity, INuGetProjectContext context) { ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity, matchVersion: false); if (packageReference?.Equals(packageIdentity, matchVersion: true) == true) { context.Log(MessageLevel.Warning, GettextCatalog.GetString("Package '{0}' already exists in project '{1}'", packageIdentity, project.Name)); return(false); } if (packageReference != null) { packageReference.Version = packageIdentity.Version.ToNormalizedString(); } else { packageReference = ProjectPackageReference.Create(packageIdentity); project.Items.Add(packageReference); } return(true); }