private void ResolveFileReferences(LibraryExport export)
 {
     if (export.Library.Identity.Type != LibraryType.Project)
     {
         _fileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
     }
 }
 private void ResolveSourceFiles(LibraryExport export)
 {
     foreach (var file in export.SourceReferences)
     {
         _sourceFiles.Add(file.ResolvedPath);
     }
 }
Ejemplo n.º 3
0
 private static IEnumerable<string> GenerateLines(LibraryExport export, IEnumerable<LibraryAsset> items, string type)
 {
     return items.Select(i => DepsFormatter.EscapeRow(new[]
     {
         export.Library.Identity.Type.Value,
         export.Library.Identity.Name,
         export.Library.Identity.Version.ToNormalizedString(),
         export.Library.Hash,
         type,
         i.Name,
         i.RelativePath
     }));
 }
Ejemplo n.º 4
0
        private static Library GetLibrary(LibraryExport export,
            NuGetFramework target,
            string configuration,
            IEnumerable<LibraryAsset> libraryAssets,
            IDictionary<string, Dependency> dependencyLookup)
        {
            var type = export.Library.Identity.Type.Value.ToLowerInvariant();

            var serviceable = (export.Library as PackageDescription)?.Library.IsServiceable ?? false;
            var libraryDependencies = new List<Dependency>();

            foreach (var libraryDependency in export.Library.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string[] assemblies;
            if (type == "project")
            {
                var isExe = ((ProjectDescription) export.Library)
                    .Project
                    .GetCompilerOptions(target, configuration)
                    .EmitEntryPoint
                    .GetValueOrDefault(false);

                assemblies = new[] { export.Library.Identity.Name + (isExe ? ".exe": ".dll") };
            }
            else
            {
                assemblies = libraryAssets.Select(libraryAsset => libraryAsset.RelativePath).ToArray();
            }

            return new Library(
                type,
                export.Library.Identity.Name,
                export.Library.Identity.Version.ToString(),
                export.Library.Hash,
                assemblies,
                libraryDependencies.ToArray(),
                serviceable
                );
        }
        private void ResolveProjectReference(LibraryExport export)
        {
            var desc = export.Library as ProjectDescription;
            if (desc == null || export.Library.Identity.Type != LibraryType.Project)
            {
                return;
            }

            if (export.Library.Identity.Name == _context.ProjectFile.Name)
            {
                return;
            }

            if (!string.IsNullOrEmpty(desc?.TargetFrameworkInfo?.AssemblyPath))
            {
                return;
            }

            _sourceFiles.AddRange(export.SourceReferences.Select(source => source.ResolvedPath));
            _projectReferenes.Add(desc);
        }
Ejemplo n.º 6
0
 private static IEnumerable<string> GenerateLines(LibraryExport export, IEnumerable<LibraryAsset> items, string type)
 {
     return items.Select(item =>
         EscapeCsv(export.Library.Identity.Type.Value) + "," +
         EscapeCsv(export.Library.Identity.Name) + "," +
         EscapeCsv(export.Library.Identity.Version.ToNormalizedString()) + "," +
         EscapeCsv(export.Library.Hash) + "," +
         EscapeCsv(type) + "," +
         EscapeCsv(item.Name) + "," +
         EscapeCsv(item.RelativePath) + ",");
 }
Ejemplo n.º 7
0
 private static void CopyExport(string outputPath, LibraryExport export)
 {
     CopyFiles(export.RuntimeAssemblies, outputPath);
     CopyFiles(export.NativeLibraries, outputPath);
 }
Ejemplo n.º 8
0
        private static void PublishRefs(LibraryExport export, string outputPath)
        {
            var refsPath = Path.Combine(outputPath, "refs");
            if (!Directory.Exists(refsPath))
            {
                Directory.CreateDirectory(refsPath);
            }

            // Do not copy compilation assembly if it's in runtime assemblies
            var runtimeAssemblies = new HashSet<LibraryAsset>(export.RuntimeAssemblies);
            foreach (var compilationAssembly in export.CompilationAssemblies)
            {
                if (!runtimeAssemblies.Contains(compilationAssembly))
                {
                    var destFileName = Path.Combine(refsPath, Path.GetFileName(compilationAssembly.ResolvedPath));
                    File.Copy(compilationAssembly.ResolvedPath, destFileName, overwrite: true);
                }
            }
        }
Ejemplo n.º 9
0
 private static IEnumerable<string> GenerateLines(LibraryExport export)
 {
     return GenerateLines(export, export.RuntimeAssemblies, "runtime")
         .Union(GenerateLines(export, export.NativeLibraries, "native"));
 } 
Ejemplo n.º 10
0
        private static Library GetLibrary(LibraryExport export,
            NuGetFramework target,
            string configuration,
            bool runtime,
            IDictionary<string, Dependency> dependencyLookup)
        {
            var type = export.Library.Identity.Type;

            var serviceable = (export.Library as PackageDescription)?.Library.IsServiceable ?? false;
            var libraryDependencies = new List<Dependency>();

            var libraryAssets = runtime ? export.RuntimeAssemblies : export.CompilationAssemblies;

            foreach (var libraryDependenciesGroup in export.Library.Dependencies.GroupBy(d => d.Name))
            {
                LibraryRange libraryDependency = libraryDependenciesGroup
                    .OrderByDescending(d => d.Target == LibraryType.ReferenceAssembly)
                    .First();

                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string[] assemblies;
            if (type == LibraryType.Project)
            {
                var isExe = ((ProjectDescription)export.Library)
                    .Project
                    .GetCompilerOptions(target, configuration)
                    .EmitEntryPoint
                    .GetValueOrDefault(false);

                isExe &= target.IsDesktop();

                assemblies = new[] { export.Library.Identity.Name + (isExe ? ".exe" : ".dll") };
            }
            else if (type == LibraryType.ReferenceAssembly)
            {
                assemblies = ResolveReferenceAssembliesPath(libraryAssets);
            }
            else
            {
                assemblies = libraryAssets.Select(libraryAsset => libraryAsset.RelativePath).ToArray();
            }

            if (runtime)
            {
                return new RuntimeLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    assemblies,
                    libraryDependencies.ToArray(),
                    serviceable
                    );
            }
            else
            {
                return new CompilationLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    assemblies,
                    libraryDependencies.ToArray(),
                    serviceable
                   );
            }
        }
Ejemplo n.º 11
0
        private Library GetLibrary(LibraryExport export,
            bool runtime,
            IDictionary<string, Dependency> dependencyLookup)
        {
            var type = export.Library.Identity.Type;

            var serviceable = (export.Library as PackageDescription)?.PackageLibrary.IsServiceable ?? false;
            var libraryDependencies = new HashSet<Dependency>();

            foreach (var libraryDependency in export.Library.Dependencies)
            {
                // skip build time dependencies
                if (libraryDependency.Type.Equals(LibraryDependencyType.Build))
                {
                    continue;
                }

                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            if (runtime)
            {
                return new RuntimeLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    export.RuntimeAssemblyGroups.Select(CreateRuntimeAssetGroup).ToArray(),
                    export.NativeLibraryGroups.Select(CreateRuntimeAssetGroup).ToArray(),
                    export.ResourceAssemblies.Select(CreateResourceAssembly),
                    libraryDependencies,
                    serviceable
                    );
            }
            else
            {
                IEnumerable<string> assemblies;
                if (type == LibraryType.ReferenceAssembly)
                {
                    assemblies = ResolveReferenceAssembliesPath(export.CompilationAssemblies);
                }
                else
                {
                    assemblies = export.CompilationAssemblies.Select(libraryAsset => libraryAsset.RelativePath);
                }

                return new CompilationLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    assemblies,
                    libraryDependencies,
                    serviceable);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Filters which export's RuntimeAssets should get copied to the output path.
        /// </summary>
        /// <returns>
        /// True if the asset should be copied to the output path; otherwise, false.
        /// </returns>
        private static bool ShouldCopyExportRuntimeAsset(ProjectContext context, OutputPaths buildOutputPaths, LibraryExport export, LibraryAsset asset)
        {
            // The current project has the host .exe in its runtime assets, but it shouldn't be copied
            // to the output path during publish. The host will come from the export that has the real host in it.

            if (context.RootProject.Identity == export.Library.Identity)
            {
                if (asset.ResolvedPath == buildOutputPaths.RuntimeFiles.Executable)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 13
0
        private Library GetLibrary(LibraryExport export,
            bool runtime,
            IDictionary<string, Dependency> dependencyLookup)
        {
            var type = export.Library.Identity.Type;

            var serviceable = (export.Library as PackageDescription)?.Library.IsServiceable ?? false;
            var libraryDependencies = new HashSet<Dependency>();

            var libraryAssets = runtime ? export.RuntimeAssemblies : export.CompilationAssemblies;

            foreach (var libraryDependency in export.Library.Dependencies)
            {
                // skip build time dependencies
                if (!libraryDependency.Type.HasFlag(
                        LibraryDependencyTypeFlag.MainReference |
                        LibraryDependencyTypeFlag.MainExport |
                        LibraryDependencyTypeFlag.RuntimeComponent |
                        LibraryDependencyTypeFlag.BecomesNupkgDependency))
                {
                    continue;
                }

                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            IEnumerable<string> assemblies;
            if (type == LibraryType.ReferenceAssembly)
            {
                assemblies = ResolveReferenceAssembliesPath(libraryAssets);
            }
            else
            {
                assemblies = libraryAssets.Select(libraryAsset => libraryAsset.RelativePath);
            }

            if (runtime)
            {
                return new RuntimeLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    assemblies.Select(RuntimeAssembly.Create),
                    export.ResourceAssemblies.Select(CreateResourceAssembly),
                    export.RuntimeTargets.Select(CreateRuntimeTarget),
                    libraryDependencies,
                    serviceable
                    );
            }
            else
            {
                return new CompilationLibrary(
                    type.ToString().ToLowerInvariant(),
                    export.Library.Identity.Name,
                    export.Library.Identity.Version.ToString(),
                    export.Library.Hash,
                    assemblies,
                    libraryDependencies,
                    serviceable
                   );
            }
        }