public void PublishExcludesBuildDependencies()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("AppWithDirectDependencyAndTypeBuild")
                .WithLockFiles();

            var publishCommand = new PublishCommand(testInstance.TestRoot);
            var publishResult = publishCommand.Execute();
            publishResult.Should().Pass();

            var publishDir = publishCommand.GetOutputDirectory(portable: true);

            publishDir.Should().HaveFiles(new[]
            {
                // This one is directly referenced
                "xunit.core.dll"
            });

            // But these are brought in only by the type:build dependency, and should not be published
            publishDir.Should().NotHaveFiles(new [] {
                "xunit.assert.dll"
            });

            // Check the deps file
            var reader = new DependencyContextJsonReader();
            DependencyContext context;
            using (var file = File.OpenRead(Path.Combine(publishDir.FullName, "AppWithDirectDependencyAndTypeBuild.deps.json")))
            {
                context = reader.Read(file);
            }

            context.RuntimeLibraries.Should().NotContain(l => string.Equals(l.Name, "xunit.assert"));
            context.CompileLibraries.Should().NotContain(l => string.Equals(l.Name, "xunit.assert"));
        }
        public DependencyContext LoadDependencyContextFromFile(string depsJsonFile)
        {
            DependencyContext dependencyContext = null;
            DependencyContextJsonReader contextReader = new DependencyContextJsonReader();

            using (var contextStream = File.OpenRead(depsJsonFile))
            {
                dependencyContext = contextReader.Read(contextStream);
            }

            return dependencyContext;
        }
示例#3
0
        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            string projectDirectory = null;
            string depsFile = null;
            IReadOnlyList<string> runtimes = null;
            try
            {
                ArgumentSyntax.Parse(args, syntax =>
                {
                    syntax.ApplicationName = "Runtime GraphGenerator";

                    syntax.HandleHelp = false;
                    syntax.HandleErrors = false;

                    syntax.DefineOption("p|project", ref projectDirectory, "Project location");
                    syntax.DefineOption("d|deps", ref depsFile, "Deps file path");

                    syntax.DefineParameterList("runtimes", ref runtimes, "Runtimes");
                });
            }
            catch (ArgumentSyntaxException exception)
            {
                Console.Error.WriteLine(exception.Message);
                return 1;
            }

            if (runtimes == null || runtimes.Count == 0)
            {
                Reporter.Error.WriteLine("No runtimes specified");
                return 1;
            }
            if (!File.Exists(depsFile))
            {
                Reporter.Error.WriteLine($"Deps file not found: {depsFile}");
                return 1;
            }
            if (!Directory.Exists(projectDirectory))
            {
                Reporter.Error.WriteLine($"Project directory not found: {projectDirectory}");
                return 1;
            }

            try
            {
                DependencyContext context;
                using (var depsStream = File.OpenRead(depsFile))
                {
                    context = new DependencyContextJsonReader().Read(depsStream);
                }
                var framework = NuGetFramework.Parse(context.Target.Framework);
                var projectContext = ProjectContext.Create(projectDirectory, framework);

                // Configuration is used only for P2P dependencies so were don't care
                var exporter = projectContext.CreateExporter("Debug");
                var manager = new RuntimeGraphManager();
                var graph = manager.Collect(exporter.GetDependencies(LibraryType.Package));
                var expandedGraph = manager.Expand(graph, runtimes);

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

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

                return 0;
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                return 1;
            }
        }