private void EmitAssemblyWrapper(string wrapRoot, FrameworkName targetFramework, string assemblyPath, string projectName = null, bool isSubProcedure = false) { if (string.IsNullOrEmpty(projectName)) { projectName = Path.GetFileNameWithoutExtension(assemblyPath); } var targetProjectJson = Path.Combine(wrapRoot, projectName, Runtime.Project.ProjectFileName); var outputIndentation = string.Empty; if (isSubProcedure) { outputIndentation = " "; } Reports.Information.WriteLine("{0}Wrapping project '{1}' for '{2}'", outputIndentation, projectName, targetFramework); Reports.Information.WriteLine("{0} Source {1}", outputIndentation, assemblyPath.Bold()); Reports.Information.WriteLine("{0} Target {1}", outputIndentation, targetProjectJson.Bold()); // Add 'assembly' and 'pdb' to 'bin' section of the target framework var relativeAssemblyPath = PathUtility.GetRelativePath(targetProjectJson, assemblyPath, PathSeparator); var pdbPath = GetSideBySidePdbPath(assemblyPath); string relativePdbPath = null; if (!string.IsNullOrEmpty(pdbPath)) { relativePdbPath = PathUtility.GetRelativePath(targetProjectJson, pdbPath, PathSeparator); } var projectJson = LoadOrCreateProjectJson(targetProjectJson); AddFrameworkBinPaths(projectJson, targetFramework, relativeAssemblyPath, relativePdbPath); // Wrap dependency assemblies that are in the same dir var assemblyInfo = new AssemblyInformation(assemblyPath, processorArchitecture: null); // Key: dependency assembly file name. Value: original dependency name used by dependee. var dependencyOriginalName = assemblyInfo.GetDependencies() .ToDictionary(x => x + ".dll", x => x, StringComparer.OrdinalIgnoreCase); foreach (var filePath in Directory.EnumerateFiles(Path.GetDirectoryName(assemblyPath))) { var fileName = Path.GetFileName(filePath); if (dependencyOriginalName.ContainsKey(fileName)) { // Project dependency name should be case-sensitive, so here we // correct dependency project name by passing in project name with correct case EmitAssemblyWrapper(wrapRoot, targetFramework, filePath, projectName: dependencyOriginalName[fileName], isSubProcedure: isSubProcedure); AddProjectDependency(projectJson, projectName: dependencyOriginalName[fileName], targetFramework: targetFramework); } } PathUtility.EnsureParentDirectory(targetProjectJson); File.WriteAllText(targetProjectJson, projectJson.ToString()); }
private IList <string> WalkAll(string rootPath) { var result = new HashSet <string>(); var stack = new Stack <string>(); stack.Push(rootPath); while (stack.Count > 0) { var path = stack.Pop(); if (!result.Add(Path.GetFileNameWithoutExtension(path))) { continue; } var assemblyInformation = new AssemblyInformation(path, null); foreach (var reference in assemblyInformation.GetDependencies()) { var newPath = Path.Combine(_assemblyFolder, reference + ".dll"); if (!File.Exists(newPath)) { continue; } stack.Push(newPath); } } return(result.ToList()); }
private IEnumerable<string> GetAssemblyDependencies(string assemblyName) { var filepath = ResolveAssemblyFilePath(assemblyName); if (filepath != null && File.Exists(filepath)) { var assemblyInfo = new AssemblyInformation(filepath, processorArchitecture: null); return assemblyInfo.GetDependencies(); } else { return Enumerable.Empty<string>(); } }
private IEnumerable <string> GetAssemblyDependencies(string assemblyName) { var filepath = ResolveAssemblyFilePath(assemblyName); if (filepath != null && File.Exists(filepath)) { var assemblyInfo = new AssemblyInformation(filepath, processorArchitecture: null); return(assemblyInfo.GetDependencies()); } else { return(Enumerable.Empty <string>()); } }
private IEnumerable <string> GetAssemblyDependencies(string assemblyName) { var filepath = ResolveAssemblyFilePath(assemblyName); if (filepath != null && File.Exists(filepath)) { var assemblyInfo = new AssemblyInformation(filepath, processorArchitecture: null); var dependencies = assemblyInfo.GetDependencies(); foreach (var dependency in dependencies) { AddDependencySource(_dependencyAssemblySources, dependency, assemblyName); } return(dependencies); } else { return(Enumerable.Empty <string>()); } }
private void Sort(AssemblyInformation node, List <AssemblyInformation> output, HashSet <AssemblyInformation> seen) { if (!seen.Add(node)) { return; } foreach (var dependency in node.GetDependencies()) { AssemblyInformation dependencyInfo; if (_universe.TryGetValue(dependency, out dependencyInfo)) { Sort(dependencyInfo, output, seen); } } if (!output.Contains(node)) { output.Add(node); } }
private IEnumerable<string> GetAssemblyDependencies(string assemblyName) { var filepath = ResolveAssemblyFilePath(assemblyName); if (filepath != null && File.Exists(filepath)) { var assemblyInfo = new AssemblyInformation(filepath, processorArchitecture: null); var dependencies = assemblyInfo.GetDependencies(); foreach (var dependency in dependencies) { AddDependencySource(_dependencyAssemblySources, dependency, assemblyName); } return dependencies; } else { return Enumerable.Empty<string>(); } }
private void EmitAssemblyWrapper(string wrapRoot, FrameworkName targetFramework, string assemblyPath, string projectName = null, bool isSubProcedure = false) { if (string.IsNullOrEmpty(projectName)) { projectName = Path.GetFileNameWithoutExtension(assemblyPath); } var targetProjectJson = Path.Combine(wrapRoot, projectName, Runtime.Project.ProjectFileName); var outputIndentation = string.Empty; if (isSubProcedure) { outputIndentation = " "; } Reports.Information.WriteLine("{0}Wrapping project '{1}' for '{2}'", outputIndentation, projectName, targetFramework); Reports.Information.WriteLine("{0} Source {1}", outputIndentation, assemblyPath.Bold()); Reports.Information.WriteLine("{0} Target {1}", outputIndentation, targetProjectJson.Bold()); // Add 'assembly' and 'pdb' to 'bin' section of the target framework var relativeAssemblyPath = PathUtility.GetRelativePath(targetProjectJson, assemblyPath, PathSeparator); var pdbPath = GetSideBySidePdbPath(assemblyPath); string relativePdbPath = null; if (!string.IsNullOrEmpty(pdbPath)) { relativePdbPath = PathUtility.GetRelativePath(targetProjectJson, pdbPath, PathSeparator); } var projectJson = LoadOrCreateProjectJson(targetProjectJson); AddFrameworkBinPaths(projectJson, targetFramework, relativeAssemblyPath, relativePdbPath); // Wrap dependency assemblies that are in the same dir var assemblyInfo = new AssemblyInformation(assemblyPath, processorArchitecture: null); // Key: dependency assembly file name. Value: original dependency name used by dependee. var dependencyOriginalName = assemblyInfo.GetDependencies() .ToDictionary(x => x + ".dll", x => x, StringComparer.OrdinalIgnoreCase); foreach (var filePath in Directory.EnumerateFiles(Path.GetDirectoryName(assemblyPath))) { var fileName = Path.GetFileName(filePath); if (dependencyOriginalName.ContainsKey(fileName)) { // Project dependency name should be case-sensitive, so here we // correct dependency project name by passing in project name with correct case EmitAssemblyWrapper(wrapRoot, targetFramework, filePath, projectName: dependencyOriginalName[fileName], isSubProcedure: isSubProcedure); AddProjectDependency(projectJson, projectName: dependencyOriginalName[fileName], targetFramework: targetFramework); } } PathUtility.EnsureParentDirectory(targetProjectJson); File.WriteAllText(targetProjectJson, projectJson.ToString()); }
private void Sort(AssemblyInformation node, List<AssemblyInformation> output, HashSet<AssemblyInformation> seen) { if (!seen.Add(node)) { return; } foreach (var dependency in node.GetDependencies()) { AssemblyInformation dependencyInfo; if (_universe.TryGetValue(dependency, out dependencyInfo)) { Sort(dependencyInfo, output, seen); } } if (!output.Contains(node)) { output.Add(node); } }
private IList<string> WalkAll(string rootPath) { var result = new HashSet<string>(); var stack = new Stack<string>(); stack.Push(rootPath); while (stack.Count > 0) { var path = stack.Pop(); if (!result.Add(Path.GetFileNameWithoutExtension(path))) { continue; } var assemblyInformation = new AssemblyInformation(path, null); foreach (var reference in assemblyInformation.GetDependencies()) { var newPath = Path.Combine(_assemblyFolder, reference + ".dll"); if (!File.Exists(newPath)) { continue; } stack.Push(newPath); } } return result.ToList(); }