public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, RuntimeGraph runtimeGraph, ProjectContext projectContext) { _mainProjectInfo = mainProjectInfo; _includeRuntimeFileVersions = includeRuntimeFileVersions; _runtimeGraph = runtimeGraph; var libraryLookup = new LockFileLookup(projectContext.LockFile); _dependencyLibraries = projectContext.LockFileTarget.Libraries .Select(lockFileTargetLibrary => { var dependencyLibrary = new DependencyLibrary(lockFileTargetLibrary.Name, lockFileTargetLibrary.Version, lockFileTargetLibrary.Type); LockFileLibrary library; if (libraryLookup.TryGetLibrary(lockFileTargetLibrary, out library)) { dependencyLibrary.Sha512 = library.Sha512; dependencyLibrary.Path = library.Path; dependencyLibrary.MSBuildProject = library.MSBuildProject; } return(dependencyLibrary); }).ToDictionary(d => d.Name, StringComparer.OrdinalIgnoreCase); _libraryDependencies = new Dictionary <string, List <LibraryDependency> >(StringComparer.OrdinalIgnoreCase); foreach (var library in projectContext.LockFileTarget.Libraries) { _libraryDependencies[library.Name] = library.Dependencies .Select(d => new LibraryDependency() { Name = d.Id, MinVersion = d.VersionRange.MinVersion }).ToList(); } _mainProjectDependencies = projectContext.GetTopLevelDependencies().ToList(); _packagesToBeFiltered = projectContext.PackagesToBeFiltered; _isFrameworkDependent = projectContext.IsFrameworkDependent; _platformLibrary = projectContext.PlatformLibrary?.Name; _dotnetFrameworkName = projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName; _runtimeIdentifier = projectContext.LockFileTarget.RuntimeIdentifier; _isPortable = projectContext.IsPortable; _usedLibraryNames = new HashSet <string>(_dependencyLibraries.Keys, StringComparer.OrdinalIgnoreCase); }
private Library GetLibrary( LockFileTargetLibrary export, LockFileLookup libraryLookup, IDictionary <string, Dependency> dependencyLookup, bool runtime) { var type = export.Type; bool isPackage = type == "package"; // TEMPORARY: All packages are serviceable in RC2 // See https://github.com/dotnet/cli/issues/2569 var serviceable = isPackage; var libraryDependencies = new HashSet <Dependency>(); foreach (PackageDependency libraryDependency in export.Dependencies) { Dependency dependency; if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency)) { libraryDependencies.Add(dependency); } } string hash = string.Empty; string path = null; string hashPath = null; LockFileLibrary library; SingleProjectInfo referenceProjectInfo = null; if (libraryLookup.TryGetLibrary(export, out library)) { if (isPackage) { if (!string.IsNullOrEmpty(library.Sha512)) { hash = "sha512-" + library.Sha512; hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version); } path = library.Path; } else if (type == "project") { referenceProjectInfo = GetProjectInfo(library); } } if (runtime) { return(CreateRuntimeLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, CreateRuntimeAssemblyGroups(export, referenceProjectInfo), CreateNativeLibraryGroups(export), CreateResourceAssemblyGroups(export, referenceProjectInfo), libraryDependencies, serviceable, path, hashPath)); } else { IEnumerable <string> assemblies = GetCompileTimeAssemblies(export, referenceProjectInfo); return(new CompilationLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, assemblies, libraryDependencies, serviceable, path, hashPath)); } }
private Library GetLibrary( LockFileTargetLibrary export, LockFileLookup libraryLookup, IDictionary <string, Dependency> dependencyLookup, bool runtime) { var type = export.Type; bool isPackage = export.IsPackage(); // TEMPORARY: All packages are serviceable in RC2 // See https://github.com/dotnet/cli/issues/2569 var serviceable = isPackage; var libraryDependencies = new HashSet <Dependency>(); foreach (PackageDependency libraryDependency in export.Dependencies) { Dependency dependency; if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency)) { libraryDependencies.Add(dependency); } } string hash = string.Empty; string path = null; string hashPath = null; LockFileLibrary library; SingleProjectInfo referenceProjectInfo = null; if (libraryLookup.TryGetLibrary(export, out library)) { if (isPackage) { if (!string.IsNullOrEmpty(library.Sha512)) { hash = "sha512-" + library.Sha512; hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version); } path = library.Path; } else if (export.IsProject()) { referenceProjectInfo = GetProjectInfo(library); if (referenceProjectInfo is UnreferencedProjectInfo) { // unreferenced ProjectInfos will be added later as simple dll dependencies return(null); } if (runtime) { // DependencyReferences do not get passed to the compilation, so we should only // process them when getting the runtime libraries. foreach (var dependencyReference in referenceProjectInfo.DependencyReferences) { libraryDependencies.Add( new Dependency( GetReferenceLibraryName(dependencyReference), dependencyReference.Version)); } } } } if (runtime) { return(CreateRuntimeLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, CreateRuntimeAssemblyGroups(export, referenceProjectInfo), CreateNativeLibraryGroups(export), CreateResourceAssemblyGroups(export, referenceProjectInfo), libraryDependencies, serviceable, path, hashPath)); } else { IEnumerable <string> assemblies = GetCompileTimeAssemblies(export, referenceProjectInfo); return(new CompilationLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, assemblies, libraryDependencies, serviceable, path, hashPath)); } }
private Library GetLibrary( LockFileTargetLibrary export, LockFileLookup libraryLookup, IDictionary <string, Dependency> dependencyLookup, bool runtime) { var type = export.Type; bool isPackage = export.IsPackage(); // TEMPORARY: All packages are serviceable in RC2 // See https://github.com/dotnet/cli/issues/2569 var serviceable = isPackage; var libraryDependencies = new HashSet <Dependency>(); foreach (PackageDependency libraryDependency in export.Dependencies) { Dependency dependency; if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency)) { libraryDependencies.Add(dependency); } } string hash = string.Empty; string path = null; string hashPath = null; LockFileLibrary library; SingleProjectInfo referenceProjectInfo = null; if (libraryLookup.TryGetLibrary(export, out library)) { if (isPackage) { if (!string.IsNullOrEmpty(library.Sha512)) { hash = "sha512-" + library.Sha512; hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version); } path = library.Path; } else if (export.IsProject()) { referenceProjectInfo = GetProjectInfo(library); if (referenceProjectInfo is UnreferencedProjectInfo) { // unreferenced ProjectInfos will be added later as simple dll dependencies return(null); } if (runtime) { // DependencyReferences do not get passed to the compilation, so we should only // process them when getting the runtime libraries. foreach (var dependencyReference in referenceProjectInfo.DependencyReferences) { libraryDependencies.Add( new Dependency( GetReferenceLibraryName(dependencyReference), dependencyReference.Version)); } } } } if (runtime) { return(CreateRuntimeLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, CreateRuntimeAssemblyGroups(export, referenceProjectInfo), CreateNativeLibraryGroups(export), CreateResourceAssemblyGroups(export, referenceProjectInfo), libraryDependencies, serviceable, path, hashPath)); } else { IEnumerable <string> assemblies = Enumerable.Empty <string>(); // In some situations, the assets file will include compilation assets under the RID-specific // target, but not under the RID-less target. The RID-less target is what is used for project // compilation, so make sure we get those assets when writing the compile references to the assets // file. // This can happen when the runtime graph adds dependencies which don't have compile assets excluded. // This was encountered with the 4.3.0 System.Security.Claims, System.Security.Principal.Windows, and // System.Threading.Overlapped packages. LockFileTargetLibrary exportWithCompileAssets; if (_compilationTargetLibraries != null) { _compilationTargetLibraries.TryGetValue(export.Name, out exportWithCompileAssets); } else { exportWithCompileAssets = export; } if (exportWithCompileAssets != null) { assemblies = GetCompileTimeAssemblies(exportWithCompileAssets, referenceProjectInfo); } return(new CompilationLibrary( type.ToLowerInvariant(), export.Name, export.Version.ToString(), hash, assemblies, libraryDependencies, serviceable, path, hashPath)); } }