Move
This commit is contained in:
parent
ac5432bff2
commit
dc249cb94b
11 changed files with 352 additions and 166 deletions
|
@ -3,7 +3,9 @@
|
||||||
"emitEntryPoint": true,
|
"emitEntryPoint": true,
|
||||||
"preserveCompilationContext": true
|
"preserveCompilationContext": true
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"Microsoft.CodeAnalysis.CSharp": "1.3.0-beta1-20160425-01"
|
||||||
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -694,18 +694,27 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
deps = JObject.ReadFrom(reader);
|
deps = JObject.ReadFrom(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
var target = deps["targets"][deps["runtimeTarget"]["name"].Value<string>()];
|
string version = null;
|
||||||
var library = target.Children<JProperty>().First();
|
foreach (JProperty target in deps["targets"])
|
||||||
var version = library.Name.Substring(library.Name.IndexOf('/') + 1);
|
{
|
||||||
|
var targetLibrary = target.Value.Children<JProperty>().FirstOrDefault();
|
||||||
|
if (targetLibrary == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
version = targetLibrary.Name.Substring(targetLibrary.Name.IndexOf('/') + 1);
|
||||||
if (newName == null)
|
if (newName == null)
|
||||||
{
|
{
|
||||||
library.Remove();
|
targetLibrary.Remove();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
library.Replace(new JProperty(newName + '/' + version, library.Value));
|
targetLibrary.Replace(new JProperty(newName + '/' + version, targetLibrary.Value));
|
||||||
}
|
}
|
||||||
library = deps["libraries"].Children<JProperty>().First();
|
}
|
||||||
|
if (version != null)
|
||||||
|
{
|
||||||
|
var library = deps["libraries"].Children<JProperty>().First();
|
||||||
if (newName == null)
|
if (newName == null)
|
||||||
{
|
{
|
||||||
library.Remove();
|
library.Remove();
|
||||||
|
@ -720,6 +729,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
deps.WriteTo(writer);
|
deps.WriteTo(writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void DeleteMainPublishOutput(string path, string name)
|
private static void DeleteMainPublishOutput(string path, string name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.ProjectModel
|
||||||
|
{
|
||||||
|
public static class ProjectModelPlatformExtensions
|
||||||
|
{
|
||||||
|
public static IEnumerable<LibraryExport> ExcludePlatformExports(this ProjectContext context, IEnumerable<LibraryExport> allExports)
|
||||||
|
{
|
||||||
|
var exclusionList = context.GetPlatformExclusionList(allExports);
|
||||||
|
return allExports.Where(e => !exclusionList.Contains(e.Library.Identity.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<string> GetPlatformExclusionList(this ProjectContext context, IEnumerable<LibraryExport> allExports)
|
||||||
|
{
|
||||||
|
var exclusionList = new HashSet<string>();
|
||||||
|
var redistPackage = context.PlatformLibrary;
|
||||||
|
if (redistPackage == null)
|
||||||
|
{
|
||||||
|
return exclusionList;
|
||||||
|
}
|
||||||
|
var exports = allExports
|
||||||
|
.Where(e => e.Library.Identity.Type.Equals(LibraryType.Package))
|
||||||
|
.ToDictionary(e => e.Library.Identity.Name);
|
||||||
|
|
||||||
|
var redistExport = exports[redistPackage.Identity.Name];
|
||||||
|
|
||||||
|
exclusionList.Add(redistExport.Library.Identity.Name);
|
||||||
|
CollectDependencies(exports, redistExport.Library.Dependencies, exclusionList);
|
||||||
|
return exclusionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CollectDependencies(Dictionary<string, LibraryExport> exports, IEnumerable<LibraryRange> dependencies, HashSet<string> exclusionList)
|
||||||
|
{
|
||||||
|
foreach (var dependency in dependencies)
|
||||||
|
{
|
||||||
|
var export = exports[dependency.Name];
|
||||||
|
if (export.Library.Identity.Version.Equals(dependency.VersionRange.MinVersion))
|
||||||
|
{
|
||||||
|
exclusionList.Add(export.Library.Identity.Name);
|
||||||
|
CollectDependencies(exports, export.Library.Dependencies, exclusionList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,34 +8,6 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.DependencyModel
|
namespace Microsoft.Extensions.DependencyModel
|
||||||
{
|
{
|
||||||
public class TargetInfo
|
|
||||||
{
|
|
||||||
public TargetInfo(string framework,
|
|
||||||
string runtime,
|
|
||||||
string runtimeSignature,
|
|
||||||
bool isPortable)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(framework))
|
|
||||||
{
|
|
||||||
throw new ArgumentException(nameof(framework));
|
|
||||||
}
|
|
||||||
|
|
||||||
Framework = framework;
|
|
||||||
Runtime = runtime;
|
|
||||||
RuntimeSignature = runtimeSignature;
|
|
||||||
IsPortable = isPortable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Framework { get; }
|
|
||||||
|
|
||||||
public string Runtime { get; }
|
|
||||||
|
|
||||||
public string RuntimeSignature { get; }
|
|
||||||
|
|
||||||
public bool IsPortable { get; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DependencyContext
|
public class DependencyContext
|
||||||
{
|
{
|
||||||
private static readonly Lazy<DependencyContext> _defaultContext = new Lazy<DependencyContext>(LoadDefault);
|
private static readonly Lazy<DependencyContext> _defaultContext = new Lazy<DependencyContext>(LoadDefault);
|
||||||
|
|
|
@ -11,8 +11,6 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
{
|
{
|
||||||
public class DependencyContextLoader
|
public class DependencyContextLoader
|
||||||
{
|
{
|
||||||
private static Lazy<string[]> _depsFiles = new Lazy<string[]>(GetHostDepsList);
|
|
||||||
|
|
||||||
private const string DepsJsonExtension = ".deps.json";
|
private const string DepsJsonExtension = ".deps.json";
|
||||||
|
|
||||||
private readonly string _entryPointDepsLocation;
|
private readonly string _entryPointDepsLocation;
|
||||||
|
@ -21,8 +19,8 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
private readonly IDependencyContextReader _jsonReader;
|
private readonly IDependencyContextReader _jsonReader;
|
||||||
|
|
||||||
public DependencyContextLoader() : this(
|
public DependencyContextLoader() : this(
|
||||||
GetDefaultEntrypointDepsLocation(),
|
DependencyContextPaths.Current.Application,
|
||||||
GetDefaultRuntimeDepsLocation(),
|
DependencyContextPaths.Current.SharedRuntime,
|
||||||
FileSystemWrapper.Default,
|
FileSystemWrapper.Default,
|
||||||
new DependencyContextJsonReader())
|
new DependencyContextJsonReader())
|
||||||
{
|
{
|
||||||
|
@ -129,36 +127,5 @@ namespace Microsoft.Extensions.DependencyModel
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetDefaultRuntimeDepsLocation()
|
|
||||||
{
|
|
||||||
var deps = _depsFiles.Value;
|
|
||||||
if (deps != null && deps.Length > 1)
|
|
||||||
{
|
|
||||||
return deps[1];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetDefaultEntrypointDepsLocation()
|
|
||||||
{
|
|
||||||
var deps = _depsFiles.Value;
|
|
||||||
if (deps != null && deps.Length > 0)
|
|
||||||
{
|
|
||||||
return deps[0];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string[] GetHostDepsList()
|
|
||||||
{
|
|
||||||
// TODO: We're going to replace this with AppContext.GetData
|
|
||||||
var appDomainType = typeof(object).GetTypeInfo().Assembly?.GetType("System.AppDomain");
|
|
||||||
var currentDomain = appDomainType?.GetProperty("CurrentDomain")?.GetValue(null);
|
|
||||||
var deps = appDomainType?.GetMethod("GetData")?.Invoke(currentDomain, new[] { "APP_CONTEXT_DEPS_FILES" });
|
|
||||||
|
|
||||||
return (deps as string)?.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.DependencyModel
|
||||||
|
{
|
||||||
|
internal class DependencyContextPaths
|
||||||
|
{
|
||||||
|
private static readonly string DepsFilesProperty = "APP_CONTEXT_DEPS_FILES";
|
||||||
|
|
||||||
|
public static DependencyContextPaths Current { get; } = GetCurrent();
|
||||||
|
|
||||||
|
public string Application { get; }
|
||||||
|
|
||||||
|
public string SharedRuntime { get; }
|
||||||
|
|
||||||
|
public DependencyContextPaths(string application, string sharedRuntime)
|
||||||
|
{
|
||||||
|
Application = application;
|
||||||
|
SharedRuntime = sharedRuntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DependencyContextPaths GetCurrent()
|
||||||
|
{
|
||||||
|
#if NETSTANDARD1_5
|
||||||
|
var deps = AppContext.GetData(DepsFilesProperty);
|
||||||
|
#else
|
||||||
|
var deps = AppDomain.CurrentDomain.GetData(DepsFilesProperty);
|
||||||
|
#endif
|
||||||
|
var files = (deps as string)?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
return new DependencyContextPaths(
|
||||||
|
files != null && files.Length > 0 ? files[0] : null,
|
||||||
|
files != null && files.Length > 1 ? files[1] : null
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,45 +11,49 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
|
||||||
{
|
{
|
||||||
public class AppBaseCompilationAssemblyResolver : ICompilationAssemblyResolver
|
public class AppBaseCompilationAssemblyResolver : ICompilationAssemblyResolver
|
||||||
{
|
{
|
||||||
|
private static string RefsDirectoryName = "refs";
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly string _basePath;
|
private readonly string _basePath;
|
||||||
|
private readonly DependencyContextPaths _dependencyContextPaths;
|
||||||
|
|
||||||
public AppBaseCompilationAssemblyResolver()
|
public AppBaseCompilationAssemblyResolver()
|
||||||
: this(FileSystemWrapper.Default)
|
: this(FileSystemWrapper.Default)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppBaseCompilationAssemblyResolver(string basePath) : this(FileSystemWrapper.Default, basePath)
|
public AppBaseCompilationAssemblyResolver(string basePath)
|
||||||
|
: this(FileSystemWrapper.Default, basePath, DependencyContextPaths.Current)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem)
|
internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem)
|
||||||
: this(fileSystem, ApplicationEnvironment.ApplicationBasePath)
|
: this(fileSystem, ApplicationEnvironment.ApplicationBasePath, DependencyContextPaths.Current)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem, string basePath)
|
internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem, string basePath, DependencyContextPaths dependencyContextPaths)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_basePath = basePath;
|
_basePath = basePath;
|
||||||
|
_dependencyContextPaths = dependencyContextPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string> assemblies)
|
public bool TryResolveAssemblyPaths(CompilationLibrary library, List<string> assemblies)
|
||||||
{
|
{
|
||||||
var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase);
|
var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var isPackage = string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase);
|
||||||
if (!isProject &&
|
if (!isProject &&
|
||||||
!string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase) &&
|
!isPackage &&
|
||||||
!string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase))
|
!string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var refsPath = Path.Combine(_basePath, "refs");
|
var refsPath = Path.Combine(_basePath, RefsDirectoryName);
|
||||||
var hasRefs = _fileSystem.Directory.Exists(refsPath);
|
var isPublished = _fileSystem.Directory.Exists(refsPath);
|
||||||
|
|
||||||
// Resolving packages and reference assebmlies requires refs folder to exist
|
// Resolving reference assebmlies requires refs folder to exist
|
||||||
if (!isProject && !hasRefs)
|
if (!isProject && !isPackage && !isPublished)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -59,11 +63,24 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
|
||||||
_basePath
|
_basePath
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasRefs)
|
if (isPublished)
|
||||||
{
|
{
|
||||||
directories.Insert(0, refsPath);
|
directories.Insert(0, refsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only packages can come from shared runtime
|
||||||
|
var sharedPath = _dependencyContextPaths.SharedRuntime;
|
||||||
|
if (isPublished && isPackage && !string.IsNullOrEmpty(sharedPath))
|
||||||
|
{
|
||||||
|
var sharedDirectory = Path.GetDirectoryName(sharedPath);
|
||||||
|
var sharedRefs = Path.Combine(sharedDirectory, RefsDirectoryName);
|
||||||
|
if (_fileSystem.Directory.Exists(sharedRefs))
|
||||||
|
{
|
||||||
|
directories.Add(sharedRefs);
|
||||||
|
}
|
||||||
|
directories.Add(sharedDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var assembly in library.Assemblies)
|
foreach (var assembly in library.Assemblies)
|
||||||
{
|
{
|
||||||
bool resolved = false;
|
bool resolved = false;
|
||||||
|
@ -80,9 +97,15 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resolved)
|
if (!resolved)
|
||||||
|
{
|
||||||
|
// throw in case when we are published app and nothing found
|
||||||
|
// because we cannot rely on nuget package cache in this case
|
||||||
|
if (isPublished)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"Can not find assembly file {assemblyFile} at '{string.Join(",", directories)}'");
|
$"Can not find assembly file {assemblyFile} at '{string.Join(",", directories)}'");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
34
src/Microsoft.Extensions.DependencyModel/TargetInfo.cs
Normal file
34
src/Microsoft.Extensions.DependencyModel/TargetInfo.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// 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.
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.DependencyModel
|
||||||
|
{
|
||||||
|
public class TargetInfo
|
||||||
|
{
|
||||||
|
public TargetInfo(string framework,
|
||||||
|
string runtime,
|
||||||
|
string runtimeSignature,
|
||||||
|
bool isPortable)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(framework))
|
||||||
|
{
|
||||||
|
throw new ArgumentException(nameof(framework));
|
||||||
|
}
|
||||||
|
|
||||||
|
Framework = framework;
|
||||||
|
Runtime = runtime;
|
||||||
|
RuntimeSignature = runtimeSignature;
|
||||||
|
IsPortable = isPortable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Framework { get; }
|
||||||
|
|
||||||
|
public string Runtime { get; }
|
||||||
|
|
||||||
|
public string RuntimeSignature { get; }
|
||||||
|
|
||||||
|
public bool IsPortable { get; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -129,18 +129,12 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
// Use a library exporter to collect publish assets
|
// Use a library exporter to collect publish assets
|
||||||
var exporter = context.CreateExporter(configuration, buildBasePath);
|
var exporter = context.CreateExporter(configuration, buildBasePath);
|
||||||
|
|
||||||
// Collect all exports and organize them
|
|
||||||
var packageExports = exporter.GetAllExports()
|
|
||||||
.Where(e => e.Library.Identity.Type.Equals(LibraryType.Package))
|
|
||||||
.ToDictionary(e => e.Library.Identity.Name);
|
|
||||||
var collectExclusionList = context.IsPortable ? GetExclusionList(context, packageExports) : new HashSet<string>();
|
|
||||||
|
|
||||||
// Get the output paths used by the call to `dotnet build` above (since we didn't pass `--output`, they will be different from
|
// Get the output paths used by the call to `dotnet build` above (since we didn't pass `--output`, they will be different from
|
||||||
// our current output paths)
|
// our current output paths)
|
||||||
var buildOutputPaths = context.GetOutputPaths(configuration, buildBasePath);
|
var buildOutputPaths = context.GetOutputPaths(configuration, buildBasePath);
|
||||||
|
|
||||||
var exports = exporter.GetAllExports();
|
var exports = exporter.GetAllExports();
|
||||||
foreach (var export in exports.Where(e => !collectExclusionList.Contains(e.Library.Identity.Name)))
|
foreach (var export in context.ExcludePlatformExports(exports))
|
||||||
{
|
{
|
||||||
Reporter.Verbose.WriteLine($"publish: Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
Reporter.Verbose.WriteLine($"publish: Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
||||||
|
|
||||||
|
@ -160,6 +154,13 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
File.Copy(resourceAsset.Asset.ResolvedPath, Path.Combine(dir, resourceAsset.Asset.FileName), overwrite: true);
|
File.Copy(resourceAsset.Asset.ResolvedPath, Path.Combine(dir, resourceAsset.Asset.FileName), overwrite: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach (var export in exports)
|
||||||
|
{
|
||||||
|
if (options.PreserveCompilationContext.GetValueOrDefault())
|
||||||
|
{
|
||||||
|
PublishRefs(export, outputPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (context.ProjectFile.HasRuntimeOutput(configuration) && !context.TargetFramework.IsDesktop())
|
if (context.ProjectFile.HasRuntimeOutput(configuration) && !context.TargetFramework.IsDesktop())
|
||||||
{
|
{
|
||||||
|
@ -171,14 +172,6 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
outputPath);
|
outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.PreserveCompilationContext.GetValueOrDefault())
|
|
||||||
{
|
|
||||||
foreach (var export in exports)
|
|
||||||
{
|
|
||||||
PublishRefs(export, outputPath, !collectExclusionList.Contains(export.Library.Identity.Name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentFiles = new ContentFiles(context);
|
var contentFiles = new ContentFiles(context);
|
||||||
|
|
||||||
if (context.ProjectFile.PublishOptions != null)
|
if (context.ProjectFile.PublishOptions != null)
|
||||||
|
@ -265,41 +258,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
return result == 0;
|
return result == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<string> GetExclusionList(ProjectContext context, Dictionary<string, LibraryExport> exports)
|
private static void PublishRefs(LibraryExport export, string outputPath)
|
||||||
{
|
|
||||||
var exclusionList = new HashSet<string>();
|
|
||||||
var redistPackages = context.RootProject.Dependencies
|
|
||||||
.Where(r => r.Type.Equals(LibraryDependencyType.Platform))
|
|
||||||
.ToList();
|
|
||||||
if (redistPackages.Count == 0)
|
|
||||||
{
|
|
||||||
return exclusionList;
|
|
||||||
}
|
|
||||||
else if (redistPackages.Count > 1)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Multiple packages with type: \"platform\" were specified!");
|
|
||||||
}
|
|
||||||
var redistExport = exports[redistPackages[0].Name];
|
|
||||||
|
|
||||||
exclusionList.Add(redistExport.Library.Identity.Name);
|
|
||||||
CollectDependencies(exports, redistExport.Library.Dependencies, exclusionList);
|
|
||||||
return exclusionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CollectDependencies(Dictionary<string, LibraryExport> exports, IEnumerable<LibraryRange> dependencies, HashSet<string> exclusionList)
|
|
||||||
{
|
|
||||||
foreach (var dependency in dependencies)
|
|
||||||
{
|
|
||||||
var export = exports[dependency.Name];
|
|
||||||
if (export.Library.Identity.Version.Equals(dependency.VersionRange.MinVersion))
|
|
||||||
{
|
|
||||||
exclusionList.Add(export.Library.Identity.Name);
|
|
||||||
CollectDependencies(exports, export.Library.Dependencies, exclusionList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PublishRefs(LibraryExport export, string outputPath, bool deduplicate)
|
|
||||||
{
|
{
|
||||||
var refsPath = Path.Combine(outputPath, "refs");
|
var refsPath = Path.Combine(outputPath, "refs");
|
||||||
if (!Directory.Exists(refsPath))
|
if (!Directory.Exists(refsPath))
|
||||||
|
@ -311,13 +270,14 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
var runtimeAssemblies = new HashSet<LibraryAsset>(export.RuntimeAssemblyGroups.GetDefaultAssets());
|
var runtimeAssemblies = new HashSet<LibraryAsset>(export.RuntimeAssemblyGroups.GetDefaultAssets());
|
||||||
foreach (var compilationAssembly in export.CompilationAssemblies)
|
foreach (var compilationAssembly in export.CompilationAssemblies)
|
||||||
{
|
{
|
||||||
if (!deduplicate || !runtimeAssemblies.Contains(compilationAssembly))
|
if (runtimeAssemblies.Contains(compilationAssembly))
|
||||||
{
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var destFileName = Path.Combine(refsPath, Path.GetFileName(compilationAssembly.ResolvedPath));
|
var destFileName = Path.Combine(refsPath, Path.GetFileName(compilationAssembly.ResolvedPath));
|
||||||
File.Copy(compilationAssembly.ResolvedPath, destFileName, overwrite: true);
|
File.Copy(compilationAssembly.ResolvedPath, destFileName, overwrite: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static int RenamePublishedHost(ProjectContext context, string outputPath, CommonCompilerOptions compilationOptions)
|
private static int RenamePublishedHost(ProjectContext context, string outputPath, CommonCompilerOptions compilationOptions)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.DependencyModel;
|
|
||||||
using Microsoft.Extensions.DependencyModel.Resolution;
|
using Microsoft.Extensions.DependencyModel.Resolution;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.DependencyModel.Tests
|
namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
{
|
{
|
||||||
public class AppBaseResolverTests
|
public class AppBaseResolverTests
|
||||||
|
@ -18,6 +17,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
private static string BasePath = Path.Combine("Base","Path");
|
private static string BasePath = Path.Combine("Base","Path");
|
||||||
private static string BasePathRefs = Path.Combine(BasePath, "refs");
|
private static string BasePathRefs = Path.Combine(BasePath, "refs");
|
||||||
|
|
||||||
|
private static string SharedFxPath = Path.Combine("shared", "fx");
|
||||||
|
private static string SharedFxPathRefs = Path.Combine(SharedFxPath, "refs");
|
||||||
|
|
||||||
|
private static DependencyContextPaths DependencyContextPaths = new DependencyContextPaths(null, Path.Combine(SharedFxPath, "deps.json"));
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolvesProjectType()
|
public void ResolvesProjectType()
|
||||||
{
|
{
|
||||||
|
@ -25,7 +29,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
.Create()
|
.Create()
|
||||||
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
.Build();
|
.Build();
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ProjectType,
|
TestLibraryFactory.ProjectType,
|
||||||
assemblies: TestLibraryFactory.EmptyAssemblies);
|
assemblies: TestLibraryFactory.EmptyAssemblies);
|
||||||
|
@ -42,7 +46,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
.Create()
|
.Create()
|
||||||
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
.Build();
|
.Build();
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.PackageType,
|
TestLibraryFactory.PackageType,
|
||||||
assemblies: TestLibraryFactory.EmptyAssemblies);
|
assemblies: TestLibraryFactory.EmptyAssemblies);
|
||||||
|
@ -59,7 +63,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
.Create()
|
.Create()
|
||||||
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
.Build();
|
.Build();
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.EmptyAssemblies);
|
assemblies: TestLibraryFactory.EmptyAssemblies);
|
||||||
|
@ -79,7 +83,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -98,7 +102,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ProjectType,
|
TestLibraryFactory.ProjectType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -120,7 +124,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var exception = Assert.Throws<InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
|
var exception = Assert.Throws<InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
|
||||||
|
@ -141,7 +145,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -164,7 +168,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
|
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -187,7 +191,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
TestLibraryFactory.ReferenceAssemblyType,
|
TestLibraryFactory.ReferenceAssemblyType,
|
||||||
assemblies: TestLibraryFactory.TwoAssemblies);
|
assemblies: TestLibraryFactory.TwoAssemblies);
|
||||||
|
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -205,12 +209,14 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
.Create()
|
.Create()
|
||||||
.AddFiles(BasePath, TestLibraryFactory.DefaultAssembly)
|
.AddFiles(BasePath, TestLibraryFactory.DefaultAssembly)
|
||||||
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
.AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.AddFile(SharedFxPath, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.AddFile(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
.Build();
|
.Build();
|
||||||
var library = TestLibraryFactory.Create(
|
var library = TestLibraryFactory.Create(
|
||||||
TestLibraryFactory.ReferenceAssemblyType
|
TestLibraryFactory.PackageType
|
||||||
);
|
);
|
||||||
|
|
||||||
var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
|
var resolver = CreateResolver(fileSystem);
|
||||||
var assemblies = new List<string>();
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
@ -220,6 +226,128 @@ namespace Microsoft.Extensions.DependencyModel.Tests
|
||||||
assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.DefaultAssembly));
|
assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.DefaultAssembly));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SearchesInSharedFxRefsPathForPublishedPortable()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
|
||||||
|
.AddFiles(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
assemblies.Should().HaveCount(1);
|
||||||
|
assemblies.Should().Contain(Path.Combine(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SearchesInSharedFxPathForPublishedPortable()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
|
||||||
|
.AddFiles(SharedFxPath, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
assemblies.Should().HaveCount(1);
|
||||||
|
assemblies.Should().Contain(Path.Combine(SharedFxPath, TestLibraryFactory.DefaultAssembly));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void PrefersSharedFxPathRefsPathPublishedPortable()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
|
||||||
|
.AddFiles(SharedFxPath, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.AddFiles(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
assemblies.Should().HaveCount(1);
|
||||||
|
assemblies.Should().Contain(Path.Combine(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SkipsSharedFxPathForNonPublishedPortable()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.AddFiles(SharedFxPath, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.AddFiles(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldThrowForNonResolvedInPublishedApps()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
|
Assert.Throws<InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldSkipForNonResolvedInNonPublishedApps()
|
||||||
|
{
|
||||||
|
var fileSystem = FileSystemMockBuilder
|
||||||
|
.Create()
|
||||||
|
.Build();
|
||||||
|
var library = TestLibraryFactory.Create(
|
||||||
|
TestLibraryFactory.PackageType
|
||||||
|
);
|
||||||
|
|
||||||
|
var resolver = CreateResolver(fileSystem);
|
||||||
|
var assemblies = new List<string>();
|
||||||
|
|
||||||
|
var result = resolver.TryResolveAssemblyPaths(library, assemblies);
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AppBaseCompilationAssemblyResolver CreateResolver(IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
return new AppBaseCompilationAssemblyResolver(fileSystem, BasePath, DependencyContextPaths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
using Microsoft.DotNet.TestFramework;
|
using System;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using FluentAssertions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish.Tests
|
namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
|
@ -93,7 +94,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
publishCommand.GetOutputDirectory(true).Should().HaveFile("PortableAppCompilationContext.dll");
|
publishCommand.GetOutputDirectory(true).Should().HaveFile("PortableAppCompilationContext.dll");
|
||||||
|
|
||||||
var refsDirectory = new DirectoryInfo(Path.Combine(publishCommand.GetOutputDirectory(true).FullName, "refs"));
|
var refsDirectory = new DirectoryInfo(Path.Combine(publishCommand.GetOutputDirectory(true).FullName, "refs"));
|
||||||
// Should have compilation time assemblies
|
// Microsoft.CodeAnalysis.CSharp is IL only
|
||||||
|
refsDirectory.Should().NotHaveFile("Microsoft.CodeAnalysis.CSharp.dll");
|
||||||
|
// System.IO has facede
|
||||||
refsDirectory.Should().HaveFile("System.IO.dll");
|
refsDirectory.Should().HaveFile("System.IO.dll");
|
||||||
// Libraries in which lib==ref should be deduped
|
// Libraries in which lib==ref should be deduped
|
||||||
refsDirectory.Should().NotHaveFile("PortableAppCompilationContext.dll");
|
refsDirectory.Should().NotHaveFile("PortableAppCompilationContext.dll");
|
||||||
|
|
Loading…
Reference in a new issue