コード例 #1
0
        private void ExecuteCore()
        {
            DependencyContext context;

            using (var depsStream = File.OpenRead(DepsFilePath))
            {
                context = new DependencyContextJsonReader().Read(depsStream);
            }
            LockFile lockFile = LockFileUtilities.GetLockFile(AssetsFilePath, NullLogger.Instance);

            var manager       = new RuntimeGraphManager();
            var graph         = manager.Collect(lockFile);
            var expandedGraph = manager.Expand(graph, Runtime);

            var trimmedRuntimeLibraries = context.RuntimeLibraries;

            if (PackagesToRemove != null && PackagesToRemove.Any())
            {
                trimmedRuntimeLibraries = RuntimeReference.RemoveReferences(context.RuntimeLibraries, PackagesToRemove);
            }

            context = new DependencyContext(
                context.Target,
                context.CompilationOptions,
                context.CompileLibraries,
                trimmedRuntimeLibraries,
                expandedGraph
                );

            using (var depsStream = File.Create(DepsFilePath))
            {
                new DependencyContextWriter().Write(context, depsStream);
            }
        }
コード例 #2
0
        private void ExecuteCore()
        {
            DependencyContext context;

            using (var depsStream = File.OpenRead(DepsFilePath))
            {
                context = new DependencyContextJsonReader().Read(depsStream);
            }

            var lockFile = LockFileUtilities.GetLockFile(AssetsFilePath, NullLogger.Instance);

            if (lockFile == null)
            {
                throw new ArgumentException($"Could not load a LockFile at '{AssetsFilePath}'.", nameof(AssetsFilePath));
            }

            var manager       = new RuntimeGraphManager();
            var graph         = manager.Collect(lockFile);
            var expandedGraph = manager.Expand(graph, Runtime);

            // Remove the runtime entry for the project which generates the original deps.json. For example, there is no Microsoft.AspNetCore.App.dll.
            var trimmedRuntimeLibraries = RuntimeReference.RemoveSharedFxRuntimeEntry(context.RuntimeLibraries, FrameworkName);

            trimmedRuntimeLibraries = ResolveProjectsAsPackages(ResolvedPackageProjectReferences, trimmedRuntimeLibraries);

            if (PackagesToRemove != null && PackagesToRemove.Any())
            {
                trimmedRuntimeLibraries = RuntimeReference.RemoveReferences(trimmedRuntimeLibraries, PackagesToRemove);
            }

            context = new DependencyContext(
                context.Target,
                CompilationOptions.Default,
                Array.Empty <CompilationLibrary>(),
                trimmedRuntimeLibraries,
                expandedGraph
                );

            using (var depsStream = File.Create(OutputPath))
            {
                new DependencyContextWriter().Write(context, depsStream);
            }
        }