Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }