private LibraryExport ExportProject(ProjectDescription project) { var builder = LibraryExportBuilder.Create(project); var compilerOptions = project.Project.GetCompilerOptions(project.TargetFrameworkInfo.FrameworkName, _configuration); if (!string.IsNullOrEmpty(project.TargetFrameworkInfo?.AssemblyPath)) { // Project specifies a pre-compiled binary. We're done! var assemblyPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.AssemblyPath); var pdbPath = Path.ChangeExtension(assemblyPath, "pdb"); var compileAsset = new LibraryAsset( project.Project.Name, Path.GetFileName(assemblyPath), assemblyPath); builder.AddCompilationAssembly(compileAsset); builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compileAsset })); if (File.Exists(pdbPath)) { builder.AddRuntimeAsset(new LibraryAsset(Path.GetFileName(pdbPath), Path.GetFileName(pdbPath), pdbPath)); } } else if (HasSourceFiles(project, compilerOptions)) { var outputPaths = project.GetOutputPaths(_buildBasePath, _solutionRootPath, _configuration, _runtime); var compilationAssembly = outputPaths.CompilationFiles.Assembly; var compilationAssemblyAsset = LibraryAsset.CreateFromAbsolutePath( outputPaths.CompilationFiles.BasePath, compilationAssembly); builder.AddCompilationAssembly(compilationAssemblyAsset); if (ExportsRuntime(project)) { var runtimeAssemblyAsset = LibraryAsset.CreateFromAbsolutePath( outputPaths.RuntimeFiles.BasePath, outputPaths.RuntimeFiles.Assembly); builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { runtimeAssemblyAsset })); builder.WithRuntimeAssets(CollectAssets(outputPaths.RuntimeFiles)); } else { builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compilationAssemblyAsset })); builder.WithRuntimeAssets(CollectAssets(outputPaths.CompilationFiles)); } builder.WithResourceAssemblies(outputPaths.CompilationFiles.Resources().Select(r => new LibraryResourceAssembly( LibraryAsset.CreateFromAbsolutePath(outputPaths.CompilationFiles.BasePath, r.Path), r.Locale))); } builder.WithSourceReferences(project.Project.Files.SharedFiles.Select(f => LibraryAsset.CreateFromAbsolutePath(project.Path, f) )); return(builder.Build()); }
/// <summary> /// Retrieves a list of <see cref="LibraryExport"/> objects representing the assets /// required from other libraries to compile this project. /// </summary> private IEnumerable <LibraryExport> ExportLibraries(Func <LibraryDescription, bool> condition) { var seenMetadataReferences = new HashSet <string>(); // Iterate over libraries in the library manager foreach (var library in LibraryManager.GetLibraries()) { if (!condition(library)) { continue; } var compilationAssemblies = new List <LibraryAsset>(); var sourceReferences = new List <LibraryAsset>(); var analyzerReferences = new List <AnalyzerReference>(); var libraryExport = GetExport(library); // We need to filter out source references from non-root libraries, // so we rebuild the library export foreach (var reference in libraryExport.CompilationAssemblies) { if (seenMetadataReferences.Add(reference.Name)) { compilationAssemblies.Add(reference); } } // Source and analyzer references are not transitive if (library.Parents.Contains(_rootProject)) { sourceReferences.AddRange(libraryExport.SourceReferences); analyzerReferences.AddRange(libraryExport.AnalyzerReferences); } var builder = LibraryExportBuilder.Create(library); if (_runtime != null && _runtimeFallbacks != null) { // For portable apps that are built with runtime trimming we replace RuntimeAssemblyGroups and NativeLibraryGroups // with single default group that contains asset specific to runtime we are trimming for // based on runtime fallback list builder.WithRuntimeAssemblyGroups(TrimAssetGroups(libraryExport.RuntimeAssemblyGroups, _runtimeFallbacks)); builder.WithNativeLibraryGroups(TrimAssetGroups(libraryExport.NativeLibraryGroups, _runtimeFallbacks)); } else { builder.WithRuntimeAssemblyGroups(libraryExport.RuntimeAssemblyGroups); builder.WithNativeLibraryGroups(libraryExport.NativeLibraryGroups); } yield return(builder .WithCompilationAssemblies(compilationAssemblies) .WithSourceReferences(sourceReferences) .WithRuntimeAssets(libraryExport.RuntimeAssets) .WithEmbedddedResources(libraryExport.EmbeddedResources) .WithAnalyzerReference(analyzerReferences) .WithResourceAssemblies(libraryExport.ResourceAssemblies) .Build()); } }
private LibraryExport ExportPackage(PackageDescription package) { var builder = LibraryExportBuilder.Create(package); builder.WithNativeLibraries(PopulateAssets(package, package.NativeLibraries)); builder.WithRuntimeAssemblies(PopulateAssets(package, package.RuntimeAssemblies)); builder.WithCompilationAssemblies(PopulateAssets(package, package.CompileTimeAssemblies)); builder.WithSourceReferences(GetSharedSources(package)); builder.WithAnalyzerReference(GetAnalyzerReferences(package)); if (package.ContentFiles.Any()) { var parameters = PPFileParameters.CreateForProject(_rootProject.Project); Action <Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters); var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage(); var languageGroups = package.ContentFiles.GroupBy(file => file.CodeLanguage); var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ?? languageGroups.FirstOrDefault(g => g.Key == null); if (selectedGroup != null) { foreach (var contentFile in selectedGroup) { if (contentFile.CodeLanguage != null && string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0) { continue; } var fileTransform = contentFile.PPOutputPath != null ? transform : null; var fullPath = Path.Combine(package.Path, contentFile.Path); if (contentFile.BuildAction == BuildAction.Compile) { builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(package.Path, contentFile.Path, fileTransform)); } else if (contentFile.BuildAction == BuildAction.EmbeddedResource) { builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(package.Path, contentFile.Path, fileTransform)); } if (contentFile.CopyToOutput) { builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform)); } } } } return(builder.Build()); }
private LibraryExport ExportFrameworkLibrary(LibraryDescription library) { // We assume the path is to an assembly. Framework libraries only export compile-time stuff // since they assume the runtime library is present already var builder = LibraryExportBuilder.Create(library); if (!string.IsNullOrEmpty(library.Path)) { builder.WithCompilationAssemblies(new[] { new LibraryAsset(library.Identity.Name, null, library.Path) }); } return(builder.Build()); }
/// <summary> /// Retrieves a list of <see cref="LibraryExport"/> objects representing the assets /// required from other libraries to compile this project. /// </summary> private IEnumerable <LibraryExport> ExportLibraries(Func <LibraryDescription, bool> condition) { var seenMetadataReferences = new HashSet <string>(); // Iterate over libraries in the library manager foreach (var library in LibraryManager.GetLibraries()) { if (!condition(library)) { continue; } var compilationAssemblies = new List <LibraryAsset>(); var sourceReferences = new List <LibraryAsset>(); var analyzerReferences = new List <AnalyzerReference>(); var libraryExport = GetExport(library); // We need to filter out source references from non-root libraries, // so we rebuild the library export foreach (var reference in libraryExport.CompilationAssemblies) { if (seenMetadataReferences.Add(reference.Name)) { compilationAssemblies.Add(reference); } } // Source and analyzer references are not transitive if (library.Parents.Contains(_rootProject)) { sourceReferences.AddRange(libraryExport.SourceReferences); analyzerReferences.AddRange(libraryExport.AnalyzerReferences); } yield return(LibraryExportBuilder.Create(library) .WithCompilationAssemblies(compilationAssemblies) .WithSourceReferences(sourceReferences) .WithRuntimeAssemblies(libraryExport.RuntimeAssemblies) .WithRuntimeAssets(libraryExport.RuntimeAssets) .WithNativeLibraries(libraryExport.NativeLibraries) .WithEmbedddedResources(libraryExport.EmbeddedResources) .WithAnalyzerReference(analyzerReferences) .WithResourceAssemblies(libraryExport.ResourceAssemblies) .WithRuntimeTargets(libraryExport.RuntimeTargets) .Build()); } }
/// <summary> /// Create a LibraryExport from LibraryDescription. /// /// When the library is not resolved the LibraryExport is created nevertheless. /// </summary> private LibraryExport GetExport(LibraryDescription library) { if (!library.Resolved) { // For a unresolved project reference returns a export with empty asset. return(LibraryExportBuilder.Create(library).Build()); } if (Equals(LibraryType.Package, library.Identity.Type)) { return(ExportPackage((PackageDescription)library)); } else if (Equals(LibraryType.Project, library.Identity.Type)) { return(ExportProject((ProjectDescription)library)); } else { return(ExportFrameworkLibrary(library)); } }
private LibraryExport ExportPackage(TargetLibraryWithAssets library) { var builder = LibraryExportBuilder.Create(library); builder.AddNativeLibraryGroup(new LibraryAssetGroup(PopulateAssets(library, library.NativeLibraries))); builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(PopulateAssets(library, library.RuntimeAssemblies))); builder.WithResourceAssemblies(PopulateResources(library, library.ResourceAssemblies)); builder.WithCompilationAssemblies(PopulateAssets(library, library.CompileTimeAssemblies)); if (library.Identity.Type.Equals(LibraryType.Package)) { builder.WithSourceReferences(GetSharedSources((PackageDescription)library)); builder.WithAnalyzerReference(GetAnalyzerReferences((PackageDescription)library)); } if (library.ContentFiles.Any()) { var parameters = PPFileParameters.CreateForProject(_rootProject.Project); Action <Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters); var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage(); var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage); var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ?? languageGroups.FirstOrDefault(g => g.Key == null); if (selectedGroup != null) { foreach (var contentFile in selectedGroup) { if (contentFile.CodeLanguage != null && string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0) { continue; } var fileTransform = contentFile.PPOutputPath != null ? transform : null; var fullPath = Path.Combine(library.Path, contentFile.Path); if (contentFile.BuildAction == BuildAction.Compile) { builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform)); } else if (contentFile.BuildAction == BuildAction.EmbeddedResource) { builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform)); } if (contentFile.CopyToOutput) { builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform)); } } } } if (library.RuntimeTargets.Any()) { foreach (var targetGroup in library.RuntimeTargets.GroupBy(t => t.Runtime)) { var runtime = new List <LibraryAsset>(); var native = new List <LibraryAsset>(); foreach (var lockFileRuntimeTarget in targetGroup) { if (string.Equals(lockFileRuntimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase)) { native.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path)); } else if (string.Equals(lockFileRuntimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase)) { runtime.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path)); } } if (runtime.Any()) { builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(targetGroup.Key, runtime.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath)))); } if (native.Any()) { builder.AddNativeLibraryGroup(new LibraryAssetGroup(targetGroup.Key, native.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath)))); } } } return(builder.Build()); }