public DependencyContextBuilder( SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, ITaskItem[] runtimeFrameworks, string runtimeIdentifier, bool isSelfContained, string platformLibraryName, string targetFramework) { _mainProjectInfo = mainProjectInfo; _includeRuntimeFileVersions = includeRuntimeFileVersions; _isFrameworkDependent = LockFileExtensions.IsFrameworkDependent( runtimeFrameworks, isSelfContained, runtimeIdentifier, string.IsNullOrWhiteSpace(platformLibraryName)); _isPortable = _isFrameworkDependent && string.IsNullOrEmpty(_runtimeIdentifier); if (_isFrameworkDependent != true || _isPortable != true) { throw new ArgumentException( $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without assetfile. " + $"runtimeFrameworks: {string.Join(",", runtimeFrameworks.Select(r => r.ItemSpec))} " + $"isSelfContained: {isSelfContained} " + $"runtimeIdentifier: {runtimeIdentifier} " + $"platformLibraryName: {platformLibraryName}"); } _platformLibrary = platformLibraryName; // NOTE: This uses the TargetFramework (ie "net5.0") as the deps.json runtimeTarget name, instead of // the TargetFrameworkMoniker (ie ".NETCoreApp,Version=v5.0"), which is normally used. // // This constructor should only be used for C++/CLI, and is used because PackageReference isn't // currently supported in that context so there is no assets file to read from. // // Using the TargetFramework instead should have minimal impact. _dotnetFrameworkName = targetFramework; _runtimeIdentifier = runtimeIdentifier; _dependencyLibraries = new Dictionary <string, DependencyLibrary>(); _libraryDependencies = new Dictionary <string, List <LibraryDependency> >(); _mainProjectDependencies = new List <string>(); _packagesToBeFiltered = null; _usedLibraryNames = new HashSet <string>(); }
public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, ProjectContext projectContext, bool includeRuntimeFileVersions) { _mainProjectInfo = mainProjectInfo; _projectContext = projectContext; _includeRuntimeFileVersions = includeRuntimeFileVersions; // This resolver is only used for building file names, so that base path is not required. _versionFolderPathResolver = new VersionFolderPathResolver(rootPath: null); if (_includeRuntimeFileVersions) { // This is used to look up the paths to package files on disk, which is only needed in this class if // it needs to read the file versions _packageResolver = NuGetPackageResolver.CreateResolver(projectContext.LockFile); } }
private CompilationLibrary GetProjectCompilationLibrary( SingleProjectInfo projectInfo, ProjectContext projectContext, Dictionary <string, Dependency> dependencyLookup) { List <Dependency> dependencies = GetProjectDependencies(projectContext, dependencyLookup); return(new CompilationLibrary( type: "project", name: projectInfo.Name, version: projectInfo.Version, hash: string.Empty, assemblies: new[] { projectInfo.OutputName }, dependencies: dependencies.ToArray(), serviceable: false)); }
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); }
protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions); SingleProjectInfo mainProject = SingleProjectInfo.Create( ProjectPath, AssemblyName, AssemblyExtension, AssemblyVersion, AssemblySatelliteAssemblies); IEnumerable <ReferenceInfo> frameworkReferences = ReferenceInfo.CreateFrameworkReferenceInfos(ReferencePaths); IEnumerable <ReferenceInfo> directReferences = ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths); Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos( ReferencePaths, ReferenceSatellitePaths); IEnumerable <string> privateAssets = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName); DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext) .WithFrameworkReferences(frameworkReferences) .WithDirectReferences(directReferences) .WithReferenceProjectInfos(referenceProjects) .WithPrivateAssets(privateAssets) .WithCompilationOptions(compilationOptions) .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath()) .Build(); var writer = new DependencyContextWriter(); using (var fileStream = File.Create(DepsFilePath)) { writer.Write(dependencyContext, fileStream); } _filesWritten.Add(new TaskItem(DepsFilePath)); }
private RuntimeLibrary GetProjectRuntimeLibrary( SingleProjectInfo projectInfo, ProjectContext projectContext, Dictionary <string, Dependency> dependencyLookup) { RuntimeAssetGroup[] runtimeAssemblyGroups = new[] { new RuntimeAssetGroup(string.Empty, projectInfo.OutputName) }; List <Dependency> dependencies = GetProjectDependencies(projectContext, dependencyLookup); return(CreateRuntimeLibrary( type: "project", name: projectInfo.Name, version: projectInfo.Version, hash: string.Empty, runtimeAssemblyGroups: runtimeAssemblyGroups, nativeLibraryGroups: new RuntimeAssetGroup[] { }, resourceAssemblies: CreateResourceAssemblies(projectInfo.ResourceAssemblies), dependencies: dependencies.ToArray(), serviceable: false)); }
public DependencyContextBuilder( SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, ITaskItem[] runtimeFrameworks, string runtimeIdentifier, bool isSelfContained, string platformLibraryName, string targetFramework) { _mainProjectInfo = mainProjectInfo; _includeRuntimeFileVersions = includeRuntimeFileVersions; _isFrameworkDependent = LockFileExtensions.IsFrameworkDependent( runtimeFrameworks, isSelfContained, runtimeIdentifier, string.IsNullOrWhiteSpace(platformLibraryName)); _isPortable = _isFrameworkDependent && string.IsNullOrEmpty(_runtimeIdentifier); if (_isFrameworkDependent != true || _isPortable != true) { throw new ArgumentException( $"{nameof(DependencyContextBuilder)} Does not support non FrameworkDependent without assetfile. " + $"runtimeFrameworks: {string.Join(",", runtimeFrameworks.Select(r => r.ItemSpec))} " + $"isSelfContained: {isSelfContained} " + $"runtimeIdentifier: {runtimeIdentifier} " + $"platformLibraryName: {platformLibraryName}"); } _platformLibrary = platformLibraryName; _dotnetFrameworkName = targetFramework; _runtimeIdentifier = runtimeIdentifier; _dependencyLibraries = new Dictionary <string, DependencyLibrary>(); _libraryDependencies = new Dictionary <string, List <LibraryDependency> >(); _mainProjectDependencies = new List <string>(); _packagesToBeFiltered = null; _usedLibraryNames = new HashSet <string>(); }
public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, ProjectContext projectContext, bool includeRuntimeFileVersions) { _mainProjectInfo = mainProjectInfo; _projectContext = projectContext; _includeRuntimeFileVersions = includeRuntimeFileVersions; // This resolver is only used for building file names, so that base path is not required. _versionFolderPathResolver = new VersionFolderPathResolver(rootPath: null); if (_includeRuntimeFileVersions) { // This is used to look up the paths to package files on disk, which is only needed in this class if // it needs to read the file versions _packageResolver = NuGetPackageResolver.CreateResolver(projectContext.LockFile); } if (_projectContext.CompilationLockFileTarget != _projectContext.LockFileTarget) { _compilationTargetLibraries = _projectContext.CompilationLockFileTarget.Libraries .ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase); } }
private SingleProjectInfo GetProjectInfo(LockFileLibrary library) { string projectPath = library.MSBuildProject; if (string.IsNullOrEmpty(projectPath)) { throw new Exception($"Could not find valid 'MSBuildProject' for project LockFileTargetLibrary '{library.Name}'"); } string mainProjectDirectory = Path.GetDirectoryName(_mainProjectInfo.ProjectPath); string fullProjectPath = Path.GetFullPath(Path.Combine(mainProjectDirectory, projectPath)); SingleProjectInfo referenceProjectInfo = null; if (_referenceProjectInfos?.TryGetValue(fullProjectPath, out referenceProjectInfo) != true || referenceProjectInfo == null) { throw new Exception($"Could not find valid a SingleProjectInfo for project '{fullProjectPath}'"); } return(referenceProjectInfo); }
private SingleProjectInfo GetProjectInfo(LockFileLibrary library) { string projectPath = library.MSBuildProject; if (string.IsNullOrEmpty(projectPath)) { throw new BuildErrorException(Strings.CannotFindProjectInfo, library.Name); } string mainProjectDirectory = Path.GetDirectoryName(_mainProjectInfo.ProjectPath); string fullProjectPath = Path.GetFullPath(Path.Combine(mainProjectDirectory, projectPath)); SingleProjectInfo referenceProjectInfo = null; if (_referenceProjectInfos?.TryGetValue(fullProjectPath, out referenceProjectInfo) != true || referenceProjectInfo == null) { throw new BuildErrorException(Strings.CannotFindProjectInfo, fullProjectPath); } return(referenceProjectInfo); }
protected override void ExecuteCore() { LoadFilesToSkip(); LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions); SingleProjectInfo mainProject = SingleProjectInfo.Create( ProjectPath, AssemblyName, AssemblyExtension, AssemblyVersion, AssemblySatelliteAssemblies); IEnumerable <ReferenceInfo> referenceAssemblyInfos = ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies); IEnumerable <ReferenceInfo> directReferences = ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths); IEnumerable <ReferenceInfo> dependencyReferences = ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths); Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos( ReferencePaths, ReferenceDependencyPaths, ReferenceSatellitePaths); IEnumerable <string> excludeFromPublishAssets = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, IsSelfContained); DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, projectContext, IncludeRuntimeFileVersions) .WithMainProjectInDepsFile(IncludeMainProject) .WithReferenceAssemblies(referenceAssemblyInfos) .WithDirectReferences(directReferences) .WithDependencyReferences(dependencyReferences) .WithReferenceProjectInfos(referenceProjects) .WithExcludeFromPublishAssets(excludeFromPublishAssets) .WithCompilationOptions(compilationOptions) .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath()) .WithPackagesThatWhereFiltered(GetFilteredPackages()) .Build(); if (compileFilesToSkip.Any() || runtimeFilesToSkip.Any()) { dependencyContext = TrimFilesToSkip(dependencyContext); } var writer = new DependencyContextWriter(); using (var fileStream = File.Create(DepsFilePath)) { writer.Write(dependencyContext, fileStream); } _filesWritten.Add(new TaskItem(DepsFilePath)); }
private void WriteDepsFile(string depsFilePath) { ProjectContext projectContext; if (AssetsFilePath == null) { projectContext = null; } else { LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); projectContext = lockFile.CreateProjectContext( TargetFramework, RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); } CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions); SingleProjectInfo mainProject = SingleProjectInfo.Create( ProjectPath, AssemblyName, AssemblyExtension, AssemblyVersion, AssemblySatelliteAssemblies); var userRuntimeAssemblySet = new HashSet <string>(UserRuntimeAssemblies ?? Enumerable.Empty <string>(), StringComparer.OrdinalIgnoreCase); Func <ITaskItem, bool> isUserRuntimeAssembly = item => userRuntimeAssemblySet.Contains(item.ItemSpec); IEnumerable <ReferenceInfo> referenceAssemblyInfos = ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies); // If there is a generated asset file. The projectContext will have project reference. // So remove it from directReferences to avoid duplication var projectContextHasProjectReferences = projectContext != null; IEnumerable <ReferenceInfo> directReferences = ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths, projectContextHasProjectReferences, isUserRuntimeAssembly); IEnumerable <ReferenceInfo> dependencyReferences = ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths, isUserRuntimeAssembly); Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos(ReferencePaths, ReferenceSatellitePaths, isUserRuntimeAssembly); bool ShouldIncludeRuntimeAsset(ITaskItem item) { if (IsSelfContained) { if (!IsSingleFile || !item.GetMetadata(MetadataKeys.DropFromSingleFile).Equals("true")) { return(true); } } else if (item.HasMetadataValue(MetadataKeys.RuntimePackAlwaysCopyLocal, "true")) { return(true); } return(false); } IEnumerable <RuntimePackAssetInfo> runtimePackAssets = RuntimePackAssets.Where(ShouldIncludeRuntimeAsset).Select(RuntimePackAssetInfo.FromItem); DependencyContextBuilder builder; if (projectContext != null) { // Generate the RID-fallback for self-contained builds. // // In order to support loading components with RID-specific assets, // the AssemblyDependencyResolver requires a RID fallback graph. // The component itself should not carry the RID fallback graph with it, because // it would need to carry graph of all the RIDs and needs updates for newer RIDs. // For framework dependent apps, the RID fallback graph comes from the core framework Microsoft.NETCore.App, // so there is no need to write it into the app. // If self-contained apps, the (applicable subset of) RID fallback graph needs to be written to the deps.json manifest. // // If a RID-graph is provided to the DependencyContextBuilder, it generates a RID-fallback // graph with respect to the target RuntimeIdentifier. RuntimeGraph runtimeGraph = IsSelfContained ? new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath) : null; builder = new DependencyContextBuilder(mainProject, IncludeRuntimeFileVersions, runtimeGraph, projectContext); } else { builder = new DependencyContextBuilder( mainProject, IncludeRuntimeFileVersions, RuntimeFrameworks, isSelfContained: IsSelfContained, platformLibraryName: PlatformLibraryName, runtimeIdentifier: RuntimeIdentifier, targetFramework: TargetFramework); } builder = builder .WithMainProjectInDepsFile(IncludeMainProject) .WithReferenceAssemblies(referenceAssemblyInfos) .WithDirectReferences(directReferences) .WithDependencyReferences(dependencyReferences) .WithReferenceProjectInfos(referenceProjects) .WithRuntimePackAssets(runtimePackAssets) .WithCompilationOptions(compilationOptions) .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath()) .WithPackagesThatWereFiltered(GetFilteredPackages()); if (CompileReferences.Length > 0) { builder = builder.WithCompileReferences(ReferenceInfo.CreateReferenceInfos(CompileReferences)); } var resolvedNuGetFiles = ResolvedNuGetFiles.Select(f => new ResolvedFile(f, false)) .Concat(ResolvedRuntimeTargetsFiles.Select(f => new ResolvedFile(f, true))); builder = builder.WithResolvedNuGetFiles(resolvedNuGetFiles); DependencyContext dependencyContext = builder.Build(); var writer = new DependencyContextWriter(); using (var fileStream = File.Create(depsFilePath)) { writer.Write(dependencyContext, fileStream); } _filesWritten.Add(new TaskItem(depsFilePath)); }
private IEnumerable <string> GetCompileTimeAssemblies(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.IsProject() && !(referenceProjectInfo is UnreferencedProjectInfo)) { return(new[] { referenceProjectInfo.OutputName }); } else { return(targetLibrary .CompileTimeAssemblies .FilterPlaceholderFiles() .Select(libraryAsset => libraryAsset.Path)); } }
private IEnumerable <string> GetCompileTimeAssemblies(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.Type == "project") { EnsureProjectInfo(referenceProjectInfo, targetLibrary.Name); return(new[] { referenceProjectInfo.OutputName }); } else { return(targetLibrary .CompileTimeAssemblies .FilterPlaceHolderFiles() .Select(libraryAsset => libraryAsset.Path)); } }
private IReadOnlyList <RuntimeAssetGroup> CreateRuntimeAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.Type == "project") { EnsureProjectInfo(referenceProjectInfo, targetLibrary.Name); return(new[] { new RuntimeAssetGroup(string.Empty, referenceProjectInfo.OutputName) }); } else { List <RuntimeAssetGroup> assemblyGroups = new List <RuntimeAssetGroup>(); assemblyGroups.Add( new RuntimeAssetGroup( string.Empty, targetLibrary.RuntimeAssemblies.FilterPlaceHolderFiles().Select(a => a.Path))); foreach (var runtimeTargetsGroup in targetLibrary.GetRuntimeTargetsGroups("runtime")) { assemblyGroups.Add( new RuntimeAssetGroup( runtimeTargetsGroup.Key, runtimeTargetsGroup.Select(t => t.Path))); } return(assemblyGroups); } }
private void WriteDepsFileNew(string depsFilePath) { LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath); CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions); SingleProjectInfo mainProject = SingleProjectInfo.Create( ProjectPath, AssemblyName, AssemblyExtension, AssemblyVersion, AssemblySatelliteAssemblies); IEnumerable <ReferenceInfo> referenceAssemblyInfos = ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies); IEnumerable <ReferenceInfo> directReferences = ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths, ReferenceSatellitePaths); IEnumerable <ReferenceInfo> dependencyReferences = ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths); Dictionary <string, SingleProjectInfo> referenceProjects = SingleProjectInfo.CreateProjectReferenceInfos( ReferencePaths, ReferenceDependencyPaths, ReferenceSatellitePaths); IEnumerable <string> excludeFromPublishAssets = PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences); IEnumerable <RuntimePackAssetInfo> runtimePackAssets = RuntimePackAssets.Select(item => RuntimePackAssetInfo.FromItem(item)); ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, PlatformLibraryName, RuntimeFrameworks, IsSelfContained); var builder = new DependencyContextBuilder2(mainProject, projectContext, IncludeRuntimeFileVersions); builder = builder .WithMainProjectInDepsFile(IncludeMainProject) .WithReferenceAssemblies(referenceAssemblyInfos) .WithDirectReferences(directReferences) .WithDependencyReferences(dependencyReferences) .WithReferenceProjectInfos(referenceProjects) .WithExcludeFromPublishAssets(excludeFromPublishAssets) .WithRuntimePackAssets(runtimePackAssets) .WithCompilationOptions(compilationOptions) .WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath()) .WithPackagesThatWereFiltered(GetFilteredPackages()); if (CompileReferences.Length > 0) { builder = builder.WithCompileReferences(ReferenceInfo.CreateReferenceInfos(CompileReferences)); } var resolvedNuGetFiles = ResolvedNuGetFiles.Select(f => new ResolvedFile(f, false)) .Concat(ResolvedRuntimeTargetsFiles.Select(f => new ResolvedFile(f, true))); builder = builder.WithResolvedNuGetFiles(resolvedNuGetFiles); DependencyContext dependencyContext = builder.Build(); var writer = new DependencyContextWriter(); using (var fileStream = File.Create(depsFilePath)) { writer.Write(dependencyContext, fileStream); } _filesWritten.Add(new TaskItem(depsFilePath)); }
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 IEnumerable <ResourceAssembly> CreateResourceAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.Type == "project") { EnsureProjectInfo(referenceProjectInfo, targetLibrary.Name); return(CreateResourceAssemblies(referenceProjectInfo.ResourceAssemblies)); } else { return(targetLibrary.ResourceAssemblies.FilterPlaceHolderFiles().Select(CreateResourceAssembly)); } }
private IReadOnlyList <RuntimeAssetGroup> CreateRuntimeAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.IsProject() && !(referenceProjectInfo is UnreferencedProjectInfo)) { return(new[] { new RuntimeAssetGroup(string.Empty, referenceProjectInfo.OutputName) }); } else { List <RuntimeAssetGroup> assemblyGroups = new List <RuntimeAssetGroup>(); assemblyGroups.Add( new RuntimeAssetGroup( string.Empty, targetLibrary.RuntimeAssemblies.FilterPlaceholderFiles().Select(a => CreateRuntimeFile(targetLibrary, a)))); foreach (var runtimeTargetsGroup in targetLibrary.GetRuntimeTargetsGroups("runtime")) { assemblyGroups.Add( new RuntimeAssetGroup( runtimeTargetsGroup.Key, runtimeTargetsGroup.Select(t => CreateRuntimeFile(targetLibrary, t)))); } return(assemblyGroups); } }
private IEnumerable <ResourceAssembly> CreateResourceAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo) { if (targetLibrary.IsProject() && !(referenceProjectInfo is UnreferencedProjectInfo)) { return(CreateResourceAssemblies(referenceProjectInfo.ResourceAssemblies)); } else { return(targetLibrary.ResourceAssemblies.FilterPlaceholderFiles().Select(CreateResourceAssembly)); } }
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)); } }