コード例 #1
0
        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);
        }
コード例 #2
0
        static ProjectPackageReference CreateImportedPackageReference(IMSBuildItemEvaluated item, DotNetProject project)
        {
            var packageReference = ProjectPackageReference.Create(item);

            ModifyImportedPackageReference?.Invoke(packageReference, project);
            return(packageReference);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 static void ApplyIncludeFlags(LibraryDependency dependency, ProjectPackageReference packageReference)
 {
     MSBuildRestoreUtility.ApplyIncludeFlags(
         dependency,
         packageReference.Metadata.GetValue("IncludeAssets"),
         packageReference.Metadata.GetValue("ExcludeAssets"),
         packageReference.Metadata.GetValue("PrivateAssets"));
 }
コード例 #5
0
        void RemoveExistingPackageReference(PackageIdentity packageIdentity)
        {
            ProjectPackageReference packageReference = project.GetPackageReference(packageIdentity, matchVersion: false);

            if (packageReference != null)
            {
                project.Items.Remove(packageReference);
            }
        }
コード例 #6
0
        void OnModifyPackageReference(ProjectPackageReference item)
        {
            if (!string.IsNullOrEmpty(item.Version))
            {
                return;
            }

            ModifyImplicitPackageReferenceVersion?.Invoke(item, DotNetProject);
        }
コード例 #7
0
        internal static ProjectPackageReference Create(string packageId, string version)
        {
            var packageReference = new ProjectPackageReference {
                Include = packageId
            };

            packageReference.Metadata.SetValue("Version", version);

            return(packageReference);
        }
コード例 #8
0
        static VersionRange GetVersionRange(ProjectPackageReference packageReference)
        {
            string versionRange = packageReference.Metadata.GetValue("Version");

            if (!string.IsNullOrEmpty(versionRange))
            {
                return(VersionRange.Parse(versionRange));
            }

            return(VersionRange.All);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }