Esempio n. 1
0
 private IEnumerable <LibraryAsset> PopulateAssets(PackageDescription package, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section)
     {
         yield return(LibraryAsset.CreateFromRelativePath(package.Path, assemblyPath.Path));
     }
 }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
 private IEnumerable <LibraryAsset> PopulateAssets(TargetLibraryWithAssets library, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path)))
     {
         yield return(LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path));
     }
 }
Esempio n. 4
0
 private IEnumerable <LibraryAsset> PopulateAssets(TargetLibraryWithAssets library, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section)
     {
         yield return(LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path));
     }
 }
Esempio n. 5
0
 private IEnumerable <LibraryAsset> GetSharedSources(PackageDescription package)
 {
     return(package
            .PackageLibrary
            .Files
            .Where(path => path.StartsWith("shared" + Path.DirectorySeparatorChar))
            .Select(path => LibraryAsset.CreateFromRelativePath(package.Path, path)));
 }
        public static AssemblyName GetAssemblyName(this LibraryAsset asset)
        {
            var name = asset.Name;

            if (asset.Name.EndsWith(NativeImageSufix))
            {
                name = name.Substring(0, name.Length - NativeImageSufix.Length);
            }

            return(new AssemblyName(name));
        }
        public void LibraryAsset_CopyTo_Clears_Readonly()
        {
            var libraryAsset = GetMockLibraryAsset(nameof(LibraryAsset_CopyTo_Clears_Readonly));
            MakeFileReadonly(libraryAsset.ResolvedPath);

            IEnumerable<LibraryAsset> assets = new LibraryAsset[] { libraryAsset };

            var outputDirectory = Path.Combine(AppContext.BaseDirectory,$"{nameof(LibraryAsset_CopyTo_Clears_Readonly)}_out");
            assets.CopyTo(outputDirectory);

            var copiedFile = Directory.EnumerateFiles(outputDirectory, Path.GetFileName(libraryAsset.RelativePath)).First();
            IsFileReadonly(copiedFile).Should().BeFalse();
        }
Esempio n. 8
0
        private IEnumerable <LibraryAsset> CollectAssets(CompilationOutputFiles files)
        {
            var assemblyPath = files.Assembly;

            foreach (var path in files.All().Except(files.Resources().Select(r => r.Path)))
            {
                if (string.Equals(assemblyPath, path))
                {
                    continue;
                }
                yield return(LibraryAsset.CreateFromAbsolutePath(files.BasePath, path));
            }
        }
Esempio n. 9
0
 private IEnumerable <LibraryResourceAssembly> PopulateResources(TargetLibraryWithAssets library, IEnumerable <LockFileItem> section)
 {
     foreach (var assemblyPath in section.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path)))
     {
         if (!assemblyPath.Properties.TryGetValue(Constants.LocaleLockFilePropertyName, out var locale))
         {
             locale = null;
         }
         yield return(new LibraryResourceAssembly(
                          LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path),
                          locale));
     }
 }
Esempio n. 10
0
        public static Stream GetTransformedStream(this LibraryAsset asset)
        {
            if (asset.Transform == null)
            {
                return(File.OpenRead(asset.ResolvedPath));
            }

            using (var input = File.OpenRead(asset.ResolvedPath))
            {
                var output = new MemoryStream();
                asset.Transform(input, output);
                return(output);
            }
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        public static string GetTransformedFile(this LibraryAsset asset, string tempLocation, string tempName = null)
        {
            if (asset.Transform == null)
            {
                return(asset.ResolvedPath);
            }

            tempName = tempName ?? Path.GetFileName(asset.RelativePath);
            using (var input = File.OpenRead(asset.ResolvedPath))
            {
                var transformedName = Path.Combine(tempLocation, tempName);
                using (var output = File.OpenWrite(transformedName))
                {
                    asset.Transform(input, output);
                }
                return(transformedName);
            }
        }
Esempio n. 13
0
        private static string ResolveTargetName(string destinationPath, LibraryAsset asset)
        {
            string targetName;
            if (!string.IsNullOrEmpty(asset.RelativePath))
            {
                targetName = Path.Combine(destinationPath, asset.RelativePath);
                var destinationAssetPath = Path.GetDirectoryName(targetName);

                if (!Directory.Exists(destinationAssetPath))
                {
                    Directory.CreateDirectory(destinationAssetPath);
                }
            }
            else
            {
                targetName = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
            }
            return targetName;
        }
Esempio n. 14
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            var compileAssemblies = new List<LibraryAsset>();
            var runtimeAssets = new List<LibraryAsset>();
            var sourceReferences = new List<string>();

            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,
                    null,
                    Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, assemblyPath)));

                compileAssemblies.Add(compileAsset);
                runtimeAssets.Add(new LibraryAsset(Path.GetFileName(pdbPath), Path.GetFileName(pdbPath), pdbPath));
            }
            else if (project.Project.Files.SourceFiles.Any())
            {
                var outputPaths = project.GetOutputPaths(_buildBasePath, _solutionRootPath, _configuration, _runtime);
                var files = outputPaths.CompilationFiles;

                var assemblyPath = files.Assembly;
                compileAssemblies.Add(new LibraryAsset(project.Identity.Name, null, assemblyPath));

                foreach (var path in files.All())
                {
                    if (string.Equals(assemblyPath, path))
                    {
                        continue;
                    }

                    runtimeAssets.Add(new LibraryAsset(Path.GetFileName(path), path.Replace(files.BasePath, string.Empty), path));
                }
            }

            // Add shared sources
            foreach (var sharedFile in project.Project.Files.SharedFiles)
            {
                sourceReferences.Add(sharedFile);
            }

            // No support for ref or native in projects, so runtimeAssemblies is
            // just the same as compileAssemblies and nativeLibraries are empty
            // Also no support for analyzer projects
            return new LibraryExport(project, compileAssemblies, sourceReferences,
                compileAssemblies, runtimeAssets, EmptyArray<LibraryAsset>.Value, EmptyArray<AnalyzerReference>.Value);
        }
Esempio n. 15
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            var compileAssemblies = new List <LibraryAsset>();
            var runtimeAssets     = new List <LibraryAsset>();
            var sourceReferences  = new List <string>();

            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,
                    null,
                    Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, assemblyPath)));

                compileAssemblies.Add(compileAsset);
                runtimeAssets.Add(new LibraryAsset(Path.GetFileName(pdbPath), Path.GetFileName(pdbPath), pdbPath));
            }
            else if (project.Project.Files.SourceFiles.Any())
            {
                var outputPaths = project.GetOutputPaths(_buildBasePath, _solutionRootPath, _configuration, _runtime);
                CompilationOutputFiles files;

                if (project == _rootProject &&
                    !string.IsNullOrWhiteSpace(_runtime) &&
                    project.Project.HasRuntimeOutput(_configuration))
                {
                    files = outputPaths.RuntimeFiles;
                }
                else
                {
                    files = outputPaths.CompilationFiles;
                }

                var assemblyPath = files.Assembly;
                compileAssemblies.Add(new LibraryAsset(project.Identity.Name, null, assemblyPath));

                foreach (var path in files.All())
                {
                    if (string.Equals(assemblyPath, path))
                    {
                        continue;
                    }

                    runtimeAssets.Add(new LibraryAsset(Path.GetFileName(path), path.Replace(files.BasePath, string.Empty), path));
                }
            }

            // Add shared sources
            foreach (var sharedFile in project.Project.Files.SharedFiles)
            {
                sourceReferences.Add(sharedFile);
            }

            // No support for ref or native in projects, so runtimeAssemblies is
            // just the same as compileAssemblies and nativeLibraries are empty
            // Also no support for analyzer projects
            return(new LibraryExport(project, compileAssemblies, sourceReferences,
                                     compileAssemblies, runtimeAssets, EmptyArray <LibraryAsset> .Value, EmptyArray <AnalyzerReference> .Value));
        }
Esempio n. 16
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            var compileAssemblies = new List<LibraryAsset>();
            var runtimeAssets = new List<string>();
            var sourceReferences = new List<string>();

            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,
                    null,
                    Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, assemblyPath)));

                compileAssemblies.Add(compileAsset);
                runtimeAssets.Add(pdbPath);
            }
            else
            {
                var outputCalculator = project.GetOutputPathCalculator();
                var assemblyPath = outputCalculator.GetAssemblyPath(_configuration);
                compileAssemblies.Add(new LibraryAsset(project.Identity.Name, null, assemblyPath));

                foreach (var path in outputCalculator.GetBuildOutputs(_configuration))
                {
                    if (string.Equals(assemblyPath, path))
                    {
                        continue;
                    }

                    runtimeAssets.Add(path);
                }
            }

            // Add shared sources
            foreach (var sharedFile in project.Project.Files.SharedFiles)
            {
                sourceReferences.Add(sharedFile);
            }

            // No support for ref or native in projects, so runtimeAssemblies is
            // just the same as compileAssemblies and nativeLibraries are empty
            // Also no support for analyzer projects
            return new LibraryExport(project, compileAssemblies, sourceReferences,
                compileAssemblies, runtimeAssets, Array.Empty<LibraryAsset>(), Array.Empty<AnalyzerReference>());
        }
Esempio n. 17
0
 public LibraryExportBuilder AddRuntimeAsset(LibraryAsset asset)
 {
     Add(ref _runtimeAssets, asset);
     return(this);
 }
Esempio n. 18
0
        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());
        }
Esempio n. 19
0
 public bool Equals(LibraryAsset other)
 {
     return(string.Equals(Name, other.Name) &&
            string.Equals(RelativePath, other.RelativePath) &&
            string.Equals(ResolvedPath, other.ResolvedPath));
 }
Esempio n. 20
0
        private static AssemblyReferenceInfo GetAssemblyInfo(LibraryAsset arg)
        {
            using (var peReader = new PEReader(File.OpenRead(arg.ResolvedPath)))
            {
                var metadataReader = peReader.GetMetadataReader();

                var definition = metadataReader.GetAssemblyDefinition();

                var identity = new AssemblyIdentity(
                    metadataReader.GetString(definition.Name),
                    definition.Version,
                    metadataReader.GetString(definition.Culture),
                    GetPublicKeyToken(metadataReader.GetBlobBytes(definition.PublicKey))
                );

                var references = new List<AssemblyIdentity>(metadataReader.AssemblyReferences.Count);

                foreach (var assemblyReferenceHandle in metadataReader.AssemblyReferences)
                {
                    var assemblyReference = metadataReader.GetAssemblyReference(assemblyReferenceHandle);
                    references.Add(new AssemblyIdentity(
                        metadataReader.GetString(assemblyReference.Name),
                        assemblyReference.Version,
                        metadataReader.GetString(assemblyReference.Culture),
                        GetPublicKeyToken(metadataReader.GetBlobBytes(assemblyReference.PublicKeyOrToken))
                    ));
                }

                return new AssemblyReferenceInfo(identity, references.ToArray());
            }
        }
Esempio n. 21
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;
        }
Esempio n. 22
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            var builder = LibraryExportBuilder.Create(project);

            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 (project.Project.Files.SourceFiles.Any())
            {
                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.WithSourceReferences(project.Project.Files.SharedFiles.Select(f =>
                LibraryAsset.CreateFromAbsolutePath(project.Path, f)
            ));

            return builder.Build();
        }
Esempio n. 23
0
 public LibraryExportBuilder AddCompilationAssembly(LibraryAsset asset)
 {
     Add(ref _compilationAssemblies, asset);
     return(this);
 }
Esempio n. 24
0
 public LibraryExportBuilder AddSourceReference(LibraryAsset asset)
 {
     Add(ref _sourceReferences, asset);
     return(this);
 }
Esempio n. 25
0
        private LibraryExport ExportProject(ProjectDescription project)
        {
            if (!project.Resolved)
            {
                // For a unresolved project reference returns a export with empty asset.
                return(new LibraryExport(library: project,
                                         compileAssemblies: Enumerable.Empty <LibraryAsset>(),
                                         sourceReferences: Enumerable.Empty <string>(),
                                         nativeLibraries: Enumerable.Empty <LibraryAsset>(),
                                         runtimeAssets: Enumerable.Empty <string>(),
                                         runtimeAssemblies: Array.Empty <LibraryAsset>(),
                                         analyzers: Array.Empty <AnalyzerReference>()));
            }

            var compileAssemblies = new List <LibraryAsset>();
            var runtimeAssets     = new List <string>();
            var sourceReferences  = new List <string>();

            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,
                    null,
                    Path.GetFullPath(Path.Combine(project.Project.ProjectDirectory, assemblyPath)));

                compileAssemblies.Add(compileAsset);
                runtimeAssets.Add(pdbPath);
            }
            else if (project.Project.Files.SourceFiles.Any())
            {
                var outputCalculator = project.GetOutputPathCalculator();
                var assemblyPath     = outputCalculator.GetAssemblyPath(_configuration);
                compileAssemblies.Add(new LibraryAsset(project.Identity.Name, null, assemblyPath));

                foreach (var path in outputCalculator.GetBuildOutputs(_configuration))
                {
                    if (string.Equals(assemblyPath, path))
                    {
                        continue;
                    }

                    runtimeAssets.Add(path);
                }
            }

            // Add shared sources
            foreach (var sharedFile in project.Project.Files.SharedFiles)
            {
                sourceReferences.Add(sharedFile);
            }

            // No support for ref or native in projects, so runtimeAssemblies is
            // just the same as compileAssemblies and nativeLibraries are empty
            // Also no support for analyzer projects
            return(new LibraryExport(project, compileAssemblies, sourceReferences,
                                     compileAssemblies, runtimeAssets, Array.Empty <LibraryAsset>(), Array.Empty <AnalyzerReference>()));
        }
Esempio n. 26
0
 public bool Equals(LibraryAsset other)
 {
     return string.Equals(Name, other.Name)
         && string.Equals(RelativePath, other.RelativePath)
         && string.Equals(ResolvedPath, other.ResolvedPath);
 }
Esempio n. 27
0
 public LibraryExportBuilder AddEmbedddedResource(LibraryAsset asset)
 {
     Add(ref _embeddedResources, asset);
     return(this);
 }
Esempio n. 28
0
        private static string DetermineFileDestinationDirectory(LibraryAsset file, string outputPath, bool nativeSubdirectories)
        {
            var destinationDirectory = outputPath;

            if (nativeSubdirectories)
            {
                destinationDirectory = Path.Combine(outputPath, GetNativeRelativeSubdirectory(file.RelativePath));
            }

            return destinationDirectory;
        }
Esempio n. 29
0
 public LibraryExportBuilder AddNativeLibrary(LibraryAsset asset)
 {
     Add(ref _compilationAssets, asset);
     return(this);
 }