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);
            }
        }
示例#2
0
        private void ExecuteCore()
        {
            DependencyContext context;

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

            LockFile 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);

            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);
            }
        }
示例#3
0
文件: Program.cs 项目: schellap/cli
        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);
            }
        }
        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, BaseRuntimeIdentifier);

            var runtimeFiles       = new List <RuntimeFile>();
            var nativeFiles        = new List <RuntimeFile>();
            var resourceAssemblies = new List <ResourceAssembly>();
            var platformManifest   = new List <string>();

            foreach (var library in context.RuntimeLibraries)
            {
                foreach (var file in library.RuntimeAssemblyGroups.SelectMany(g => g.RuntimeFiles))
                {
                    var fileName = Path.GetFileName(file.Path);
                    var path     = $"runtimes/{context.Target.Runtime}/lib/{TargetFramework}/{fileName}";
                    runtimeFiles.Add(
                        new RuntimeFile(
                            path,
                            file.AssemblyVersion,
                            file.FileVersion));

                    platformManifest.Add($"{fileName}|{FrameworkName}|{file.AssemblyVersion}|{file.FileVersion}");
                }

                foreach (var file in library.NativeLibraryGroups.SelectMany(g => g.RuntimeFiles))
                {
                    var fileName = Path.GetFileName(file.Path);
                    var path     = $"runtimes/{context.Target.Runtime}/native/{fileName}";
                    nativeFiles.Add(
                        new RuntimeFile(
                            path,
                            file.AssemblyVersion,
                            file.FileVersion));

                    if (!Version.TryParse(file.FileVersion, out var fileVersion))
                    {
                        fileVersion = new Version(0, 0, 0, 0);
                    }
                    platformManifest.Add($"{fileName}|{FrameworkName}||{fileVersion}");
                }

                resourceAssemblies.AddRange(
                    library.ResourceAssemblies);
            }

            var runtimePackageName = $"runtime.{context.Target.Runtime}.{FrameworkName}";

            var runtimeLibrary = new RuntimeLibrary("package",
                                                    runtimePackageName,
                                                    FrameworkVersion,
                                                    string.Empty,
                                                    new[] { new RuntimeAssetGroup(string.Empty, runtimeFiles) },
                                                    new[] { new RuntimeAssetGroup(string.Empty, nativeFiles) },
                                                    resourceAssemblies,
                                                    Array.Empty <Dependency>(),
                                                    hashPath: null,
                                                    path: $"{runtimePackageName.ToLowerInvariant()}/{FrameworkVersion}",
                                                    serviceable: true);

            var targetingPackLibrary = new RuntimeLibrary("package",
                                                          FrameworkName,
                                                          FrameworkVersion,
                                                          string.Empty,
                                                          Array.Empty <RuntimeAssetGroup>(),
                                                          Array.Empty <RuntimeAssetGroup>(),
                                                          resourceAssemblies,
                                                          new[] { new Dependency(runtimeLibrary.Name, runtimeLibrary.Version) },
                                                          hashPath: null,
                                                          path: $"{FrameworkName.ToLowerInvariant()}/{FrameworkVersion}",
                                                          serviceable: true);

            context = new DependencyContext(
                context.Target,
                CompilationOptions.Default,
                Array.Empty <CompilationLibrary>(),
                new[] { targetingPackLibrary, runtimeLibrary },
                expandedGraph
                );

            Directory.CreateDirectory(Path.GetDirectoryName(PlatformManifestOutputPath));
            Directory.CreateDirectory(Path.GetDirectoryName(DepsFileOutputPath));

            File.WriteAllLines(PlatformManifestOutputPath, platformManifest.OrderBy(n => n));

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