示例#1
0
        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);
            }
        }
示例#2
0
 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));
     }
 }
示例#3
0
 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));
     }
 }
示例#4
0
        // A package is a TransitiveProjectReference if it is a project, is not directly referenced,
        // and does not contain a placeholder compile time assembly
        public static bool IsTransitiveProjectReference(this LockFileTargetLibrary library, LockFile lockFile, ref HashSet <string> directProjectDependencies)
        {
            if (!library.IsProject())
            {
                return(false);
            }

            if (directProjectDependencies == null)
            {
                directProjectDependencies = lockFile.GetProjectFileDependencySet();
            }

            return(!directProjectDependencies.Contains(library.Name) &&
                   !library.CompileTimeAssemblies.Any(f => f.IsPlaceholderFile()));
        }
示例#5
0
        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));
            }
        }