Example #1
0
        public Task <RuntimeFile> GetRuntimes(WalkProviderMatch match, FrameworkName targetFramework)
        {
            foreach (var path in _dependencyProvider.GetAttemptedPaths(targetFramework))
            {
                var runtimeJsonPath = path
                                      .Replace("{name}.nuspec", "runtime.json")
                                      .Replace("project.json", "runtime.json")
                                      .Replace("{name}", match.Library.Name)
                                      .Replace("{version}", match.Library.Version.ToString());

                if (File.Exists(runtimeJsonPath))
                {
                    var formatter = new RuntimeFileFormatter();
                    return(Task.FromResult(formatter.ReadRuntimeFile(runtimeJsonPath)));
                }
            }
            return(Task.FromResult <RuntimeFile>(null));
        }
Example #2
0
 public async Task <RuntimeFile> GetRuntimes(WalkProviderMatch match, FrameworkName targetFramework)
 {
     using (var stream = await _source.OpenRuntimeStreamAsync(new PackageInfo
     {
         Id = match.Library.Name,
         Version = match.Library.Version,
         ContentUri = match.Path
     }))
     {
         if (stream != null)
         {
             var formatter = new RuntimeFileFormatter();
             using (var reader = new StreamReader(stream))
             {
                 return(formatter.ReadRuntimeFile(reader));
             }
         }
     }
     return(null);
 }
Example #3
0
        private async Task <bool> RestoreForProject(string projectJsonPath, string rootDirectory, string packagesDirectory)
        {
            var success = true;

            Reports.Information.WriteLine(string.Format("Restoring packages for {0}", projectJsonPath.Bold()));

            var sw = new Stopwatch();

            sw.Start();

            var projectFolder       = Path.GetDirectoryName(projectJsonPath);
            var projectLockFilePath = Path.Combine(projectFolder, LockFileFormat.LockFileName);

            Runtime.Project project;
            if (!Runtime.Project.TryGetProject(projectJsonPath, out project))
            {
                throw new Exception("TODO: project.json parse error");
            }

            var lockFile = await ReadLockFile(projectLockFilePath);

            var useLockFile = false;

            if (Lock == false &&
                Unlock == false &&
                lockFile != null &&
                lockFile.Islocked)
            {
                useLockFile = true;
            }

            if (useLockFile && !lockFile.IsValidForProject(project))
            {
                // Exhibit the same behavior as if it has been run with "dnu restore --lock"
                Reports.Information.WriteLine("Updating the invalid lock file with {0}",
                                              "dnu restore --lock".Yellow().Bold());
                useLockFile = false;
                Lock        = true;
            }

            Func <string, string> getVariable = key =>
            {
                return(null);
            };

            if (!ScriptExecutor.Execute(project, "prerestore", getVariable))
            {
                ErrorMessages.GetOrAdd("prerestore", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                return(false);
            }

            var projectDirectory  = project.ProjectDirectory;
            var projectResolver   = new ProjectResolver(projectDirectory, rootDirectory);
            var packageRepository = new PackageRepository(packagesDirectory);
            var restoreOperations = new RestoreOperations(Reports.Verbose);
            var projectProviders  = new List <IWalkProvider>();
            var localProviders    = new List <IWalkProvider>();
            var remoteProviders   = new List <IWalkProvider>();
            var contexts          = new List <RestoreContext>();

            projectProviders.Add(
                new LocalWalkProvider(
                    new ProjectReferenceDependencyProvider(
                        projectResolver)));

            localProviders.Add(
                new LocalWalkProvider(
                    new NuGetDependencyResolver(packageRepository)));

            var effectiveSources = PackageSourceUtils.GetEffectivePackageSources(
                SourceProvider,
                FeedOptions.Sources,
                FeedOptions.FallbackSources);

            AddRemoteProvidersFromSources(remoteProviders, effectiveSources);

            var tasks = new List <Task <GraphNode> >();

            if (useLockFile)
            {
                Reports.Information.WriteLine(string.Format("Following lock file {0}", projectLockFilePath.White().Bold()));

                var context = new RestoreContext
                {
                    FrameworkName           = ApplicationEnvironment.RuntimeFramework,
                    ProjectLibraryProviders = projectProviders,
                    LocalLibraryProviders   = localProviders,
                    RemoteLibraryProviders  = remoteProviders,
                };

                contexts.Add(context);

                foreach (var lockFileLibrary in lockFile.Libraries)
                {
                    var projectLibrary = new LibraryRange
                    {
                        Name         = lockFileLibrary.Name,
                        VersionRange = new SemanticVersionRange
                        {
                            MinVersion           = lockFileLibrary.Version,
                            MaxVersion           = lockFileLibrary.Version,
                            IsMaxInclusive       = true,
                            VersionFloatBehavior = SemanticVersionFloatBehavior.None,
                        }
                    };
                    tasks.Add(restoreOperations.CreateGraphNode(context, projectLibrary, _ => false));
                }
            }
            else
            {
                foreach (var configuration in project.GetTargetFrameworks())
                {
                    var context = new RestoreContext
                    {
                        FrameworkName           = configuration.FrameworkName,
                        ProjectLibraryProviders = projectProviders,
                        LocalLibraryProviders   = localProviders,
                        RemoteLibraryProviders  = remoteProviders,
                    };
                    contexts.Add(context);
                }

                if (!contexts.Any())
                {
                    contexts.Add(new RestoreContext
                    {
                        FrameworkName           = ApplicationEnvironment.RuntimeFramework,
                        ProjectLibraryProviders = projectProviders,
                        LocalLibraryProviders   = localProviders,
                        RemoteLibraryProviders  = remoteProviders,
                    });
                }

                foreach (var context in contexts)
                {
                    var projectLibrary = new LibraryRange
                    {
                        Name         = project.Name,
                        VersionRange = new SemanticVersionRange(project.Version)
                    };

                    tasks.Add(restoreOperations.CreateGraphNode(context, projectLibrary, _ => true));
                }
            }

            var graphs = await Task.WhenAll(tasks);

            foreach (var graph in graphs)
            {
                Reduce(graph);
            }

            if (!useLockFile)
            {
                var runtimeFormatter   = new RuntimeFileFormatter();
                var projectRuntimeFile = runtimeFormatter.ReadRuntimeFile(projectJsonPath);
                if (projectRuntimeFile.Runtimes.Any())
                {
                    var runtimeTasks = new List <Task <GraphNode> >();

                    foreach (var pair in contexts.Zip(graphs, (context, graph) => new { context, graph }))
                    {
                        var runtimeFileTasks = new List <Task <RuntimeFile> >();
                        ForEach(pair.graph, node =>
                        {
                            var match = node?.Item?.Match;
                            if (match == null)
                            {
                                return;
                            }
                            runtimeFileTasks.Add(match.Provider.GetRuntimes(node.Item.Match, pair.context.FrameworkName));
                        });

                        var libraryRuntimeFiles = await Task.WhenAll(runtimeFileTasks);

                        var runtimeFiles = new List <RuntimeFile> {
                            projectRuntimeFile
                        };
                        runtimeFiles.AddRange(libraryRuntimeFiles.Where(file => file != null));

                        foreach (var runtimeName in projectRuntimeFile.Runtimes.Keys)
                        {
                            var runtimeSpecs = new List <RuntimeSpec>();
                            FindRuntimeSpecs(
                                runtimeName,
                                runtimeFiles,
                                runtimeSpecs,
                                _ => false);

                            var runtimeContext = new RestoreContext
                            {
                                FrameworkName           = pair.context.FrameworkName,
                                ProjectLibraryProviders = pair.context.ProjectLibraryProviders,
                                LocalLibraryProviders   = pair.context.LocalLibraryProviders,
                                RemoteLibraryProviders  = pair.context.RemoteLibraryProviders,
                                RuntimeName             = runtimeName,
                                RuntimeSpecs            = runtimeSpecs
                            };
                            var projectLibrary = new LibraryRange
                            {
                                Name         = project.Name,
                                VersionRange = new SemanticVersionRange(project.Version)
                            };
                            Reports.Information.WriteLine(string.Format("Graph for {0} on {1}", runtimeContext.FrameworkName, runtimeContext.RuntimeName));
                            runtimeTasks.Add(restoreOperations.CreateGraphNode(runtimeContext, projectLibrary, _ => true));
                        }
                    }

                    var runtimeGraphs = await Task.WhenAll(runtimeTasks);

                    foreach (var runtimeGraph in runtimeGraphs)
                    {
                        Reduce(runtimeGraph);
                    }

                    graphs = graphs.Concat(runtimeGraphs).ToArray();
                }
            }

            var graphItems   = new List <GraphItem>();
            var installItems = new List <GraphItem>();
            var missingItems = new HashSet <LibraryRange>();

            ForEach(graphs, node =>
            {
                if (node == null ||
                    node.LibraryRange == null ||
                    node.Disposition == GraphNode.DispositionType.Rejected)
                {
                    return;
                }

                if (node.Item == null || node.Item.Match == null)
                {
                    if (!node.LibraryRange.IsGacOrFrameworkReference &&
                        node.LibraryRange.VersionRange != null &&
                        missingItems.Add(node.LibraryRange))
                    {
                        var errorMessage = string.Format("Unable to locate {0} {1}",
                                                         node.LibraryRange.Name.Red().Bold(),
                                                         node.LibraryRange.VersionRange);
                        ErrorMessages.GetOrAdd(projectJsonPath, _ => new List <string>()).Add(errorMessage);
                        Reports.Error.WriteLine(errorMessage);
                        success = false;
                    }

                    return;
                }

                if (!string.Equals(node.Item.Match.Library.Name, node.LibraryRange.Name, StringComparison.Ordinal))
                {
                    // Fix casing of the library name to be installed
                    node.Item.Match.Library.Name = node.LibraryRange.Name;
                }

                var isRemote      = remoteProviders.Contains(node.Item.Match.Provider);
                var isInstallItem = installItems.Any(item => item.Match.Library == node.Item.Match.Library);

                if (!isInstallItem && isRemote)
                {
                    installItems.Add(node.Item);
                }

                var isGraphItem = graphItems.Any(item => item.Match.Library == node.Item.Match.Library);
                if (!isGraphItem)
                {
                    graphItems.Add(node.Item);
                }
            });

            await InstallPackages(installItems, packagesDirectory, packageFilter : (library, nupkgSHA) => true);

            if (!useLockFile)
            {
                Reports.Information.WriteLine(string.Format("Writing lock file {0}", projectLockFilePath.White().Bold()));

                // Collect target frameworks
                var frameworks = new HashSet <FrameworkName>();
                foreach (var item in graphItems)
                {
                    Runtime.Project dependencyProject;
                    if (projectProviders.Contains(item.Match.Provider) && projectResolver.TryResolveProject(item.Match.Library.Name, out dependencyProject))
                    {
                        frameworks.AddRange(dependencyProject.GetTargetFrameworks().Select(t => t.FrameworkName));
                    }
                }

                WriteLockFile(projectLockFilePath, project, graphItems, new PackageRepository(packagesDirectory), frameworks);
            }

            if (!ScriptExecutor.Execute(project, "postrestore", getVariable))
            {
                ErrorMessages.GetOrAdd("postrestore", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                return(false);
            }

            if (!ScriptExecutor.Execute(project, "prepare", getVariable))
            {
                ErrorMessages.GetOrAdd("prepare", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                return(false);
            }

            Reports.Information.WriteLine(string.Format("{0}, {1}ms elapsed", "Restore complete".Green().Bold(), sw.ElapsedMilliseconds));

            return(success);
        }
Example #4
0
        private async Task <bool> RestoreForProject(string projectJsonPath, string rootDirectory, string packagesDirectory)
        {
            var success = true;

            Reports.Information.WriteLine(string.Format("Restoring packages for {0}", projectJsonPath.Bold()));

            var sw = new Stopwatch();

            sw.Start();

            var projectFolder       = Path.GetDirectoryName(projectJsonPath);
            var projectLockFilePath = Path.Combine(projectFolder, LockFileFormat.LockFileName);

            Runtime.Project project;
            var             diagnostics = new List <ICompilationMessage>();

            if (!Runtime.Project.TryGetProject(projectJsonPath, out project, diagnostics))
            {
                throw new Exception("TODO: project.json parse error");
            }

            if (diagnostics.HasErrors())
            {
                var errorMessages = diagnostics
                                    .Where(x => x.Severity == CompilationMessageSeverity.Error)
                                    .Select(x => x.Message);
                ErrorMessages.GetOrAdd(projectJsonPath, _ => new List <string>()).AddRange(errorMessages);
            }

            var lockFile = await ReadLockFile(projectLockFilePath);

            var useLockFile = false;

            if (Lock == false &&
                Unlock == false &&
                lockFile != null &&
                lockFile.Islocked)
            {
                useLockFile = true;
            }

            if (useLockFile && !lockFile.IsValidForProject(project))
            {
                // Exhibit the same behavior as if it has been run with "dnu restore --lock"
                Reports.Information.WriteLine("Updating the invalid lock file with {0}",
                                              "dnu restore --lock".Yellow().Bold());
                useLockFile = false;
                Lock        = true;
            }

            Func <string, string> getVariable = key =>
            {
                return(null);
            };

            if (!SkipRestoreEvents)
            {
                if (!ScriptExecutor.Execute(project, "prerestore", getVariable))
                {
                    ErrorMessages.GetOrAdd("prerestore", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                    Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                    return(false);
                }
            }

            var projectDirectory  = project.ProjectDirectory;
            var projectResolver   = new ProjectResolver(projectDirectory, rootDirectory);
            var packageRepository = new PackageRepository(packagesDirectory)
            {
                CheckHashFile = CheckHashFile
            };
            var restoreOperations = new RestoreOperations(Reports.Verbose);
            var projectProviders  = new List <IWalkProvider>();
            var localProviders    = new List <IWalkProvider>();
            var remoteProviders   = new List <IWalkProvider>();
            var contexts          = new List <RestoreContext>();
            var cache             = new Dictionary <LibraryRange, Task <WalkProviderMatch> >();

            projectProviders.Add(
                new LocalWalkProvider(
                    new ProjectReferenceDependencyProvider(
                        projectResolver)));

            localProviders.Add(
                new LocalWalkProvider(
                    new NuGetDependencyResolver(packageRepository)));

            var effectiveSources = PackageSourceUtils.GetEffectivePackageSources(
                Config.Sources,
                FeedOptions.Sources,
                FeedOptions.FallbackSources);

            AddRemoteProvidersFromSources(remoteProviders, effectiveSources);

            var tasks = new List <Task <TargetContext> >();

            if (useLockFile)
            {
                Reports.Information.WriteLine(string.Format("Following lock file {0}", projectLockFilePath.White().Bold()));

                var context = new RestoreContext
                {
                    FrameworkName           = FallbackFramework,
                    ProjectLibraryProviders = projectProviders,
                    LocalLibraryProviders   = localProviders,
                    RemoteLibraryProviders  = remoteProviders,
                    MatchCache = cache
                };

                contexts.Add(context);

                foreach (var lockFileLibrary in lockFile.Libraries)
                {
                    var projectLibrary = new LibraryRange(lockFileLibrary.Name, frameworkReference: false)
                    {
                        VersionRange = new SemanticVersionRange
                        {
                            MinVersion           = lockFileLibrary.Version,
                            MaxVersion           = lockFileLibrary.Version,
                            IsMaxInclusive       = true,
                            VersionFloatBehavior = SemanticVersionFloatBehavior.None,
                        }
                    };

                    tasks.Add(CreateGraphNode(restoreOperations, context, projectLibrary, _ => false));
                }
            }
            else
            {
                var frameworks = TargetFrameworks.Count == 0 ? project.GetTargetFrameworks().Select(f => f.FrameworkName) : TargetFrameworks;

                foreach (var frameworkName in frameworks)
                {
                    var context = new RestoreContext
                    {
                        FrameworkName           = frameworkName,
                        ProjectLibraryProviders = projectProviders,
                        LocalLibraryProviders   = localProviders,
                        RemoteLibraryProviders  = remoteProviders,
                        MatchCache = cache
                    };
                    contexts.Add(context);
                }

                if (!contexts.Any())
                {
                    contexts.Add(new RestoreContext
                    {
                        FrameworkName           = FallbackFramework,
                        ProjectLibraryProviders = projectProviders,
                        LocalLibraryProviders   = localProviders,
                        RemoteLibraryProviders  = remoteProviders,
                        MatchCache = cache
                    });
                }

                foreach (var context in contexts)
                {
                    var projectLibrary = new LibraryRange(project.Name, frameworkReference: false)
                    {
                        VersionRange = new SemanticVersionRange(project.Version)
                    };

                    tasks.Add(CreateGraphNode(restoreOperations, context, projectLibrary, _ => true));
                }
            }

            var targetContexts = await Task.WhenAll(tasks);

            foreach (var targetContext in targetContexts)
            {
                Reduce(targetContext.Root);
            }

            if (!useLockFile)
            {
                var runtimeFormatter   = new RuntimeFileFormatter();
                var projectRuntimeFile = runtimeFormatter.ReadRuntimeFile(projectJsonPath);
                if (projectRuntimeFile.Runtimes.Any())
                {
                    var runtimeTasks = new List <Task <TargetContext> >();

                    foreach (var pair in contexts.Zip(targetContexts, (context, graph) => new { context, graph }))
                    {
                        var runtimeFileTasks = new List <Task <RuntimeFile> >();
                        ForEach(pair.graph.Root, node =>
                        {
                            var match = node?.Item?.Match;
                            if (match == null)
                            {
                                return;
                            }
                            runtimeFileTasks.Add(match.Provider.GetRuntimes(node.Item.Match, pair.context.FrameworkName));
                        });

                        var libraryRuntimeFiles = await Task.WhenAll(runtimeFileTasks);

                        var runtimeFiles = new List <RuntimeFile> {
                            projectRuntimeFile
                        };
                        runtimeFiles.AddRange(libraryRuntimeFiles.Where(file => file != null));

                        foreach (var runtimeName in projectRuntimeFile.Runtimes.Keys)
                        {
                            var runtimeSpecs = new List <RuntimeSpec>();
                            FindRuntimeSpecs(
                                runtimeName,
                                runtimeFiles,
                                runtimeSpecs,
                                _ => false);

                            var runtimeContext = new RestoreContext
                            {
                                FrameworkName           = pair.context.FrameworkName,
                                ProjectLibraryProviders = pair.context.ProjectLibraryProviders,
                                LocalLibraryProviders   = pair.context.LocalLibraryProviders,
                                RemoteLibraryProviders  = pair.context.RemoteLibraryProviders,
                                RuntimeName             = runtimeName,
                                RuntimeSpecs            = runtimeSpecs,
                                MatchCache = cache
                            };
                            var projectLibrary = new LibraryRange(project.Name, frameworkReference: false)
                            {
                                VersionRange = new SemanticVersionRange(project.Version)
                            };
                            Reports.Information.WriteLine(string.Format("Graph for {0} on {1}", runtimeContext.FrameworkName, runtimeContext.RuntimeName));
                            runtimeTasks.Add(CreateGraphNode(restoreOperations, runtimeContext, projectLibrary, _ => true));
                        }
                    }

                    var runtimeTragetContexts = await Task.WhenAll(runtimeTasks);

                    foreach (var runtimeTargetContext in runtimeTragetContexts)
                    {
                        Reduce(runtimeTargetContext.Root);
                    }

                    targetContexts = targetContexts.Concat(runtimeTragetContexts).ToArray();
                }
            }

            var graphItems   = new List <GraphItem>();
            var installItems = new List <GraphItem>();
            var missingItems = new HashSet <LibraryRange>();

            foreach (var context in targetContexts)
            {
                ForEach(context.Root, node =>
                {
                    if (node == null || node.LibraryRange == null)
                    {
                        return;
                    }

                    if (node.Item == null || node.Item.Match == null)
                    {
                        // This is a workaround for #1322. Since we use restore to generate the lock file
                        // after publish, it's possible to fail restore after copying the closure
                        if (!IgnoreMissingDependencies)
                        {
                            if (!node.LibraryRange.IsGacOrFrameworkReference &&
                                node.LibraryRange.VersionRange != null &&
                                missingItems.Add(node.LibraryRange))
                            {
                                var errorMessage = string.Format("Unable to locate {0} {1}",
                                                                 node.LibraryRange.Name.Red().Bold(),
                                                                 node.LibraryRange.VersionRange);
                                ErrorMessages.GetOrAdd(projectJsonPath, _ => new List <string>()).Add(errorMessage);
                                Reports.Error.WriteLine(errorMessage);
                                success = false;
                            }
                        }

                        return;
                    }

                    if (!string.Equals(node.Item.Match.Library.Name, node.LibraryRange.Name, StringComparison.Ordinal))
                    {
                        // Fix casing of the library name to be installed
                        node.Item.Match.Library.Name = node.LibraryRange.Name;
                    }

                    var isRemote      = remoteProviders.Contains(node.Item.Match.Provider);
                    var isInstallItem = installItems.Any(item => item.Match.Library == node.Item.Match.Library);

                    if (!isInstallItem && isRemote)
                    {
                        // It's ok to download rejected nodes so we avoid downloading them in the future
                        // The trade off is that subsequent restores avoid going to any remotes
                        installItems.Add(node.Item);
                    }

                    // Don't add rejected nodes since we only want to write reduced nodes
                    // to the lock file
                    if (node.Disposition != GraphNode.DispositionType.Rejected)
                    {
                        var isGraphItem = graphItems.Any(item => item.Match.Library == node.Item.Match.Library);

                        if (!isGraphItem)
                        {
                            graphItems.Add(node.Item);
                        }

                        context.Libraries.Add(node.Item.Match.Library);
                    }
                });
            }

            if (!SkipInstall)
            {
                await InstallPackages(installItems, packagesDirectory);
            }

            if (!useLockFile)
            {
                Reports.Information.WriteLine(string.Format("Writing lock file {0}", projectLockFilePath.White().Bold()));

                var repository = new PackageRepository(packagesDirectory);

                WriteLockFile(lockFile,
                              projectLockFilePath,
                              project,
                              graphItems,
                              repository,
                              targetContexts);
            }

            if (!SkipRestoreEvents)
            {
                if (!ScriptExecutor.Execute(project, "postrestore", getVariable))
                {
                    ErrorMessages.GetOrAdd("postrestore", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                    Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                    return(false);
                }

                if (!ScriptExecutor.Execute(project, "prepare", getVariable))
                {
                    ErrorMessages.GetOrAdd("prepare", _ => new List <string>()).Add(ScriptExecutor.ErrorMessage);
                    Reports.Error.WriteLine(ScriptExecutor.ErrorMessage);
                    return(false);
                }
            }

            Reports.Information.WriteLine(string.Format("{0}, {1}ms elapsed", "Restore complete".Green().Bold(), sw.ElapsedMilliseconds));

            return(success);
        }
Example #5
0
        public void Main(string[] args)
        {
            var runtimeFileFormatter = new RuntimeFileFormatter();
            var runtimeFile          = runtimeFileFormatter.ReadRuntimeFile("runtime.json");

            foreach (var runtime in runtimeFile.Runtimes.Values)
            {
                Console.WriteLine("{0} Imports: {1}", runtime.Name, string.Join(", ", runtime.Import));
            }
            foreach (var runtime in runtimeFile.Runtimes.Values)
            {
                var sources = new List <string>();
                AddSources(runtimeFile, runtime, sources);

                Console.WriteLine("{0} Effective: {1}", runtime.Name, string.Join(", ", sources));
            }

            var libs = _manager.GetLibraries().ToDictionary(
                x => x.Name,
                x => new Lib {
                LibraryInformation = x
            });

            var comps86 = new Dictionary <string, Comp>();
            var comps64 = new Dictionary <string, Comp>();

            foreach (var lib in libs.Values)
            {
                lib.Dependencies = lib.LibraryInformation.Dependencies
                                   .Select(x => libs[x])
                                   .ToList();
            }

            //if (Directory.Exists("Data\\Build"))
            //{
            //    Directory.Delete("Data\\Build", true);
            //}

            var coreClr = libs["CoreCLR"];

            var clr86Path = Path.Combine(coreClr.LibraryInformation.Path, "Runtime", "x86");
            var clr64Path = Path.Combine(coreClr.LibraryInformation.Path, "Runtime", "amd64");

            var runtimes = new RuntimeCollection();

            foreach (var fn in Directory.GetFiles(clr86Path, "*.dll"))
            {
                var comp = new Comp(fn, coreClr.Version);
                comp.RuntimeName = "win7-x86";
                comp.Parse();
                runtimes.Add(comp);
            }

            foreach (var fn in Directory.GetFiles(clr64Path, "*.dll"))
            {
                var comp = new Comp(fn, coreClr.Version);
                comp.RuntimeName = "win7-amd64";
                comp.Parse();
                runtimes.Add(comp);
            }

            foreach (var entry in runtimes.Entries.Values)
            {
                foreach (var comp in entry.Comps.Values)
                {
                    comp.Lib          = libs.Get(comp.Name);
                    comp.Dependencies = comp.AssemblyReferences
                                        .Select(x => entry.Comps[x])
                                        .Concat(comp.DllImports
                                                .Where(x => entry.Comps.ContainsKey(x))
                                                .Select(x => entry.Comps[x]))
                                        .ToList();
                }
            }

            Directory.CreateDirectory(Path.Combine("Data", "Lib"));
            foreach (var lib in libs.Values.Where(x => x.IsReferenceAssembly))
            {
                File.Copy(
                    lib.FilePath,
                    Path.Combine("Data", "Lib", Path.GetFileName(lib.FilePath)),
                    true);
            }
            foreach (var entry in runtimes.Entries.Values)
            {
                Directory.CreateDirectory(Path.Combine("Data", "Comp", entry.Runtime.Name));
                foreach (var comp in entry.Comps.Values)
                {
                    File.Copy(
                        comp.FilePath,
                        Path.Combine("Data", "Comp", entry.Runtime.Name, Path.GetFileName(comp.FilePath)),
                        true);
                }
            }

            foreach (var lib in libs.Values
                     .Where(x => x.IsReferenceAssembly)
                     .OrderBy(x => x.Name))
            {
                lib.RepackReferencePackage(Path.Combine("Data", "Build"));
            }
            foreach (var entry in runtimes.Entries.Values)
            {
                foreach (var comp in entry.Comps.Values)
                {
                    comp.RepackImplementationPackage(Path.Combine("Data", "Build", entry.Runtime.Name));

                    var runtimeSpec = runtimeFile.Runtimes.Get(entry.Runtime.Name);
                    if (comp.Lib != null)
                    {
                        var dep = runtimeSpec.Dependencies.GetOrAdd(
                            comp.Lib.Name,
                            () => new DependencySpec {
                            Name = comp.Lib.Name
                        });
                        dep.Implementations.GetOrAdd(
                            comp.PackageId,
                            () => new ImplementationSpec {
                            Name = comp.PackageId, Version = comp.Version
                        });
                    }
                    else
                    {
                        var dep = runtimeSpec.Dependencies.GetOrAdd(
                            comp.DependencyId,
                            () => new DependencySpec {
                            Name = comp.DependencyId
                        });
                        dep.Implementations.GetOrAdd(
                            comp.PackageId,
                            () => new ImplementationSpec {
                            Name = comp.PackageId, Version = comp.Version
                        });
                        if (comp.DependencyId.StartsWith("runtime.api.ms.win"))
                        {
                            runtimeFile
                            .Runtimes.Get("win8")
                            .Dependencies.GetOrAdd(
                                comp.DependencyId,
                                () => new DependencySpec {
                                Name = comp.DependencyId
                            });
                        }
                    }
                }
            }

            runtimeFileFormatter.WriteRuntimeFile(
                Path.Combine("Data", "runtime.json"),
                runtimeFile);

            var lineupId      = "Microsoft.Baseline";
            var lineupVersion = "1.0.0-beta1-10000";

            Directory.CreateDirectory(
                Path.Combine("Data", "Build", "Lineup", lineupId, lineupVersion));

            runtimeFileFormatter.WriteRuntimeFile(
                Path.Combine("Data", "Build", "Lineup", lineupId, lineupVersion, "runtime.json"),
                runtimeFile);

            var nuspecTemplate = @"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd"">
  <metadata>
    <id>{0}</id>
    <version>{1}</version>
    <title>{0}</title>
    <authors>Microsoft</authors>
    <owners>Microsoft</owners>
    <licenseUrl>http://go.microsoft.com/fwlink/?LinkId=329770</licenseUrl>
    <iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <description>{0}</description>
    <copyright>Copyright © Microsoft Corporation</copyright>
  </metadata>
</package>
";

            File.WriteAllText(
                Path.Combine("Data", "Build", "Lineup", lineupId, lineupVersion, lineupId + ".nuspec"),
                string.Format(nuspecTemplate, lineupId, lineupVersion));

            return;

            foreach (var lib in libs.Values
                     .Where(x => x.IsReferenceAssembly)
                     .OrderBy(x => x.Name))
            {
                var listed = new List <Lib>();
                Console.WriteLine("${0}", lib.Name);
                Console.WriteLine("  (contracts)");
                Dump(2, lib, libs, listed, _ => false);

                Comp comp = null;
                if (!comps86.TryGetValue(lib.Name, out comp))
                {
                    var path = Path.Combine(lib.LibraryInformation.Path, "lib", "aspnetcore50", lib.Name + ".dll");
                    if (File.Exists(path))
                    {
                        comp = new Comp(path, coreClr.Version);
                        comp.Parse();
                        comps86[comp.Name] = comp;
                        comp.Dependencies  = comp.AssemblyReferences
                                             .Select(x => comps86[x])
                                             .ToList();
                    }
                }
                var listed2 = new List <Comp>();
                Console.WriteLine("  (implementations)");
                if (comp == null)
                {
                    Console.WriteLine("    *** MISSING ***");
                }
                else
                {
                    Dump(2, comp, libs, listed, listed2);
                }
            }

            foreach (var comp in comps86.Values)
            {
                if (libs.ContainsKey(comp.Name))
                {
                    Console.WriteLine("^{0}", comp.Name);
                }
                else
                {
                    Console.WriteLine("^~{0}", comp.Name);
                }

                foreach (var x in comp.TypeForwarding)
                {
                    Console.WriteLine("    {0} <= {1}", x.Key, string.Join(" ", x.Value));
                }
                Console.WriteLine("    ++ {0}", string.Join(" ", comp.TypeDefinitions));
                foreach (var x in comp.TypeReferencing)
                {
                    Console.WriteLine("    {0} => {1}", x.Key, string.Join(" ", x.Value));
                }
            }
        }