示例#1
0
        protected override void ExecuteCore()
        {
            var                       lockFileCache = new LockFileCache(BuildEngine4);
            LockFile                  lockFile      = lockFileCache.GetLockFile(AssetsFilePath);
            IEnumerable <string>      excludeFromPublishPackageIds = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences);
            IPackageResolver          packageResolver      = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath);
            HashSet <PackageIdentity> packagestoBeFiltered = null;

            if (TargetManifestFiles != null && TargetManifestFiles.Length > 0)
            {
                packagestoBeFiltered = new HashSet <PackageIdentity>();
                foreach (var manifestFile in TargetManifestFiles)
                {
                    Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.ParsingFiles, manifestFile));
                    var packagesSpecified = StoreArtifactParser.Parse(manifestFile);

                    foreach (var pkg in packagesSpecified)
                    {
                        Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.PackageInfoLog, pkg.Id, pkg.Version));
                    }
                    packagestoBeFiltered.UnionWith(packagesSpecified);
                }
            }

            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFramework),
                RuntimeIdentifier,
                PlatformLibraryName,
                IsSelfContained);

            projectContext.PackagesToBeFiltered = packagestoBeFiltered;

            var assemblyResolver =
                new PublishAssembliesResolver(packageResolver)
                .WithExcludeFromPublish(excludeFromPublishPackageIds)
                .WithPreserveStoreLayout(PreserveStoreLayout);

            IEnumerable <ResolvedFile> resolvedAssemblies = assemblyResolver.Resolve(projectContext);

            foreach (ResolvedFile resolvedAssembly in resolvedAssemblies)
            {
                TaskItem item = new TaskItem(resolvedAssembly.SourcePath);
                item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath);
                item.SetMetadata("AssetType", resolvedAssembly.Asset.ToString().ToLower());
                _assembliesToPublish.Add(item);
            }

            foreach (var resolvedPkg in assemblyResolver.GetResolvedPackages())
            {
                TaskItem item = new TaskItem(resolvedPkg.Id);
                item.SetMetadata("Version", resolvedPkg.Version.ToString());
                _packagesResolved.Add(item);
            }
        }
示例#2
0
        protected override void ExecuteCore()
        {
            var                       lockFileCache = new LockFileCache(this);
            LockFile                  lockFile      = lockFileCache.GetLockFile(AssetsFilePath);
            IEnumerable <string>      excludeFromPublishPackageIds = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences);
            IPackageResolver          packageResolver      = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath);
            HashSet <PackageIdentity> packagestoBeFiltered = null;

            if (RuntimeStorePackages != null && RuntimeStorePackages.Length > 0)
            {
                packagestoBeFiltered = new HashSet <PackageIdentity>();
                foreach (var package in RuntimeStorePackages)
                {
                    packagestoBeFiltered.Add(ItemUtilities.GetPackageIdentity(package));
                }
            }

            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFramework),
                RuntimeIdentifier,
                PlatformLibraryName,
                RuntimeFrameworks,
                IsSelfContained);

            projectContext.PackagesToBeFiltered = packagestoBeFiltered;

            var assemblyResolver =
                new PublishAssembliesResolver(packageResolver)
                .WithExcludeFromPublish(excludeFromPublishPackageIds)
                .WithPreserveStoreLayout(PreserveStoreLayout);

            IEnumerable <ResolvedFile> resolvedAssemblies = assemblyResolver.Resolve(projectContext);

            foreach (ResolvedFile resolvedAssembly in resolvedAssemblies)
            {
                TaskItem item = new TaskItem(resolvedAssembly.SourcePath);
                item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath);
                item.SetMetadata("AssetType", resolvedAssembly.Asset.ToString().ToLower());
                item.SetMetadata(MetadataKeys.PackageName, resolvedAssembly.Package.Id.ToString());
                item.SetMetadata(MetadataKeys.PackageVersion, resolvedAssembly.Package.Version.ToString().ToLower());

                if (resolvedAssembly.Asset == AssetType.Resources)
                {
                    //  For resources, the DestinationSubDirectory is set to the locale.  Set the Culture
                    //  metadata on the generated item to this value so that the satellite assemblies can
                    //  be filtered by culture.
                    item.SetMetadata(MetadataKeys.Culture, resolvedAssembly.DestinationSubDirectory);
                }

                _assembliesToPublish.Add(item);
            }
        }
        protected override void ExecuteCore()
        {
            LockFile             lockFile                = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            NuGetPathContext     nugetPathContext        = NuGetPathContext.Create(Path.GetDirectoryName(ProjectPath));
            IEnumerable <string> privateAssetsPackageIds = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences);

            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFramework),
                RuntimeIdentifier,
                PlatformLibraryName);

            IEnumerable <ResolvedFile> resolvedAssemblies =
                new PublishAssembliesResolver(new NuGetPackageResolver(nugetPathContext))
                .WithPrivateAssets(privateAssetsPackageIds)
                .Resolve(projectContext);

            foreach (ResolvedFile resolvedAssembly in resolvedAssemblies)
            {
                TaskItem item = new TaskItem(resolvedAssembly.SourcePath);
                item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath);

                _assembliesToPublish.Add(item);
            }
        }