Beispiel #1
0
        protected override void ExecuteCore()
        {
            bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath);

            if (!WriteAdditionalProbingPathsToMainConfig)
            {
                if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig)
                {
                    Log.LogWarning(Strings.SkippingAdditionalProbingPaths);
                }
            }

            LockFile       lockFile       = new LockFileCache(this).GetLockFile(AssetsFilePath);
            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker),
                RuntimeIdentifier,
                PlatformLibraryName,
                RuntimeFrameworks,
                IsSelfContained);

            WriteRuntimeConfig(projectContext);

            if (writeDevRuntimeConfig)
            {
                WriteDevRuntimeConfig(projectContext);
            }
        }
        protected override void ExecuteCore()
        {
            LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);

            var nugetFramework = NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker);

            lockFile.GetTargetAndThrowIfNotFound(nugetFramework, RuntimeIdentifier);
        }
Beispiel #3
0
        protected override void ExecuteCore()
        {
            LoadFilesToSkip();

            LockFile           lockFile           = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions);

            SingleProjectInfo mainProject = SingleProjectInfo.Create(
                ProjectPath,
                AssemblyName,
                AssemblyExtension,
                AssemblyVersion,
                AssemblySatelliteAssemblies);

            IEnumerable <ReferenceInfo> frameworkReferences =
                ReferenceInfo.CreateFrameworkReferenceInfos(ReferencePaths);

            IEnumerable <ReferenceInfo> directReferences =
                ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths);

            Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos(
                ReferencePaths,
                ReferenceSatellitePaths);

            IEnumerable <string> excludeFromPublishAssets = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences);

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

            DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext)
                                                  .WithMainProjectInDepsFile(IncludeMainProject)
                                                  .WithFrameworkReferences(frameworkReferences)
                                                  .WithDirectReferences(directReferences)
                                                  .WithReferenceProjectInfos(referenceProjects)
                                                  .WithExcludeFromPublishAssets(excludeFromPublishAssets)
                                                  .WithCompilationOptions(compilationOptions)
                                                  .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
                                                  .WithPackagesThatWhereFiltered(GetFilteredPackages())
                                                  .Build();

            if (compileFilesToSkip.Any() || runtimeFilesToSkip.Any())
            {
                dependencyContext = TrimFilesToSkip(dependencyContext);
            }

            var writer = new DependencyContextWriter();

            using (var fileStream = File.Create(DepsFilePath))
            {
                writer.Write(dependencyContext, fileStream);
            }
            _filesWritten.Add(new TaskItem(DepsFilePath));
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        protected override void ExecuteCore()
        {
            NuGetFramework targetFramework = NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker);
            LockFile       lockFile        = new LockFileCache(this).GetLockFile(ProjectAssetsFile);

            _packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath);

            var embeddedApphostPaths = new List <ITaskItem>();

            foreach (var runtimeIdentifier in ShimRuntimeIdentifiers.Select(r => r.ItemSpec))
            {
                var resolvedApphostAssetPath = GetApphostAsset(targetFramework, lockFile, runtimeIdentifier);

                var packagedShimOutputDirectoryAndRid = Path.Combine(
                    PackagedShimOutputDirectory,
                    runtimeIdentifier);

                var appHostDestinationFilePath = Path.Combine(
                    packagedShimOutputDirectoryAndRid,
                    ToolCommandName + Path.GetExtension(resolvedApphostAssetPath));

                Directory.CreateDirectory(packagedShimOutputDirectoryAndRid);

                // This is the embedded string. We should normalize it on forward slash, so the file won't be different according to
                // build machine.
                var appBinaryFilePath = string.Join("/",
                                                    new[] {
                    ".store",
                    PackageId.ToLowerInvariant(),
                    PackageVersion,
                    PackageId.ToLowerInvariant(),
                    PackageVersion,
                    "tools",
                    targetFramework.GetShortFolderName(),
                    "any",
                    ToolEntryPoint
                });

                AppHost.Create(
                    resolvedApphostAssetPath,
                    appHostDestinationFilePath,
                    appBinaryFilePath,
                    overwriteExisting: true
                    );

                var item = new TaskItem(appHostDestinationFilePath);
                item.SetMetadata("ShimRuntimeIdentifier", runtimeIdentifier);
                embeddedApphostPaths.Add(item);
            }

            EmbeddedApphostPaths = embeddedApphostPaths.ToArray();
        }
Beispiel #6
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()
        {
            var      lockFileCache = new LockFileCache(this);
            LockFile lockFile      = lockFileCache.GetLockFile(AssetsFilePath);
            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 assetsFileResolver =
                new AssetsFileResolver(NuGetPackageResolver.CreateResolver(lockFile))
                .WithExcludedPackages(PackageReferenceConverter.GetPackageIds(ExcludedPackageReferences))
                .WithPreserveStoreLayout(PreserveStoreLayout);

            foreach (var resolvedFile in assetsFileResolver.Resolve(projectContext))
            {
                TaskItem item = new TaskItem(resolvedFile.SourcePath);

                item.SetMetadata(MetadataKeys.DestinationSubPath, resolvedFile.DestinationSubPath);
                item.SetMetadata(MetadataKeys.DestinationSubDirectory, resolvedFile.DestinationSubDirectory);
                item.SetMetadata(MetadataKeys.AssetType, resolvedFile.Asset.ToString().ToLowerInvariant());
                item.SetMetadata(MetadataKeys.PackageName, resolvedFile.Package.Id.ToString());
                item.SetMetadata(MetadataKeys.PackageVersion, resolvedFile.Package.Version.ToString().ToLowerInvariant());

                if (resolvedFile.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, resolvedFile.DestinationSubDirectory.TrimEnd(Path.DirectorySeparatorChar));
                }

                _resolvedAssets.Add(item);
            }
        }
Beispiel #8
0
        protected override void ExecuteCore()
        {
            LockFile       lockFile       = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFramework),
                RuntimeIdentifier,
                PlatformLibraryName);

            WriteRuntimeConfig(projectContext);

            if (!string.IsNullOrEmpty(RuntimeConfigDevPath))
            {
                WriteDevRuntimeConfig(projectContext);
            }
        }
Beispiel #9
0
        protected override void ExecuteCore()
        {
            if (Items.Length == 0 || (PackageFolders.Length == 0 && string.IsNullOrEmpty(AssetsFileWithAdditionalPackageFolders)))
            {
                Output = Items;
                return;
            }

            if (!string.IsNullOrEmpty(AssetsFileWithAdditionalPackageFolders))
            {
                var lockFileCache = new LockFileCache(this);
                var lockFile      = lockFileCache.GetLockFile(AssetsFileWithAdditionalPackageFolders);
                PackageFolders = PackageFolders.Concat(lockFile.PackageFolders.Select(p => p.Path)).ToArray();
            }

            var packageResolver = NuGetPackageResolver.CreateResolver(PackageFolders);

            int index        = 0;
            var updatedItems = new ITaskItem[Items.Length];

            foreach (var item in Items)
            {
                string packageName    = item.GetMetadata(MetadataKeys.NuGetPackageId);
                string packageVersion = item.GetMetadata(MetadataKeys.PackageVersion);

                if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(packageVersion) ||
                    !string.IsNullOrEmpty(item.GetMetadata(MetadataKeys.PackageDirectory)))
                {
                    updatedItems[index++] = item;
                    continue;
                }

                var    parsedPackageVersion = NuGetVersion.Parse(packageVersion);
                string packageDirectory     = packageResolver.GetPackageDirectory(packageName, parsedPackageVersion);

                if (packageDirectory == null)
                {
                    updatedItems[index++] = item;
                    continue;
                }

                var newItem = new TaskItem(item);
                newItem.SetMetadata(MetadataKeys.PackageDirectory, packageDirectory);
                updatedItems[index++] = newItem;
            }

            Output = updatedItems;
        }
Beispiel #10
0
        protected override void ExecuteCore()
        {
            var      lockFileCache = new LockFileCache(this);
            LockFile lockFile      = lockFileCache.GetLockFile(AssetsFilePath);

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

            var packageClosure = new HashSet <PackageIdentity>();

            foreach (var packageItem in PackagesToPrune)
            {
                var pkgName = packageItem.ItemSpec;
                if (!string.IsNullOrEmpty(pkgName))
                {
                    packageClosure.UnionWith(projectContext.GetTransitiveList(pkgName));
                }
            }

            var packagesToPublish = new HashSet <PackageIdentity>();

            foreach (var resolvedFile in ResolvedFiles)
            {
                var resolvedPkg = ItemUtilities.GetPackageIdentity(resolvedFile);

                if (resolvedPkg != null && !packageClosure.Contains(resolvedPkg))
                {
                    _assembliesToPublish.Add(resolvedFile);
                    packagesToPublish.Add(resolvedPkg);
                }
            }
            AssembliesToPublish = _assembliesToPublish.ToArray();

            foreach (var resolvedPkg in packagesToPublish)
            {
                TaskItem item = new TaskItem(resolvedPkg.Id);
                item.SetMetadata("Version", resolvedPkg.Version.ToString());
                _packagesResolved.Add(item);
            }
            PublishedPackages = _packagesResolved.ToArray();
        }
Beispiel #11
0
        protected override void ExecuteCore()
        {
            LockFile           lockFile           = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions);

            SingleProjectInfo mainProject = SingleProjectInfo.Create(
                ProjectPath,
                AssemblyName,
                AssemblyExtension,
                AssemblyVersion,
                AssemblySatelliteAssemblies);

            IEnumerable <ReferenceInfo> frameworkReferences =
                ReferenceInfo.CreateFrameworkReferenceInfos(ReferencePaths);

            Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos(
                ReferencePaths,
                ReferenceSatellitePaths);

            IEnumerable <string> privateAssets = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences);

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

            DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext)
                                                  .WithFrameworkReferences(frameworkReferences)
                                                  .WithReferenceProjectInfos(referenceProjects)
                                                  .WithPrivateAssets(privateAssets)
                                                  .WithCompilationOptions(compilationOptions)
                                                  .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
                                                  .Build();

            var writer = new DependencyContextWriter();

            using (var fileStream = File.Create(DepsFilePath))
            {
                writer.Write(dependencyContext, fileStream);
            }
            _filesWritten.Add(new TaskItem(DepsFilePath));
        }
        protected override void ExecuteCore()
        {
            bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath);

            if (!WriteAdditionalProbingPathsToMainConfig)
            {
                if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig)
                {
                    Log.LogWarning(Strings.SkippingAdditionalProbingPaths);
                }
            }

            if (!string.IsNullOrEmpty(RollForward))
            {
                if (!RollForwardValues.Any(v => string.Equals(RollForward, v, StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogError(Strings.InvalidRollForwardValue, RollForward, string.Join(", ", RollForwardValues));
                    return;
                }
            }

            LockFile       lockFile       = new LockFileCache(this).GetLockFile(AssetsFilePath);
            ProjectContext projectContext = lockFile.CreateProjectContext(
                NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker),
                RuntimeIdentifier,
                PlatformLibraryName,
                RuntimeFrameworks,
                IsSelfContained);

            WriteRuntimeConfig(projectContext);

            if (writeDevRuntimeConfig)
            {
                WriteDevRuntimeConfig(projectContext);
            }
        }
        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);
            }
        }
Beispiel #14
0
 protected override void ExecuteCore()
 {
     var lockFile = new LockFileCache(this).GetLockFile(ProjectAssetsFile);
 }
Beispiel #15
0
        private void WriteDepsFile(string depsFilePath)
        {
            ProjectContext projectContext;

            if (AssetsFilePath == null)
            {
                projectContext = null;
            }
            else
            {
                LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath);
                projectContext = lockFile.CreateProjectContext(
                    TargetFramework,
                    RuntimeIdentifier,
                    PlatformLibraryName,
                    RuntimeFrameworks,
                    IsSelfContained);
            }

            CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions);

            SingleProjectInfo mainProject = SingleProjectInfo.Create(
                ProjectPath,
                AssemblyName,
                AssemblyExtension,
                AssemblyVersion,
                AssemblySatelliteAssemblies);

            var userRuntimeAssemblySet = new HashSet <string>(UserRuntimeAssemblies ?? Enumerable.Empty <string>(), StringComparer.OrdinalIgnoreCase);
            Func <ITaskItem, bool> isUserRuntimeAssembly = item => userRuntimeAssemblySet.Contains(item.ItemSpec);

            IEnumerable <ReferenceInfo> referenceAssemblyInfos =
                ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies);

            // If there is a generated asset file. The projectContext will have project reference.
            // So remove it from directReferences to avoid duplication
            var projectContextHasProjectReferences       = projectContext != null;
            IEnumerable <ReferenceInfo> directReferences =
                ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths,
                                                         ReferenceSatellitePaths,
                                                         projectContextHasProjectReferences, isUserRuntimeAssembly);

            IEnumerable <ReferenceInfo> dependencyReferences =
                ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths, isUserRuntimeAssembly);

            Dictionary <string, SingleProjectInfo> referenceProjects =
                SingleProjectInfo.CreateProjectReferenceInfos(ReferencePaths, ReferenceSatellitePaths,
                                                              isUserRuntimeAssembly);

            bool ShouldIncludeRuntimeAsset(ITaskItem item)
            {
                if (IsSelfContained)
                {
                    if (!IsSingleFile || !item.GetMetadata(MetadataKeys.DropFromSingleFile).Equals("true"))
                    {
                        return(true);
                    }
                }
                else if (item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"))
                {
                    return(true);
                }

                return(false);
            }

            IEnumerable <RuntimePackAssetInfo> runtimePackAssets =
                RuntimePackAssets.Where(ShouldIncludeRuntimeAsset).Select(RuntimePackAssetInfo.FromItem);

            DependencyContextBuilder builder;

            if (projectContext != null)
            {
                // Generate the RID-fallback for self-contained builds.
                //
                // In order to support loading components with RID-specific assets,
                // the AssemblyDependencyResolver requires a RID fallback graph.
                // The component itself should not carry the RID fallback graph with it, because
                // it would need to carry graph of all the RIDs and needs updates for newer RIDs.
                // For framework dependent apps, the RID fallback graph comes from the core framework Microsoft.NETCore.App,
                // so there is no need to write it into the app.
                // If self-contained apps, the (applicable subset of) RID fallback graph needs to be written to the deps.json manifest.
                //
                // If a RID-graph is provided to the DependencyContextBuilder, it generates a RID-fallback
                // graph with respect to the target RuntimeIdentifier.

                RuntimeGraph runtimeGraph =
                    IsSelfContained ? new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath) : null;

                builder = new DependencyContextBuilder(mainProject, IncludeRuntimeFileVersions, runtimeGraph, projectContext);
            }
            else
            {
                builder = new DependencyContextBuilder(
                    mainProject,
                    IncludeRuntimeFileVersions,
                    RuntimeFrameworks,
                    isSelfContained: IsSelfContained,
                    platformLibraryName: PlatformLibraryName,
                    runtimeIdentifier: RuntimeIdentifier,
                    targetFramework: TargetFramework);
            }

            builder = builder
                      .WithMainProjectInDepsFile(IncludeMainProject)
                      .WithReferenceAssemblies(referenceAssemblyInfos)
                      .WithDirectReferences(directReferences)
                      .WithDependencyReferences(dependencyReferences)
                      .WithReferenceProjectInfos(referenceProjects)
                      .WithRuntimePackAssets(runtimePackAssets)
                      .WithCompilationOptions(compilationOptions)
                      .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
                      .WithPackagesThatWereFiltered(GetFilteredPackages());

            if (CompileReferences.Length > 0)
            {
                builder = builder.WithCompileReferences(ReferenceInfo.CreateReferenceInfos(CompileReferences));
            }

            var resolvedNuGetFiles = ResolvedNuGetFiles.Select(f => new ResolvedFile(f, false))
                                     .Concat(ResolvedRuntimeTargetsFiles.Select(f => new ResolvedFile(f, true)));

            builder = builder.WithResolvedNuGetFiles(resolvedNuGetFiles);

            DependencyContext dependencyContext = builder.Build();

            var writer = new DependencyContextWriter();

            using (var fileStream = File.Create(depsFilePath))
            {
                writer.Write(dependencyContext, fileStream);
            }
            _filesWritten.Add(new TaskItem(depsFilePath));
        }
Beispiel #16
0
        protected override void ExecuteCore()
        {
            LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath);

            lockFile.GetTargetAndThrowIfNotFound(TargetFramework, RuntimeIdentifier);
        }
Beispiel #17
0
        protected override void ExecuteCore()
        {
            var lockFile = new LockFileCache(BuildEngine4).GetLockFile(ProjectAssetsFile);

            _packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath);

            var targetFramework   = NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker);
            var compileTimeTarget = lockFile.GetTargetAndThrowIfNotFound(targetFramework, runtime: null);
            var runtimeTarget     = lockFile.GetTargetAndThrowIfNotFound(targetFramework, RuntimeIdentifier);

            CheckRuntimePackageDependencies(compileTimeTarget, runtimeTarget);

            Analyzers = RaiseAnalyzers(
                lockFile,
                runtimeTarget);

            CompileTimeAssemblies = RaisePackageAssets(
                compileTimeTarget,
                package => package.CompileTimeAssemblies,
                setup: (asset, item) =>
            {
                item.SetMetadata(MetadataKeys.Private, "false");
                item.SetMetadata(MetadataKeys.HintPath, item.ItemSpec);

                if (MarkPackageReferencesAsExternallyResolved)
                {
                    item.SetMetadata(MetadataKeys.ExternallyResolved, "true");
                }
            });

            if (!DisableFrameworkAssemblies)
            {
                FrameworkAssemblies = RaiseFrameworkAssemblies(
                    compileTimeTarget,
                    setup: (asset, item) =>
                {
                    item.SetMetadata(MetadataKeys.Pack, "false");
                    item.SetMetadata(MetadataKeys.Private, "false");
                    item.SetMetadata(MetadataKeys.NuGetIsFrameworkReference, "true");
                });
            }

            ContentFilesToPreprocess = RaisePackageAssets(
                runtimeTarget,
                p => p.ContentFiles,
                filter: asset => !string.IsNullOrEmpty(asset.PPOutputPath),
                setup: (asset, item) =>
            {
                item.SetMetadata(MetadataKeys.BuildAction, asset.BuildAction.ToString());
                item.SetMetadata(MetadataKeys.CopyToOutput, asset.CopyToOutput.ToString());
                item.SetMetadata(MetadataKeys.PPOutputPath, asset.PPOutputPath);

                if (!string.IsNullOrEmpty(MetadataKeys.OutputPath))
                {
                    item.SetMetadata(MetadataKeys.OutputPath, asset.OutputPath);
                }

                if (!string.IsNullOrEmpty(asset.CodeLanguage))
                {
                    item.SetMetadata(MetadataKeys.CodeLanguage, asset.CodeLanguage);
                }
            });

            NativeLibraries = RaisePackageAssets(
                runtimeTarget,
                package => package.NativeLibraries);

            ResourceAssemblies = RaisePackageAssets(
                runtimeTarget,
                package => package.ResourceAssemblies,
                setup: (asset, item) =>
            {
                string locale = asset.Properties["locale"];
                item.SetMetadata(MetadataKeys.Culture, locale);
                item.SetMetadata(MetadataKeys.DestinationSubDirectory, locale + Path.DirectorySeparatorChar);
            });

            RuntimeAssemblies = RaisePackageAssets(
                runtimeTarget,
                package => package.RuntimeAssemblies);

            RuntimeTargets = RaisePackageAssets(
                runtimeTarget,
                package => package.RuntimeTargets,
                setup: (asset, item) =>
            {
                string directory = Path.GetDirectoryName(asset.Path);
                item.SetMetadata(MetadataKeys.DestinationSubDirectory, directory + Path.DirectorySeparatorChar);
            });

            if (!DisableTransitiveProjectReferences)
            {
                TransitiveProjectReferences = RaiseTransitiveProjectReferences(lockFile, runtimeTarget);
            }
        }
Beispiel #18
0
        protected override void ExecuteCore()
        {
            bool writeDevRuntimeConfig = !string.IsNullOrEmpty(RuntimeConfigDevPath);

            if (!WriteAdditionalProbingPathsToMainConfig)
            {
                if (AdditionalProbingPaths?.Any() == true && !writeDevRuntimeConfig)
                {
                    Log.LogWarning(Strings.SkippingAdditionalProbingPaths);
                }
            }

            if (!string.IsNullOrEmpty(RollForward))
            {
                if (!RollForwardValues.Any(v => string.Equals(RollForward, v, StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogError(Strings.InvalidRollForwardValue, RollForward, string.Join(", ", RollForwardValues));
                    return;
                }
            }

            if (AssetsFilePath == null)
            {
                var isFrameworkDependent = LockFileExtensions.IsFrameworkDependent(
                    RuntimeFrameworks,
                    IsSelfContained,
                    RuntimeIdentifier,
                    string.IsNullOrWhiteSpace(PlatformLibraryName));

                if (isFrameworkDependent != true)
                {
                    throw new ArgumentException(
                              $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without asset file. " +
                              $"runtimeFrameworks: {string.Join(",", RuntimeFrameworks.Select(r => r.ItemSpec))} " +
                              $"isSelfContained: {IsSelfContained} " +
                              $"runtimeIdentifier: {RuntimeIdentifier} " +
                              $"platformLibraryName: {PlatformLibraryName}");
                }

                if (PlatformLibraryName != null)
                {
                    throw new ArgumentException(
                              "Does not support non null PlatformLibraryName(TFM < 3) without asset file.");
                }

                WriteRuntimeConfig(
                    RuntimeFrameworks.Select(r => new ProjectContext.RuntimeFramework(r)).ToArray(),
                    null,
                    isFrameworkDependent: true, new List <LockFileItem>());
            }
            else
            {
                LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath);

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

                WriteRuntimeConfig(projectContext.RuntimeFrameworks,
                                   projectContext.PlatformLibrary,
                                   projectContext.IsFrameworkDependent,
                                   projectContext.LockFile.PackageFolders);

                if (writeDevRuntimeConfig)
                {
                    WriteDevRuntimeConfig(projectContext.LockFile.PackageFolders);
                }
            }
        }
Beispiel #19
0
        private void WriteDepsFileNew(string depsFilePath)
        {
            LockFile           lockFile           = new LockFileCache(this).GetLockFile(AssetsFilePath);
            CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions);

            SingleProjectInfo mainProject = SingleProjectInfo.Create(
                ProjectPath,
                AssemblyName,
                AssemblyExtension,
                AssemblyVersion,
                AssemblySatelliteAssemblies);

            IEnumerable <ReferenceInfo> referenceAssemblyInfos =
                ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies);

            IEnumerable <ReferenceInfo> directReferences =
                ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths);

            IEnumerable <ReferenceInfo> dependencyReferences =
                ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths);

            Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos(
                ReferencePaths,
                ReferenceDependencyPaths,
                ReferenceSatellitePaths);

            IEnumerable <string> excludeFromPublishAssets = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences);

            IEnumerable <RuntimePackAssetInfo> runtimePackAssets =
                RuntimePackAssets.Select(item => RuntimePackAssetInfo.FromItem(item));


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

            var builder = new DependencyContextBuilder2(mainProject, projectContext, IncludeRuntimeFileVersions);

            builder = builder
                      .WithMainProjectInDepsFile(IncludeMainProject)
                      .WithReferenceAssemblies(referenceAssemblyInfos)
                      .WithDirectReferences(directReferences)
                      .WithDependencyReferences(dependencyReferences)
                      .WithReferenceProjectInfos(referenceProjects)
                      .WithExcludeFromPublishAssets(excludeFromPublishAssets)
                      .WithRuntimePackAssets(runtimePackAssets)
                      .WithCompilationOptions(compilationOptions)
                      .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
                      .WithPackagesThatWereFiltered(GetFilteredPackages());

            if (CompileReferences.Length > 0)
            {
                builder = builder.WithCompileReferences(ReferenceInfo.CreateReferenceInfos(CompileReferences));
            }

            var resolvedNuGetFiles = ResolvedNuGetFiles.Select(f => new ResolvedFile(f, false))
                                     .Concat(ResolvedRuntimeTargetsFiles.Select(f => new ResolvedFile(f, true)));

            builder = builder.WithResolvedNuGetFiles(resolvedNuGetFiles);

            DependencyContext dependencyContext = builder.Build();

            var writer = new DependencyContextWriter();

            using (var fileStream = File.Create(depsFilePath))
            {
                writer.Write(dependencyContext, fileStream);
            }
            _filesWritten.Add(new TaskItem(depsFilePath));
        }