2015-11-16 11:21:57 -08:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
2015-10-13 14:31:29 -07:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2016-02-17 10:08:27 -08:00
|
|
|
using Microsoft.DotNet.ProjectModel.Compilation.Preprocessor;
|
|
|
|
using Microsoft.DotNet.ProjectModel.Files;
|
2015-11-27 16:19:54 -08:00
|
|
|
using Microsoft.DotNet.ProjectModel.Graph;
|
|
|
|
using Microsoft.DotNet.ProjectModel.Resolution;
|
|
|
|
using Microsoft.DotNet.ProjectModel.Utilities;
|
2016-02-17 10:08:27 -08:00
|
|
|
using Microsoft.DotNet.Tools.Compiler;
|
2015-10-13 14:31:29 -07:00
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
2015-11-27 16:19:54 -08:00
|
|
|
namespace Microsoft.DotNet.ProjectModel.Compilation
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
public class LibraryExporter
|
|
|
|
{
|
|
|
|
private readonly string _configuration;
|
2016-02-03 10:57:25 -08:00
|
|
|
private readonly string _runtime;
|
2015-10-13 14:31:29 -07:00
|
|
|
private readonly ProjectDescription _rootProject;
|
2016-02-03 10:57:25 -08:00
|
|
|
private readonly string _buildBasePath;
|
|
|
|
private readonly string _solutionRootPath;
|
|
|
|
|
|
|
|
public LibraryExporter(ProjectDescription rootProject,
|
|
|
|
LibraryManager manager,
|
|
|
|
string configuration,
|
|
|
|
string runtime,
|
|
|
|
string buildBasePath,
|
|
|
|
string solutionRootPath)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(configuration))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(configuration));
|
|
|
|
}
|
|
|
|
|
|
|
|
LibraryManager = manager;
|
|
|
|
_configuration = configuration;
|
2016-02-03 10:57:25 -08:00
|
|
|
_runtime = runtime;
|
|
|
|
_buildBasePath = buildBasePath;
|
|
|
|
_solutionRootPath = solutionRootPath;
|
2015-10-13 14:31:29 -07:00
|
|
|
_rootProject = rootProject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LibraryManager LibraryManager { get; }
|
|
|
|
|
2015-11-01 16:21:10 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets all the exports specified by this project, including the root project itself
|
|
|
|
/// </summary>
|
2015-10-13 14:31:29 -07:00
|
|
|
public IEnumerable<LibraryExport> GetAllExports()
|
|
|
|
{
|
|
|
|
return ExportLibraries(_ => true);
|
|
|
|
}
|
|
|
|
|
2015-11-01 16:21:10 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets all exports required by the project, NOT including the project itself
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public IEnumerable<LibraryExport> GetDependencies()
|
|
|
|
{
|
|
|
|
return GetDependencies(LibraryType.Unspecified);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets all exports required by the project, of the specified <see cref="LibraryType"/>, NOT including the project itself
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public IEnumerable<LibraryExport> GetDependencies(LibraryType type)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
// Export all but the main project
|
2015-11-01 16:21:10 -08:00
|
|
|
return ExportLibraries(library =>
|
|
|
|
library != _rootProject &&
|
|
|
|
LibraryIsOfType(type, library));
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <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())
|
|
|
|
{
|
2015-10-16 22:50:44 -07:00
|
|
|
if (!condition(library))
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-10-21 15:21:14 -07:00
|
|
|
var compilationAssemblies = new List<LibraryAsset>();
|
2016-02-17 10:08:27 -08:00
|
|
|
var sourceReferences = new List<LibraryAsset>();
|
2016-01-18 15:14:19 -08:00
|
|
|
var analyzerReferences = new List<AnalyzerReference>();
|
2015-10-13 14:31:29 -07:00
|
|
|
var libraryExport = GetExport(library);
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-01-11 09:37:24 -08:00
|
|
|
// We need to filter out source references from non-root libraries,
|
|
|
|
// so we rebuild the library export
|
|
|
|
foreach (var reference in libraryExport.CompilationAssemblies)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-01-11 09:37:24 -08:00
|
|
|
if (seenMetadataReferences.Add(reference.Name))
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-01-11 09:37:24 -08:00
|
|
|
compilationAssemblies.Add(reference);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-01-11 09:37:24 -08:00
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
// Source and analyzer references are not transitive
|
2016-01-11 09:37:24 -08:00
|
|
|
if (library.Parents.Contains(_rootProject))
|
|
|
|
{
|
2016-01-18 15:14:19 -08:00
|
|
|
sourceReferences.AddRange(libraryExport.SourceReferences);
|
|
|
|
analyzerReferences.AddRange(libraryExport.AnalyzerReferences);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-01-11 09:37:24 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
yield return LibraryExportBuilder.Create(library)
|
|
|
|
.WithCompilationAssemblies(compilationAssemblies)
|
|
|
|
.WithSourceReferences(sourceReferences)
|
2016-03-17 11:56:57 -07:00
|
|
|
.WithRuntimeAssemblyGroups(libraryExport.RuntimeAssemblyGroups)
|
2016-02-17 10:08:27 -08:00
|
|
|
.WithRuntimeAssets(libraryExport.RuntimeAssets)
|
2016-03-17 11:56:57 -07:00
|
|
|
.WithNativeLibraryGroups(libraryExport.NativeLibraryGroups)
|
2016-02-17 10:08:27 -08:00
|
|
|
.WithEmbedddedResources(libraryExport.EmbeddedResources)
|
|
|
|
.WithAnalyzerReference(analyzerReferences)
|
2016-03-07 10:51:40 -08:00
|
|
|
.WithResourceAssemblies(libraryExport.ResourceAssemblies)
|
2016-02-17 10:08:27 -08:00
|
|
|
.Build();
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 09:37:24 -08:00
|
|
|
/// <summary>
|
2016-02-09 16:35:43 -08:00
|
|
|
/// Create a LibraryExport from LibraryDescription.
|
|
|
|
///
|
2016-01-11 09:37:24 -08:00
|
|
|
/// When the library is not resolved the LibraryExport is created nevertheless.
|
|
|
|
/// </summary>
|
2015-10-13 14:31:29 -07:00
|
|
|
private LibraryExport GetExport(LibraryDescription library)
|
|
|
|
{
|
2016-02-15 13:50:04 -08:00
|
|
|
if (!library.Resolved)
|
|
|
|
{
|
|
|
|
// For a unresolved project reference returns a export with empty asset.
|
2016-02-17 10:08:27 -08:00
|
|
|
return LibraryExportBuilder.Create(library).Build();
|
2016-02-15 13:50:04 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 15:26:36 -07:00
|
|
|
var libraryType = library.Identity.Type;
|
|
|
|
if (Equals(LibraryType.Package, libraryType) || Equals(LibraryType.MSBuildProject, libraryType))
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
return ExportPackage((TargetLibraryWithAssets)library);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-03-23 15:26:36 -07:00
|
|
|
else if (Equals(LibraryType.Project, libraryType))
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
return ExportProject((ProjectDescription)library);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ExportFrameworkLibrary(library);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 15:26:36 -07:00
|
|
|
private LibraryExport ExportPackage(TargetLibraryWithAssets library)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
var builder = LibraryExportBuilder.Create(library);
|
|
|
|
builder.AddNativeLibraryGroup(new LibraryAssetGroup(PopulateAssets(library, library.NativeLibraries)));
|
|
|
|
builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(PopulateAssets(library, library.RuntimeAssemblies)));
|
|
|
|
builder.WithCompilationAssemblies(PopulateAssets(library, library.CompileTimeAssemblies));
|
2016-03-28 18:11:49 -07:00
|
|
|
|
|
|
|
if (library.Identity.Type.Equals(LibraryType.Package))
|
|
|
|
{
|
|
|
|
builder.WithSourceReferences(GetSharedSources((PackageDescription) library));
|
|
|
|
builder.WithAnalyzerReference(GetAnalyzerReferences((PackageDescription) library));
|
|
|
|
}
|
2016-03-23 15:26:36 -07:00
|
|
|
|
|
|
|
if (library.ContentFiles.Any())
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-02-17 10:08:27 -08:00
|
|
|
var parameters = PPFileParameters.CreateForProject(_rootProject.Project);
|
|
|
|
Action<Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters);
|
|
|
|
|
|
|
|
var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
|
2016-03-23 15:26:36 -07:00
|
|
|
var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage);
|
2016-02-17 10:08:27 -08:00
|
|
|
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;
|
|
|
|
|
2016-03-23 15:26:36 -07:00
|
|
|
var fullPath = Path.Combine(library.Path, contentFile.Path);
|
2016-02-17 10:08:27 -08:00
|
|
|
if (contentFile.BuildAction == BuildAction.Compile)
|
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
|
2016-02-17 10:08:27 -08:00
|
|
|
}
|
|
|
|
else if (contentFile.BuildAction == BuildAction.EmbeddedResource)
|
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
|
2016-02-17 10:08:27 -08:00
|
|
|
}
|
|
|
|
if (contentFile.CopyToOutput)
|
|
|
|
{
|
|
|
|
builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-03-23 15:26:36 -07:00
|
|
|
if (library.RuntimeTargets.Any())
|
2016-03-07 10:51:40 -08:00
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
foreach (var targetGroup in library.RuntimeTargets.GroupBy(t => t.Runtime))
|
2016-03-07 10:51:40 -08:00
|
|
|
{
|
|
|
|
var runtime = new List<LibraryAsset>();
|
|
|
|
var native = new List<LibraryAsset>();
|
|
|
|
|
|
|
|
foreach (var lockFileRuntimeTarget in targetGroup)
|
|
|
|
{
|
|
|
|
if (string.Equals(lockFileRuntimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
native.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
|
2016-03-07 10:51:40 -08:00
|
|
|
}
|
|
|
|
else if (string.Equals(lockFileRuntimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
runtime.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
|
2016-03-07 10:51:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 11:56:57 -07:00
|
|
|
if (runtime.Any())
|
|
|
|
{
|
2016-03-24 12:42:04 -07:00
|
|
|
builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(targetGroup.Key, runtime.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
|
2016-03-17 11:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (native.Any())
|
|
|
|
{
|
2016-03-24 12:42:04 -07:00
|
|
|
builder.AddNativeLibraryGroup(new LibraryAssetGroup(targetGroup.Key, native.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
|
2016-03-17 11:56:57 -07:00
|
|
|
}
|
2016-03-07 10:51:40 -08:00
|
|
|
}
|
|
|
|
}
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
return builder.Build();
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private LibraryExport ExportProject(ProjectDescription project)
|
|
|
|
{
|
2016-02-17 10:08:27 -08:00
|
|
|
var builder = LibraryExportBuilder.Create(project);
|
2015-10-13 14:31:29 -07:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(project.TargetFrameworkInfo?.AssemblyPath))
|
|
|
|
{
|
|
|
|
// Project specifies a pre-compiled binary. We're done!
|
|
|
|
var assemblyPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.AssemblyPath);
|
2016-01-27 13:07:26 -08:00
|
|
|
var pdbPath = Path.ChangeExtension(assemblyPath, "pdb");
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-27 13:07:26 -08:00
|
|
|
var compileAsset = new LibraryAsset(
|
2015-10-21 15:21:14 -07:00
|
|
|
project.Project.Name,
|
2016-03-04 12:16:23 -08:00
|
|
|
Path.GetFileName(assemblyPath),
|
2016-02-24 09:52:06 -08:00
|
|
|
assemblyPath);
|
2016-01-27 13:07:26 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
builder.AddCompilationAssembly(compileAsset);
|
2016-03-17 11:56:57 -07:00
|
|
|
builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compileAsset }));
|
2016-02-24 09:52:06 -08:00
|
|
|
if (File.Exists(pdbPath))
|
|
|
|
{
|
|
|
|
builder.AddRuntimeAsset(new LibraryAsset(Path.GetFileName(pdbPath), Path.GetFileName(pdbPath), pdbPath));
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-01-29 01:49:56 -08:00
|
|
|
else if (project.Project.Files.SourceFiles.Any())
|
2016-01-26 06:39:13 -08:00
|
|
|
{
|
2016-02-03 10:57:25 -08:00
|
|
|
var outputPaths = project.GetOutputPaths(_buildBasePath, _solutionRootPath, _configuration, _runtime);
|
2016-02-16 15:30:39 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
var compilationAssembly = outputPaths.CompilationFiles.Assembly;
|
|
|
|
var compilationAssemblyAsset = LibraryAsset.CreateFromAbsolutePath(
|
|
|
|
outputPaths.CompilationFiles.BasePath,
|
|
|
|
compilationAssembly);
|
|
|
|
|
|
|
|
builder.AddCompilationAssembly(compilationAssemblyAsset);
|
|
|
|
|
|
|
|
if (ExportsRuntime(project))
|
2016-02-16 15:30:39 -08:00
|
|
|
{
|
2016-02-17 10:08:27 -08:00
|
|
|
var runtimeAssemblyAsset = LibraryAsset.CreateFromAbsolutePath(
|
|
|
|
outputPaths.RuntimeFiles.BasePath,
|
|
|
|
outputPaths.RuntimeFiles.Assembly);
|
|
|
|
|
2016-03-17 11:56:57 -07:00
|
|
|
builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { runtimeAssemblyAsset }));
|
2016-02-17 10:08:27 -08:00
|
|
|
builder.WithRuntimeAssets(CollectAssets(outputPaths.RuntimeFiles));
|
2016-02-16 15:30:39 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-17 11:56:57 -07:00
|
|
|
builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(new[] { compilationAssemblyAsset }));
|
2016-02-17 10:08:27 -08:00
|
|
|
builder.WithRuntimeAssets(CollectAssets(outputPaths.CompilationFiles));
|
2016-02-16 15:30:39 -08:00
|
|
|
}
|
2016-02-17 10:08:27 -08:00
|
|
|
}
|
2016-02-03 10:57:25 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
builder.WithSourceReferences(project.Project.Files.SharedFiles.Select(f =>
|
|
|
|
LibraryAsset.CreateFromAbsolutePath(project.Path, f)
|
|
|
|
));
|
2016-01-27 13:07:26 -08:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
return builder.Build();
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
private IEnumerable<LibraryAsset> CollectAssets(CompilationOutputFiles files)
|
|
|
|
{
|
|
|
|
var assemblyPath = files.Assembly;
|
|
|
|
foreach (var path in files.All())
|
2015-10-16 22:50:44 -07:00
|
|
|
{
|
2016-02-17 10:08:27 -08:00
|
|
|
if (string.Equals(assemblyPath, path))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
yield return LibraryAsset.CreateFromAbsolutePath(files.BasePath, path);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-02-17 10:08:27 -08:00
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-02-17 10:08:27 -08:00
|
|
|
private bool ExportsRuntime(ProjectDescription project)
|
|
|
|
{
|
|
|
|
return project == _rootProject &&
|
|
|
|
!string.IsNullOrWhiteSpace(_runtime) &&
|
|
|
|
project.Project.HasRuntimeOutput(_configuration);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2015-11-01 16:21:10 -08:00
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
private static string ResolvePath(Project project, string configuration, string path)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = PathUtility.GetPathWithDirectorySeparator(path);
|
|
|
|
|
|
|
|
path = path.Replace("{configuration}", configuration);
|
|
|
|
|
2016-02-24 09:52:06 -08:00
|
|
|
return Path.Combine(project.ProjectDirectory, path);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-02-17 10:08:27 -08:00
|
|
|
var builder = LibraryExportBuilder.Create(library);
|
|
|
|
if (!string.IsNullOrEmpty(library.Path))
|
|
|
|
{
|
2016-03-17 11:56:57 -07:00
|
|
|
builder.WithCompilationAssemblies(new[]
|
2016-02-17 10:08:27 -08:00
|
|
|
{
|
|
|
|
new LibraryAsset(library.Identity.Name, null, library.Path)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return builder.Build();
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
2016-03-28 18:11:49 -07:00
|
|
|
private IEnumerable<LibraryAsset> GetSharedSources(PackageDescription package)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2016-03-28 18:11:49 -07:00
|
|
|
return package
|
|
|
|
.PackageLibrary
|
|
|
|
.Files
|
|
|
|
.Where(path => path.StartsWith("shared" + Path.DirectorySeparatorChar))
|
|
|
|
.Select(path => LibraryAsset.CreateFromRelativePath(package.Path, path));
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-03-28 18:11:49 -07:00
|
|
|
private IEnumerable<AnalyzerReference> GetAnalyzerReferences(PackageDescription package)
|
2016-01-18 15:14:19 -08:00
|
|
|
{
|
2016-03-28 18:11:49 -07:00
|
|
|
var analyzers = package
|
|
|
|
.PackageLibrary
|
|
|
|
.Files
|
|
|
|
.Where(path => path.StartsWith("analyzers" + Path.DirectorySeparatorChar) &&
|
|
|
|
path.EndsWith(".dll"));
|
|
|
|
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
var analyzerRefs = new List<AnalyzerReference>();
|
|
|
|
// See https://docs.nuget.org/create/analyzers-conventions for the analyzer
|
|
|
|
// NuGet specification
|
|
|
|
foreach (var analyzer in analyzers)
|
|
|
|
{
|
|
|
|
var specifiers = analyzer.Split(Path.DirectorySeparatorChar);
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
var assemblyPath = Path.Combine(package.Path, analyzer);
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-03-04 12:16:23 -08:00
|
|
|
// $/analyzers/{Framework Name}{Version}/{Supported Architecture}/{Supported Programming Language}/{Analyzer}.dll
|
2016-01-18 15:14:19 -08:00
|
|
|
switch (specifiers.Length)
|
|
|
|
{
|
|
|
|
// $/analyzers/{analyzer}.dll
|
|
|
|
case 2:
|
|
|
|
analyzerRefs.Add(new AnalyzerReference(
|
|
|
|
assembly: assemblyPath,
|
|
|
|
framework: null,
|
|
|
|
language: null,
|
|
|
|
runtimeIdentifier: null
|
|
|
|
));
|
|
|
|
break;
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
// $/analyzers/{framework}/{analyzer}.dll
|
|
|
|
case 3:
|
|
|
|
analyzerRefs.Add(new AnalyzerReference(
|
|
|
|
assembly: assemblyPath,
|
|
|
|
framework: NuGetFramework.Parse(specifiers[1]),
|
|
|
|
language: null,
|
|
|
|
runtimeIdentifier: null
|
|
|
|
));
|
|
|
|
break;
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
// $/analyzers/{framework}/{language}/{analyzer}.dll
|
|
|
|
case 4:
|
|
|
|
analyzerRefs.Add(new AnalyzerReference(
|
|
|
|
assembly: assemblyPath,
|
|
|
|
framework: NuGetFramework.Parse(specifiers[1]),
|
|
|
|
language: specifiers[2],
|
|
|
|
runtimeIdentifier: null
|
|
|
|
));
|
|
|
|
break;
|
2016-01-27 20:35:43 -08:00
|
|
|
|
2016-01-18 15:14:19 -08:00
|
|
|
// $/analyzers/{framework}/{runtime}/{language}/{analyzer}.dll
|
|
|
|
case 5:
|
|
|
|
analyzerRefs.Add(new AnalyzerReference(
|
|
|
|
assembly: assemblyPath,
|
|
|
|
framework: NuGetFramework.Parse(specifiers[1]),
|
|
|
|
language: specifiers[3],
|
|
|
|
runtimeIdentifier: specifiers[2]
|
|
|
|
));
|
|
|
|
break;
|
2016-01-27 20:35:43 -08:00
|
|
|
|
|
|
|
// Anything less than 2 specifiers or more than 4 is
|
|
|
|
// illegal according to the specification and will be
|
|
|
|
// ignored
|
2016-01-18 15:14:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return analyzerRefs;
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2016-03-23 15:26:36 -07:00
|
|
|
private IEnumerable<LibraryAsset> PopulateAssets(TargetLibraryWithAssets library, IEnumerable<LockFileItem> section)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
foreach (var assemblyPath in section)
|
|
|
|
{
|
2016-03-23 15:26:36 -07:00
|
|
|
yield return LibraryAsset.CreateFromRelativePath(library.Path, assemblyPath.Path);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
}
|
2015-11-01 16:21:10 -08:00
|
|
|
|
|
|
|
private static bool LibraryIsOfType(LibraryType type, LibraryDescription library)
|
|
|
|
{
|
2016-03-04 12:16:23 -08:00
|
|
|
return type.Equals(LibraryType.Unspecified) || // No type filter was requested
|
2015-11-01 16:21:10 -08:00
|
|
|
library.Identity.Type.Equals(type); // OR, library type matches requested type
|
|
|
|
}
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
2015-10-21 15:21:14 -07:00
|
|
|
}
|