diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 1954dd288..6bc2d6330 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -24,7 +24,13 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}" EndProject +<<<<<<< HEAD Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DependencyModel", "src\Microsoft.Extensions.DependencyModel\Microsoft.Extensions.DependencyModel.xproj", "{688870C8-9843-4F9E-8576-D39290AD0F25}" +======= +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{0722D325-24C8-4E83-B5AF-0A083E7F0749}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MultiProjectValidator", "tools\MultiProjectValidator\MultiProjectValidator.xproj", "{08A68C6A-86F6-4ED2-89A7-B166D33E9F85}" +>>>>>>> 20c8295... Removing dependency model from CLI repo. EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "EndToEnd", "test\EndToEnd\EndToEnd.xproj", "{65741CB1-8AEE-4C66-8198-10A7EA0E4258}" EndProject @@ -56,8 +62,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Installer", "Installer", "{ EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Cli.Msi.Tests", "test\Installer\Microsoft.DotNet.Cli.Msi.Tests\Microsoft.DotNet.Cli.Msi.Tests.xproj", "{0B31C336-149D-471A-B7B1-27B0F1E80F83}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DependencyModel.Tests", "test\Microsoft.Extensions.DependencyModel.Tests\Microsoft.Extensions.DependencyModel.Tests.xproj", "{4A4711D8-4312-49FC-87B5-4F183F4C6A51}" -EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.TestFramework", "src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.xproj", "{0724ED7C-56E3-4604-9970-25E600611383}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-test.UnitTests", "test\dotnet-test.UnitTests\dotnet-test.UnitTests.xproj", "{857274AC-E741-4266-A7FD-14DEE0C1CC96}" @@ -460,22 +464,6 @@ Global {0B31C336-149D-471A-B7B1-27B0F1E80F83}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {0B31C336-149D-471A-B7B1-27B0F1E80F83}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {0B31C336-149D-471A-B7B1-27B0F1E80F83}.RelWithDebInfo|x64.Build.0 = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|x64.ActiveCfg = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Debug|x64.Build.0 = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|Any CPU.Build.0 = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|x64.ActiveCfg = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.Release|x64.Build.0 = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {4A4711D8-4312-49FC-87B5-4F183F4C6A51}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {0724ED7C-56E3-4604-9970-25E600611383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0724ED7C-56E3-4604-9970-25E600611383}.Debug|Any CPU.Build.0 = Debug|Any CPU {0724ED7C-56E3-4604-9970-25E600611383}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -949,7 +937,6 @@ Global {0745410A-6629-47EB-AAB5-08D6288CAD72} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {0E3300A4-DF54-40BF-87D8-E7658330C288} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {0B31C336-149D-471A-B7B1-27B0F1E80F83} = {0E3300A4-DF54-40BF-87D8-E7658330C288} - {4A4711D8-4312-49FC-87B5-4F183F4C6A51} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {0724ED7C-56E3-4604-9970-25E600611383} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {857274AC-E741-4266-A7FD-14DEE0C1CC96} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {60C33D0A-A5D8-4AB0-9956-1F804654DF05} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} diff --git a/TestAssets/TestPackages/dotnet-dependency-context-test/project.json b/TestAssets/TestPackages/dotnet-dependency-context-test/project.json index b42583346..1f8caa758 100644 --- a/TestAssets/TestPackages/dotnet-dependency-context-test/project.json +++ b/TestAssets/TestPackages/dotnet-dependency-context-test/project.json @@ -8,9 +8,7 @@ "type": "platform", "version": "1.0.0" }, - "Microsoft.Extensions.DependencyModel": { - "target": "project" - } + "Microsoft.Extensions.DependencyModel": "1.0.1-beta-003395" }, "frameworks": { "netcoreapp1.0": { diff --git a/TestAssets/TestProjects/DependencyContextValidator/DependencyContextValidator/project.json b/TestAssets/TestProjects/DependencyContextValidator/DependencyContextValidator/project.json index ece3b95e7..d0557799a 100644 --- a/TestAssets/TestProjects/DependencyContextValidator/DependencyContextValidator/project.json +++ b/TestAssets/TestProjects/DependencyContextValidator/DependencyContextValidator/project.json @@ -1,9 +1,7 @@ { "version": "1.0.0-*", "dependencies": { - "Microsoft.Extensions.DependencyModel": { - "target": "project" - } + "Microsoft.Extensions.DependencyModel": "1.0.1-beta-003395" }, "frameworks": { "netstandard1.6": { diff --git a/src/Microsoft.DotNet.ProjectModel/project.json b/src/Microsoft.DotNet.ProjectModel/project.json index 5eb55a280..b1dca0083 100644 --- a/src/Microsoft.DotNet.ProjectModel/project.json +++ b/src/Microsoft.DotNet.ProjectModel/project.json @@ -5,9 +5,7 @@ }, "description": "Types to model a .NET Project", "dependencies": { - "Microsoft.Extensions.DependencyModel": { - "target": "project" - }, + "Microsoft.Extensions.DependencyModel": "1.0.1-beta-003394", "Newtonsoft.Json": "9.0.1", "NuGet.Configuration": "3.5.0-rc1-1697", "NuGet.Packaging": "3.5.0-rc1-1697", diff --git a/src/Microsoft.Extensions.DependencyModel/CollectionExtensions.cs b/src/Microsoft.Extensions.DependencyModel/CollectionExtensions.cs deleted file mode 100644 index 6e3f94356..000000000 --- a/src/Microsoft.Extensions.DependencyModel/CollectionExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.Extensions.DependencyModel; -using System.Linq; - -namespace System.Collections.Generic -{ - public static class CollectionExtensions - { - public static RuntimeAssetGroup GetDefaultGroup(this IEnumerable self) => GetGroup(self, string.Empty); - public static RuntimeAssetGroup GetRuntimeGroup(this IEnumerable self, string runtime) - { - if(string.IsNullOrEmpty(runtime)) - { - throw new ArgumentNullException(nameof(runtime)); - } - return GetGroup(self, runtime); - } - - private static RuntimeAssetGroup GetGroup(IEnumerable groups, string runtime) - { - return groups.FirstOrDefault(g => g.Runtime == runtime); - } - - public static IEnumerable GetDefaultAssets(this IEnumerable self) => GetAssets(self, string.Empty); - public static IEnumerable GetRuntimeAssets(this IEnumerable self, string runtime) - { - if(string.IsNullOrEmpty(runtime)) - { - throw new ArgumentNullException(nameof(runtime)); - } - return GetAssets(self, runtime); - } - - private static IEnumerable GetAssets(IEnumerable groups, string runtime) - { - return groups - .Where(a => string.Equals(a.Runtime, runtime, StringComparison.Ordinal)) - .SelectMany(a => a.AssetPaths); - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/CompilationLibrary.cs b/src/Microsoft.Extensions.DependencyModel/CompilationLibrary.cs deleted file mode 100644 index 0177f6e69..000000000 --- a/src/Microsoft.Extensions.DependencyModel/CompilationLibrary.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.DependencyModel.Resolution; - -namespace Microsoft.Extensions.DependencyModel -{ - public class CompilationLibrary : Library - { - public CompilationLibrary(string type, - string name, - string version, - string hash, - IEnumerable assemblies, - IEnumerable dependencies, - bool serviceable) - : base(type, name, version, hash, dependencies, serviceable) - { - if (assemblies == null) - { - throw new ArgumentNullException(nameof(assemblies)); - } - Assemblies = assemblies.ToArray(); - } - - public IReadOnlyList Assemblies { get; } - -#if !NETSTANDARD1_3 - internal static ICompilationAssemblyResolver DefaultResolver { get; } = new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[] - { - new PackageCacheCompilationAssemblyResolver(), - new AppBaseCompilationAssemblyResolver(), - new ReferenceAssemblyPathResolver(), - new PackageCompilationAssemblyResolver() - }); - - public IEnumerable ResolveReferencePaths() - { - var assemblies = new List(); - if (!DefaultResolver.TryResolveAssemblyPaths(this, assemblies)) - { - throw new InvalidOperationException($"Can not find compilation library location for package '{Name}'"); - } - return assemblies; - } -#endif - - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/CompilationOptions.cs b/src/Microsoft.Extensions.DependencyModel/CompilationOptions.cs deleted file mode 100644 index f37e553cb..000000000 --- a/src/Microsoft.Extensions.DependencyModel/CompilationOptions.cs +++ /dev/null @@ -1,81 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.Extensions.DependencyModel -{ - public class CompilationOptions - { - public IReadOnlyList Defines { get; } - - public string LanguageVersion { get; } - - public string Platform { get; } - - public bool? AllowUnsafe { get; } - - public bool? WarningsAsErrors { get; } - - public bool? Optimize { get; } - - public string KeyFile { get; } - - public bool? DelaySign { get; } - - public bool? PublicSign { get; } - - public string DebugType { get; } - - public bool? EmitEntryPoint { get; } - - public bool? GenerateXmlDocumentation { get; } - - public static CompilationOptions Default { get; } = new CompilationOptions( - defines: Enumerable.Empty(), - languageVersion: null, - platform: null, - allowUnsafe: null, - warningsAsErrors: null, - optimize: null, - keyFile: null, - delaySign: null, - publicSign: null, - debugType: null, - emitEntryPoint: null, - generateXmlDocumentation: null); - - public CompilationOptions(IEnumerable defines, - string languageVersion, - string platform, - bool? allowUnsafe, - bool? warningsAsErrors, - bool? optimize, - string keyFile, - bool? delaySign, - bool? publicSign, - string debugType, - bool? emitEntryPoint, - bool? generateXmlDocumentation) - { - if (defines == null) - { - throw new ArgumentNullException(nameof(defines)); - } - Defines = defines.ToArray(); - LanguageVersion = languageVersion; - Platform = platform; - AllowUnsafe = allowUnsafe; - WarningsAsErrors = warningsAsErrors; - Optimize = optimize; - KeyFile = keyFile; - DelaySign = delaySign; - PublicSign = publicSign; - DebugType = debugType; - EmitEntryPoint = emitEntryPoint; - GenerateXmlDocumentation = generateXmlDocumentation; - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/Dependency.cs b/src/Microsoft.Extensions.DependencyModel/Dependency.cs deleted file mode 100644 index 6f7672ff0..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Dependency.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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; -using Microsoft.DotNet.InternalAbstractions; - -namespace Microsoft.Extensions.DependencyModel -{ - public struct Dependency - { - public Dependency(string name, string version) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(nameof(name)); - } - if (string.IsNullOrEmpty(version)) - { - throw new ArgumentException(nameof(version)); - } - Name = name; - Version = version; - } - - public string Name { get; } - public string Version { get; } - - public bool Equals(Dependency other) - { - return string.Equals(Name, other.Name) && string.Equals(Version, other.Version); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Dependency && Equals((Dependency) obj); - } - - public override int GetHashCode() - { - var combiner = HashCodeCombiner.Start(); - combiner.Add(Name); - combiner.Add(Version); - return combiner.CombinedHash; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs deleted file mode 100644 index 18cc251a5..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs +++ /dev/null @@ -1,106 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Microsoft.Extensions.DependencyModel -{ - public class DependencyContext - { -#if !NETSTANDARD1_3 - private static readonly Lazy _defaultContext = new Lazy(LoadDefault); -#endif - - public DependencyContext(TargetInfo target, - CompilationOptions compilationOptions, - IEnumerable compileLibraries, - IEnumerable runtimeLibraries, - IEnumerable runtimeGraph) - { - if (target == null) - { - throw new ArgumentNullException(nameof(target)); - } - if (compilationOptions == null) - { - throw new ArgumentNullException(nameof(compilationOptions)); - } - if (compileLibraries == null) - { - throw new ArgumentNullException(nameof(compileLibraries)); - } - if (runtimeLibraries == null) - { - throw new ArgumentNullException(nameof(runtimeLibraries)); - } - if (runtimeGraph == null) - { - throw new ArgumentNullException(nameof(runtimeGraph)); - } - - Target = target; - CompilationOptions = compilationOptions; - CompileLibraries = compileLibraries.ToArray(); - RuntimeLibraries = runtimeLibraries.ToArray(); - RuntimeGraph = runtimeGraph.ToArray(); - } - -#if !NETSTANDARD1_3 - public static DependencyContext Default => _defaultContext.Value; -#endif - - public TargetInfo Target { get; } - - public CompilationOptions CompilationOptions { get; } - - public IReadOnlyList CompileLibraries { get; } - - public IReadOnlyList RuntimeLibraries { get; } - - public IReadOnlyList RuntimeGraph { get; } - - public DependencyContext Merge(DependencyContext other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - return new DependencyContext( - Target, - CompilationOptions, - CompileLibraries.Union(other.CompileLibraries, new LibraryMergeEqualityComparer()), - RuntimeLibraries.Union(other.RuntimeLibraries, new LibraryMergeEqualityComparer()), - RuntimeGraph.Union(other.RuntimeGraph) - ); - } - -#if !NETSTANDARD1_3 - private static DependencyContext LoadDefault() - { - return DependencyContextLoader.Default.Load(Assembly.GetEntryAssembly()); - } - - public static DependencyContext Load(Assembly assembly) - { - return DependencyContextLoader.Default.Load(assembly); - } -#endif - - private class LibraryMergeEqualityComparer : IEqualityComparer where T : Library - { - public bool Equals(T x, T y) - { - return StringComparer.OrdinalIgnoreCase.Equals(x.Name, y.Name); - } - - public int GetHashCode(T obj) - { - return StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Name); - } - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextExtensions.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextExtensions.cs deleted file mode 100644 index 59f73ea61..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextExtensions.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace Microsoft.Extensions.DependencyModel -{ - public static class DependencyContextExtensions - { - private const string NativeImageSufix = ".ni"; - - public static IEnumerable GetDefaultNativeAssets(this DependencyContext self) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - return self.RuntimeLibraries.SelectMany(library => library.GetDefaultNativeAssets(self)); - } - - public static IEnumerable GetRuntimeNativeAssets(this DependencyContext self, string runtimeIdentifier) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - if (runtimeIdentifier == null) - { - throw new ArgumentNullException(nameof(runtimeIdentifier)); - } - return self.RuntimeLibraries.SelectMany(library => library.GetRuntimeNativeAssets(self, runtimeIdentifier)); - } - - public static IEnumerable GetDefaultNativeAssets(this RuntimeLibrary self, DependencyContext context) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - return ResolveAssets(context, string.Empty, self.NativeLibraryGroups); - } - - public static IEnumerable GetRuntimeNativeAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - if (runtimeIdentifier == null) - { - throw new ArgumentNullException(nameof(runtimeIdentifier)); - } - return ResolveAssets(context, runtimeIdentifier, self.NativeLibraryGroups); - } - - public static IEnumerable GetDefaultAssemblyNames(this DependencyContext self) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - return self.RuntimeLibraries.SelectMany(library => library.GetDefaultAssemblyNames(self)); - } - - public static IEnumerable GetRuntimeAssemblyNames(this DependencyContext self, string runtimeIdentifier) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - if (runtimeIdentifier == null) - { - throw new ArgumentNullException(nameof(runtimeIdentifier)); - } - return self.RuntimeLibraries.SelectMany(library => library.GetRuntimeAssemblyNames(self, runtimeIdentifier)); - } - - public static IEnumerable GetDefaultAssemblyNames(this RuntimeLibrary self, DependencyContext context) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - return ResolveAssets(context, string.Empty, self.RuntimeAssemblyGroups).Select(GetAssemblyName); - } - - public static IEnumerable GetRuntimeAssemblyNames(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier) - { - if (self == null) - { - throw new ArgumentNullException(nameof(self)); - } - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - if (runtimeIdentifier == null) - { - throw new ArgumentNullException(nameof(runtimeIdentifier)); - } - return ResolveAssets(context, runtimeIdentifier, self.RuntimeAssemblyGroups).Select(GetAssemblyName); - } - - private static AssemblyName GetAssemblyName(string assetPath) - { - var name = Path.GetFileNameWithoutExtension(assetPath); - if (name == null) - { - throw new ArgumentException($"Provided path has empty file name '{assetPath}'", nameof(assetPath)); - } - - if (name.EndsWith(NativeImageSufix)) - { - name = name.Substring(0, name.Length - NativeImageSufix.Length); - } - - return new AssemblyName(name); - } - - private static IEnumerable ResolveAssets( - DependencyContext context, - string runtimeIdentifier, - IEnumerable assets) - { - var fallbacks = context.RuntimeGraph.FirstOrDefault(f => f.Runtime == runtimeIdentifier); - var rids = Enumerable.Concat(new[] { runtimeIdentifier }, fallbacks?.Fallbacks ?? Enumerable.Empty()); - return SelectAssets(rids, assets); - } - - private static IEnumerable SelectAssets(IEnumerable rids, IEnumerable groups) - { - foreach (var rid in rids) - { - var group = groups.FirstOrDefault(g => g.Runtime == rid); - if (group != null) - { - return group.AssetPaths; - } - } - - // Return the RID-agnostic group - return groups.GetDefaultAssets(); - } - - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs deleted file mode 100644 index 6c40ae6d5..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextJsonReader.cs +++ /dev/null @@ -1,704 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Newtonsoft.Json; - -namespace Microsoft.Extensions.DependencyModel -{ - public class DependencyContextJsonReader : IDependencyContextReader - { - private readonly IDictionary _stringPool = new Dictionary(); - - public DependencyContext Read(Stream stream) - { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } - - using (var streamReader = new StreamReader(stream)) - { - using (var reader = new JsonTextReader(streamReader)) - { - return Read(reader); - } - } - } - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - _stringPool.Clear(); - } - } - - public void Dispose() - { - Dispose(true); - } - - private DependencyContext Read(JsonTextReader reader) - { - var runtime = string.Empty; - var framework = string.Empty; - var isPortable = true; - string runtimeTargetName = null; - string runtimeSignature = null; - - reader.ReadStartObject(); - - CompilationOptions compilationOptions = null; - List targets = null; - Dictionary libraryStubs = null; - List runtimeFallbacks = null; - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - switch ((string)reader.Value) - { - case DependencyContextStrings.RuntimeTargetPropertyName: - ReadRuntimeTarget(reader, out runtimeTargetName, out runtimeSignature); - break; - case DependencyContextStrings.CompilationOptionsPropertName: - compilationOptions = ReadCompilationOptions(reader); - break; - case DependencyContextStrings.TargetsPropertyName: - targets = ReadTargets(reader); - break; - case DependencyContextStrings.LibrariesPropertyName: - libraryStubs = ReadLibraries(reader); - break; - case DependencyContextStrings.RuntimesPropertyName: - runtimeFallbacks = ReadRuntimes(reader); - break; - - } - } - - if (compilationOptions == null) - { - compilationOptions = CompilationOptions.Default; - } - - Target runtimeTarget = SelectRuntimeTarget(targets, runtimeTargetName); - runtimeTargetName = runtimeTarget?.Name; - - if (runtimeTargetName != null) - { - var seperatorIndex = runtimeTargetName.IndexOf(DependencyContextStrings.VersionSeperator); - if (seperatorIndex > -1 && seperatorIndex < runtimeTargetName.Length) - { - runtime = runtimeTargetName.Substring(seperatorIndex + 1); - framework = runtimeTargetName.Substring(0, seperatorIndex); - isPortable = false; - } - else - { - framework = runtimeTargetName; - } - } - - Target compileTarget = null; - - var ridlessTarget = targets.FirstOrDefault(t => !IsRuntimeTarget(t.Name)); - if (ridlessTarget != null) - { - compileTarget = ridlessTarget; - if (runtimeTarget == null) - { - runtimeTarget = compileTarget; - framework = ridlessTarget.Name; - } - } - - if (runtimeTarget == null) - { - throw new FormatException("No runtime target found"); - } - - return new DependencyContext( - new TargetInfo(framework, runtime, runtimeSignature, isPortable), - compilationOptions, - CreateLibraries(compileTarget?.Libraries, false, libraryStubs).Cast().ToArray(), - CreateLibraries(runtimeTarget.Libraries, true, libraryStubs).Cast().ToArray(), - runtimeFallbacks ?? Enumerable.Empty()); - } - - private Target SelectRuntimeTarget(List targets, string runtimeTargetName) - { - Target target; - - if (targets == null || targets.Count == 0) - { - throw new FormatException("Dependency file does not have 'targets' section"); - } - - if (!string.IsNullOrEmpty(runtimeTargetName)) - { - target = targets.FirstOrDefault(t => t.Name == runtimeTargetName); - if (target == null) - { - throw new FormatException($"Target with name {runtimeTargetName} not found"); - } - } - else - { - target = targets.FirstOrDefault(t => IsRuntimeTarget(t.Name)); - } - - return target; - } - - private bool IsRuntimeTarget(string name) - { - return name.Contains(DependencyContextStrings.VersionSeperator); - } - - private void ReadRuntimeTarget(JsonTextReader reader, out string runtimeTargetName, out string runtimeSignature) - { - runtimeTargetName = null; - runtimeSignature = null; - - reader.ReadStartObject(); - - string propertyName; - string propertyValue; - while (reader.TryReadStringProperty(out propertyName, out propertyValue)) - { - switch (propertyName) - { - case DependencyContextStrings.RuntimeTargetNamePropertyName: - runtimeTargetName = propertyValue; - break; - case DependencyContextStrings.RuntimeTargetSignaturePropertyName: - runtimeSignature = propertyValue; - break; - default: - throw new FormatException($"Unknown property name '{propertyName}'"); - } - } - - reader.CheckEndObject(); - } - - private CompilationOptions ReadCompilationOptions(JsonTextReader reader) - { - IEnumerable defines = null; - string languageVersion = null; - string platform = null; - bool? allowUnsafe = null; - bool? warningsAsErrors = null; - bool? optimize = null; - string keyFile = null; - bool? delaySign = null; - bool? publicSign = null; - string debugType = null; - bool? emitEntryPoint = null; - bool? generateXmlDocumentation = null; - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - switch ((string)reader.Value) - { - case DependencyContextStrings.DefinesPropertyName: - defines = reader.ReadStringArray(); - break; - case DependencyContextStrings.LanguageVersionPropertyName: - languageVersion = reader.ReadAsString(); - break; - case DependencyContextStrings.PlatformPropertyName: - platform = reader.ReadAsString(); - break; - case DependencyContextStrings.AllowUnsafePropertyName: - allowUnsafe = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.WarningsAsErrorsPropertyName: - warningsAsErrors = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.OptimizePropertyName: - optimize = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.KeyFilePropertyName: - keyFile = reader.ReadAsString(); - break; - case DependencyContextStrings.DelaySignPropertyName: - delaySign = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.PublicSignPropertyName: - publicSign = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.DebugTypePropertyName: - debugType = reader.ReadAsString(); - break; - case DependencyContextStrings.EmitEntryPointPropertyName: - emitEntryPoint = reader.ReadAsBoolean(); - break; - case DependencyContextStrings.GenerateXmlDocumentationPropertyName: - generateXmlDocumentation = reader.ReadAsBoolean(); - break; - default: - throw new FormatException($"Unknown property name '{reader.Value}'"); - } - } - - reader.CheckEndObject(); - - return new CompilationOptions( - defines ?? Enumerable.Empty(), - languageVersion, - platform, - allowUnsafe, - warningsAsErrors, - optimize, - keyFile, - delaySign, - publicSign, - debugType, - emitEntryPoint, - generateXmlDocumentation); - } - - private List ReadTargets(JsonTextReader reader) - { - reader.ReadStartObject(); - - var targets = new List(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - targets.Add(ReadTarget(reader, (string)reader.Value)); - } - - reader.CheckEndObject(); - - return targets; - } - - private Target ReadTarget(JsonTextReader reader, string targetName) - { - reader.ReadStartObject(); - - var libraries = new List(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - libraries.Add(ReadTargetLibrary(reader, (string)reader.Value)); - } - - reader.CheckEndObject(); - - return new Target() - { - Name = targetName, - Libraries = libraries - }; - } - - private TargetLibrary ReadTargetLibrary(JsonTextReader reader, string targetLibraryName) - { - IEnumerable dependencies = null; - List runtimes = null; - List natives = null; - List compilations = null; - List runtimeTargets = null; - List resources = null; - bool? compileOnly = null; - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - switch ((string)reader.Value) - { - case DependencyContextStrings.DependenciesPropertyName: - dependencies = ReadTargetLibraryDependencies(reader); - break; - case DependencyContextStrings.RuntimeAssembliesKey: - runtimes = ReadPropertyNames(reader); - break; - case DependencyContextStrings.NativeLibrariesKey: - natives = ReadPropertyNames(reader); - break; - case DependencyContextStrings.CompileTimeAssembliesKey: - compilations = ReadPropertyNames(reader); - break; - case DependencyContextStrings.RuntimeTargetsPropertyName: - runtimeTargets = ReadTargetLibraryRuntimeTargets(reader); - break; - case DependencyContextStrings.ResourceAssembliesPropertyName: - resources = ReadTargetLibraryResources(reader); - break; - case DependencyContextStrings.CompilationOnlyPropertyName: - compileOnly = reader.ReadAsBoolean(); - break; - default: - throw new FormatException($"Unknown property name '{reader.Value}'"); - } - } - - reader.CheckEndObject(); - - return new TargetLibrary() - { - Name = targetLibraryName, - Dependencies = dependencies ?? Enumerable.Empty(), - Runtimes = runtimes, - Natives = natives, - Compilations = compilations, - RuntimeTargets = runtimeTargets, - Resources = resources, - CompileOnly = compileOnly - }; - } - - - - public IEnumerable ReadTargetLibraryDependencies(JsonTextReader reader) - { - var dependencies = new List(); - string name; - string version; - - reader.ReadStartObject(); - - while (reader.TryReadStringProperty(out name, out version)) - { - dependencies.Add(new Dependency(Pool(name), Pool(version))); - } - - reader.CheckEndObject(); - - return dependencies; - } - - private List ReadPropertyNames(JsonTextReader reader) - { - var runtimes = new List(); - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - var libraryName = (string)reader.Value; - reader.Skip(); - - runtimes.Add(libraryName); - } - - reader.CheckEndObject(); - - return runtimes; - } - - private List ReadTargetLibraryRuntimeTargets(JsonTextReader reader) - { - var runtimeTargets = new List(); - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - var runtimeTarget = new RuntimeTargetEntryStub(); - runtimeTarget.Path = (string)reader.Value; - - reader.ReadStartObject(); - - string propertyName; - string propertyValue; - while (reader.TryReadStringProperty(out propertyName, out propertyValue)) - { - switch (propertyName) - { - case DependencyContextStrings.RidPropertyName: - runtimeTarget.Rid = Pool(propertyValue); - break; - case DependencyContextStrings.AssetTypePropertyName: - runtimeTarget.Type = Pool(propertyValue); - break; - default: - throw new FormatException($"Unknown property name '{propertyName}'"); - } - } - - reader.CheckEndObject(); - - runtimeTargets.Add(runtimeTarget); - } - - reader.CheckEndObject(); - - return runtimeTargets; - } - - private List ReadTargetLibraryResources(JsonTextReader reader) - { - var resources = new List(); - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - var path = (string)reader.Value; - string locale = null; - - reader.ReadStartObject(); - - string propertyName; - string propertyValue; - - while (reader.TryReadStringProperty(out propertyName, out propertyValue)) - { - if (propertyName == DependencyContextStrings.LocalePropertyName) - { - locale = propertyValue; - } - } - - reader.CheckEndObject(); - - if (locale != null) - { - resources.Add(new ResourceAssembly(path, Pool(locale))); - } - } - - reader.CheckEndObject(); - - return resources; - } - - private Dictionary ReadLibraries(JsonTextReader reader) - { - var libraries = new Dictionary(); - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - var libraryName = (string)reader.Value; - - libraries.Add(Pool(libraryName), ReadOneLibrary(reader)); - } - - reader.CheckEndObject(); - - return libraries; - } - - private LibraryStub ReadOneLibrary(JsonTextReader reader) - { - string hash = null; - string type = null; - bool serviceable = false; - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - switch ((string)reader.Value) - { - case DependencyContextStrings.Sha512PropertyName: - hash = reader.ReadAsString(); - break; - case DependencyContextStrings.TypePropertyName: - type = reader.ReadAsString(); - break; - case DependencyContextStrings.ServiceablePropertyName: - serviceable = reader.ReadAsBoolean().GetValueOrDefault(false); - break; - default: - throw new FormatException($"Unknown property name '{reader.Value}'"); - } - } - - reader.CheckEndObject(); - - return new LibraryStub() - { - Hash = hash, - Type = Pool(type), - Serviceable = serviceable - }; - } - - private List ReadRuntimes(JsonTextReader reader) - { - var runtimeFallbacks = new List(); - - reader.ReadStartObject(); - - while (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - var runtime = (string)reader.Value; - var fallbacks = reader.ReadStringArray(); - - runtimeFallbacks.Add(new RuntimeFallbacks(runtime, fallbacks)); - } - - reader.CheckEndObject(); - - return runtimeFallbacks; - } - - private IEnumerable CreateLibraries(IEnumerable libraries, bool runtime, Dictionary libraryStubs) - { - if (libraries == null) - { - return Enumerable.Empty(); - } - return libraries - .Select(property => CreateLibrary(property, runtime, libraryStubs)) - .Where(library => library != null); - } - - private Library CreateLibrary(TargetLibrary targetLibrary, bool runtime, Dictionary libraryStubs) - { - var nameWithVersion = targetLibrary.Name; - LibraryStub stub; - - if (!libraryStubs.TryGetValue(nameWithVersion, out stub)) - { - throw new InvalidOperationException($"Cannot find library information for {nameWithVersion}"); - } - - var seperatorPosition = nameWithVersion.IndexOf(DependencyContextStrings.VersionSeperator); - - var name = Pool(nameWithVersion.Substring(0, seperatorPosition)); - var version = Pool(nameWithVersion.Substring(seperatorPosition + 1)); - - if (runtime) - { - // Runtime section of this library was trimmed by type:platform - var isCompilationOnly = targetLibrary.CompileOnly; - if (isCompilationOnly == true) - { - return null; - } - - var runtimeAssemblyGroups = new List(); - var nativeLibraryGroups = new List(); - if (targetLibrary.RuntimeTargets != null) - { - foreach (var ridGroup in targetLibrary.RuntimeTargets.GroupBy(e => e.Rid)) - { - var groupRuntimeAssemblies = ridGroup - .Where(e => e.Type == DependencyContextStrings.RuntimeAssetType) - .Select(e => e.Path) - .ToArray(); - - if (groupRuntimeAssemblies.Any()) - { - runtimeAssemblyGroups.Add(new RuntimeAssetGroup( - ridGroup.Key, - groupRuntimeAssemblies.Where(a => Path.GetFileName(a) != "_._"))); - } - - var groupNativeLibraries = ridGroup - .Where(e => e.Type == DependencyContextStrings.NativeAssetType) - .Select(e => e.Path) - .ToArray(); - - if (groupNativeLibraries.Any()) - { - nativeLibraryGroups.Add(new RuntimeAssetGroup( - ridGroup.Key, - groupNativeLibraries.Where(a => Path.GetFileName(a) != "_._"))); - } - } - } - - if (targetLibrary.Runtimes != null && targetLibrary.Runtimes.Count > 0) - { - runtimeAssemblyGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Runtimes)); - } - - if (targetLibrary.Natives != null && targetLibrary.Natives.Count > 0) - { - nativeLibraryGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Natives)); - } - - return new RuntimeLibrary( - type: stub.Type, - name: name, - version: version, - hash: stub.Hash, - runtimeAssemblyGroups: runtimeAssemblyGroups, - nativeLibraryGroups: nativeLibraryGroups, - resourceAssemblies: targetLibrary.Resources ?? Enumerable.Empty(), - dependencies: targetLibrary.Dependencies, - serviceable: stub.Serviceable); - } - else - { - var assemblies = (targetLibrary.Compilations != null) ? targetLibrary.Compilations : Enumerable.Empty(); - return new CompilationLibrary(stub.Type, name, version, stub.Hash, assemblies, targetLibrary.Dependencies, stub.Serviceable); - } - } - - private string Pool(string s) - { - if (s == null) - { - return null; - } - - string result; - if (!_stringPool.TryGetValue(s, out result)) - { - _stringPool[s] = s; - result = s; - } - return result; - } - - private class Target - { - public string Name; - - public IEnumerable Libraries; - } - - private struct TargetLibrary - { - public string Name; - - public IEnumerable Dependencies; - - public List Runtimes; - - public List Natives; - - public List Compilations; - - public List RuntimeTargets; - - public List Resources; - - public bool? CompileOnly; - } - - private struct RuntimeTargetEntryStub - { - public string Type; - - public string Path; - - public string Rid; - } - - private struct LibraryStub - { - public string Hash; - - public string Type; - - public bool Serviceable; - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs deleted file mode 100644 index f848e602b..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextLoader.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using Microsoft.Extensions.EnvironmentAbstractions; - -#if !NETSTANDARD1_3 - -namespace Microsoft.Extensions.DependencyModel -{ - public class DependencyContextLoader - { - private const string DepsJsonExtension = ".deps.json"; - - private readonly string _entryPointDepsLocation; - private readonly string _runtimeDepsLocation; - private readonly IFileSystem _fileSystem; - private readonly Func _jsonReaderFactory; - - public DependencyContextLoader() : this( - DependencyContextPaths.Current.Application, - DependencyContextPaths.Current.SharedRuntime, - FileSystemWrapper.Default, - () => new DependencyContextJsonReader()) - { - } - - internal DependencyContextLoader( - string entryPointDepsLocation, - string runtimeDepsLocation, - IFileSystem fileSystem, - Func jsonReaderFactory) - { - _entryPointDepsLocation = entryPointDepsLocation; - _runtimeDepsLocation = runtimeDepsLocation; - _fileSystem = fileSystem; - _jsonReaderFactory = jsonReaderFactory; - } - - public static DependencyContextLoader Default { get; } = new DependencyContextLoader(); - - internal virtual bool IsEntryAssembly(Assembly assembly) - { - return assembly.Equals(Assembly.GetEntryAssembly()); - } - - internal virtual Stream GetResourceStream(Assembly assembly, string name) - { - return assembly.GetManifestResourceStream(name); - } - - public DependencyContext Load(Assembly assembly) - { - if (assembly == null) - { - throw new ArgumentNullException(nameof(assembly)); - } - - DependencyContext context = null; - using (var reader = _jsonReaderFactory()) - { - if (IsEntryAssembly(assembly)) - { - context = LoadEntryAssemblyContext(reader); - } - - if (context == null) - { - context = LoadAssemblyContext(assembly, reader); - } - - if (context?.Target.IsPortable == true) - { - var runtimeContext = LoadRuntimeContext(reader); - if (runtimeContext != null) - { - context = context.Merge(runtimeContext); - } - } - } - return context; - } - - private DependencyContext LoadEntryAssemblyContext(IDependencyContextReader reader) - { - if (!string.IsNullOrEmpty(_entryPointDepsLocation)) - { - Debug.Assert(File.Exists(_entryPointDepsLocation)); - using (var stream = _fileSystem.File.OpenRead(_entryPointDepsLocation)) - { - return reader.Read(stream); - } - } - return null; - } - - private DependencyContext LoadRuntimeContext(IDependencyContextReader reader) - { - if (!string.IsNullOrEmpty(_runtimeDepsLocation)) - { - Debug.Assert(File.Exists(_runtimeDepsLocation)); - using (var stream = _fileSystem.File.OpenRead(_runtimeDepsLocation)) - { - return reader.Read(stream); - } - } - return null; - } - - private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyContextReader reader) - { - using (var stream = GetResourceStream(assembly, assembly.GetName().Name + DepsJsonExtension)) - { - if (stream != null) - { - return reader.Read(stream); - } - } - - var depsJsonFile = Path.ChangeExtension(assembly.Location, DepsJsonExtension); - if (_fileSystem.File.Exists(depsJsonFile)) - { - using (var stream = _fileSystem.File.OpenRead(depsJsonFile)) - { - return reader.Read(stream); - } - } - - return null; - } - } -} - -#endif diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextPaths.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextPaths.cs deleted file mode 100644 index 6ea5b63ee..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextPaths.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; - -#if !NETSTANDARD1_3 - -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_6 - 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 - ); - } - } -} -#endif diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs deleted file mode 100644 index ab457bca1..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextStrings.cs +++ /dev/null @@ -1,80 +0,0 @@ -// 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. - -namespace Microsoft.Extensions.DependencyModel -{ - internal class DependencyContextStrings - { - internal const char VersionSeperator = '/'; - - internal const string CompileTimeAssembliesKey = "compile"; - - internal const string RuntimeAssembliesKey = "runtime"; - - internal const string NativeLibrariesKey = "native"; - - internal const string RuntimeTargetPropertyName = "runtimeTarget"; - - internal const string LibrariesPropertyName = "libraries"; - - internal const string TargetsPropertyName = "targets"; - - internal const string DependenciesPropertyName = "dependencies"; - - internal const string Sha512PropertyName = "sha512"; - - internal const string TypePropertyName = "type"; - - internal const string ServiceablePropertyName = "serviceable"; - - internal const string CompilationOptionsPropertName = "compilationOptions"; - - internal const string DefinesPropertyName = "defines"; - - internal const string LanguageVersionPropertyName = "languageVersion"; - - internal const string PlatformPropertyName = "platform"; - - internal const string AllowUnsafePropertyName = "allowUnsafe"; - - internal const string WarningsAsErrorsPropertyName = "warningsAsErrors"; - - internal const string OptimizePropertyName = "optimize"; - - internal const string KeyFilePropertyName = "keyFile"; - - internal const string DelaySignPropertyName = "delaySign"; - - internal const string PublicSignPropertyName = "publicSign"; - - internal const string DebugTypePropertyName = "debugType"; - - internal const string EmitEntryPointPropertyName = "emitEntryPoint"; - - internal const string GenerateXmlDocumentationPropertyName = "xmlDoc"; - - internal const string PortablePropertyName = "portable"; - - internal const string RuntimeTargetNamePropertyName = "name"; - - internal const string RuntimeTargetSignaturePropertyName = "signature"; - - internal const string RuntimesPropertyName = "runtimes"; - - internal const string RuntimeTargetsPropertyName = "runtimeTargets"; - - internal const string RidPropertyName = "rid"; - - internal const string AssetTypePropertyName = "assetType"; - - internal const string RuntimeAssetType = "runtime"; - - internal const string NativeAssetType = "native"; - - internal const string ResourceAssembliesPropertyName = "resources"; - - internal const string LocalePropertyName = "locale"; - - internal const string CompilationOnlyPropertyName = "compileOnly"; - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs deleted file mode 100644 index 9d774deea..000000000 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContextWriter.cs +++ /dev/null @@ -1,341 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Microsoft.Extensions.DependencyModel -{ - public class DependencyContextWriter - { - public void Write(DependencyContext context, Stream stream) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } - using (var writer = new StreamWriter(stream)) - { - using (var jsonWriter = new JsonTextWriter(writer) { Formatting = Formatting.Indented }) - { - Write(context).WriteTo(jsonWriter); - } - } - } - - private JObject Write(DependencyContext context) - { - var contextObject = new JObject( - new JProperty(DependencyContextStrings.RuntimeTargetPropertyName, WriteRuntimeTargetInfo(context)), - new JProperty(DependencyContextStrings.CompilationOptionsPropertName, WriteCompilationOptions(context.CompilationOptions)), - new JProperty(DependencyContextStrings.TargetsPropertyName, WriteTargets(context)), - new JProperty(DependencyContextStrings.LibrariesPropertyName, WriteLibraries(context)) - ); - if (context.RuntimeGraph.Any()) - { - contextObject.Add(new JProperty(DependencyContextStrings.RuntimesPropertyName, WriteRuntimeGraph(context))); - } - return contextObject; - } - - private JObject WriteRuntimeTargetInfo(DependencyContext context) - { - return new JObject( - new JProperty(DependencyContextStrings.RuntimeTargetNamePropertyName, - context.Target.IsPortable ? - context.Target.Framework : - context.Target.Framework + DependencyContextStrings.VersionSeperator + context.Target.Runtime - ), - new JProperty(DependencyContextStrings.RuntimeTargetSignaturePropertyName, - context.Target.RuntimeSignature - ) - ); - } - - private JObject WriteRuntimeGraph(DependencyContext context) - { - return new JObject( - context.RuntimeGraph.Select(g => new JProperty(g.Runtime, new JArray(g.Fallbacks))) - ); - } - - private JObject WriteCompilationOptions(CompilationOptions compilationOptions) - { - var o = new JObject(); - if (compilationOptions.Defines?.Any() == true) - { - o[DependencyContextStrings.DefinesPropertyName] = new JArray(compilationOptions.Defines); - } - AddPropertyIfNotNull(o, DependencyContextStrings.LanguageVersionPropertyName, compilationOptions.LanguageVersion); - AddPropertyIfNotNull(o, DependencyContextStrings.PlatformPropertyName, compilationOptions.Platform); - AddPropertyIfNotNull(o, DependencyContextStrings.AllowUnsafePropertyName, compilationOptions.AllowUnsafe); - AddPropertyIfNotNull(o, DependencyContextStrings.WarningsAsErrorsPropertyName, compilationOptions.WarningsAsErrors); - AddPropertyIfNotNull(o, DependencyContextStrings.OptimizePropertyName, compilationOptions.Optimize); - AddPropertyIfNotNull(o, DependencyContextStrings.KeyFilePropertyName, compilationOptions.KeyFile); - AddPropertyIfNotNull(o, DependencyContextStrings.DelaySignPropertyName, compilationOptions.DelaySign); - AddPropertyIfNotNull(o, DependencyContextStrings.PublicSignPropertyName, compilationOptions.PublicSign); - AddPropertyIfNotNull(o, DependencyContextStrings.EmitEntryPointPropertyName, compilationOptions.EmitEntryPoint); - AddPropertyIfNotNull(o, DependencyContextStrings.GenerateXmlDocumentationPropertyName, compilationOptions.GenerateXmlDocumentation); - AddPropertyIfNotNull(o, DependencyContextStrings.DebugTypePropertyName, compilationOptions.DebugType); - return o; - } - - private void AddPropertyIfNotNull(JObject o, string name, T value) - { - if (value != null) - { - o.Add(new JProperty(name, value)); - } - } - - private JObject WriteTargets(DependencyContext context) - { - if (context.Target.IsPortable) - { - return new JObject( - new JProperty(context.Target.Framework, WritePortableTarget(context.RuntimeLibraries, context.CompileLibraries)) - ); - } - - return new JObject( - new JProperty(context.Target.Framework, WriteTarget(context.CompileLibraries)), - new JProperty(context.Target.Framework + DependencyContextStrings.VersionSeperator + context.Target.Runtime, - WriteTarget(context.RuntimeLibraries)) - ); - } - - private JObject WriteTarget(IReadOnlyList libraries) - { - return new JObject( - libraries.Select(library => - // TODO: remove the hack of calling "ToLowerInvariant()" on library Name and Version once - // https://github.com/dotnet/core-setup/pull/64/ is merged and taken into the CLI - new JProperty(library.Name.ToLowerInvariant() + DependencyContextStrings.VersionSeperator + library.Version.ToLowerInvariant(), WriteTargetLibrary(library)))); - } - - private JObject WritePortableTarget(IReadOnlyList runtimeLibraries, IReadOnlyList compilationLibraries) - { - var runtimeLookup = runtimeLibraries.ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase); - var compileLookup = compilationLibraries.ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase); - - var targetObject = new JObject(); - - foreach (var packageName in runtimeLookup.Keys.Concat(compileLookup.Keys).Distinct()) - { - RuntimeLibrary runtimeLibrary; - runtimeLookup.TryGetValue(packageName, out runtimeLibrary); - - CompilationLibrary compilationLibrary; - compileLookup.TryGetValue(packageName, out compilationLibrary); - - if (compilationLibrary != null && runtimeLibrary != null) - { - Debug.Assert(compilationLibrary.Serviceable == runtimeLibrary.Serviceable); - Debug.Assert(compilationLibrary.Version == runtimeLibrary.Version); - Debug.Assert(compilationLibrary.Hash == runtimeLibrary.Hash); - Debug.Assert(compilationLibrary.Type == runtimeLibrary.Type); - } - - var library = (Library)compilationLibrary ?? (Library)runtimeLibrary; - targetObject.Add( - // TODO: remove the hack of calling "ToLowerInvariant()" on library Name and Version once - // https://github.com/dotnet/core-setup/pull/64/ is merged and taken into the CLI - new JProperty(library.Name.ToLowerInvariant() + DependencyContextStrings.VersionSeperator + library.Version.ToLowerInvariant(), - WritePortableTargetLibrary(runtimeLibrary, compilationLibrary) - ) - ); - - } - return targetObject; - } - - private void AddCompilationAssemblies(JObject libraryObject, IEnumerable compilationAssemblies) - { - if (!compilationAssemblies.Any()) - { - return; - } - libraryObject.Add(new JProperty(DependencyContextStrings.CompileTimeAssembliesKey, - WriteAssetList(compilationAssemblies)) - ); - } - - private void AddAssets(JObject libraryObject, string key, RuntimeAssetGroup group) - { - if (group == null || !group.AssetPaths.Any()) - { - return; - } - libraryObject.Add(new JProperty(key, - WriteAssetList(group.AssetPaths)) - ); - } - - private void AddDependencies(JObject libraryObject, IEnumerable dependencies) - { - if (!dependencies.Any()) - { - return; - } - libraryObject.AddFirst( - new JProperty(DependencyContextStrings.DependenciesPropertyName, - new JObject( - dependencies.Select(dependency => new JProperty(dependency.Name, dependency.Version)))) - ); - } - - private void AddResourceAssemblies(JObject libraryObject, IEnumerable resourceAssemblies) - { - if (!resourceAssemblies.Any()) - { - return; - } - libraryObject.Add(DependencyContextStrings.ResourceAssembliesPropertyName, - new JObject(resourceAssemblies.Select(a => - new JProperty(NormalizePath(a.Path), new JObject(new JProperty(DependencyContextStrings.LocalePropertyName, a.Locale)))) - ) - ); - } - - private JObject WriteTargetLibrary(Library library) - { - var runtimeLibrary = library as RuntimeLibrary; - if (runtimeLibrary != null) - { - var libraryObject = new JObject(); - AddDependencies(libraryObject, runtimeLibrary.Dependencies); - - // Add runtime-agnostic assets - AddAssets(libraryObject, DependencyContextStrings.RuntimeAssembliesKey, runtimeLibrary.RuntimeAssemblyGroups.GetDefaultGroup()); - AddAssets(libraryObject, DependencyContextStrings.NativeLibrariesKey, runtimeLibrary.NativeLibraryGroups.GetDefaultGroup()); - AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies); - - return libraryObject; - } - - var compilationLibrary = library as CompilationLibrary; - if (compilationLibrary != null) - { - var libraryObject = new JObject(); - AddDependencies(libraryObject, compilationLibrary.Dependencies); - AddCompilationAssemblies(libraryObject, compilationLibrary.Assemblies); - return libraryObject; - } - throw new NotSupportedException(); - } - - private JObject WritePortableTargetLibrary(RuntimeLibrary runtimeLibrary, CompilationLibrary compilationLibrary) - { - var libraryObject = new JObject(); - - var dependencies = new HashSet(); - if (runtimeLibrary != null) - { - // Add runtime-agnostic assets - AddAssets(libraryObject, DependencyContextStrings.RuntimeAssembliesKey, runtimeLibrary.RuntimeAssemblyGroups.GetDefaultGroup()); - AddAssets(libraryObject, DependencyContextStrings.NativeLibrariesKey, runtimeLibrary.NativeLibraryGroups.GetDefaultGroup()); - AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies); - - // Add runtime-specific assets - var runtimeTargets = new JObject(); - AddRuntimeSpecificAssetGroups(runtimeTargets, DependencyContextStrings.RuntimeAssetType, runtimeLibrary.RuntimeAssemblyGroups); - AddRuntimeSpecificAssetGroups(runtimeTargets, DependencyContextStrings.NativeAssetType, runtimeLibrary.NativeLibraryGroups); - if (runtimeTargets.Count > 0) - { - libraryObject.Add(DependencyContextStrings.RuntimeTargetsPropertyName, runtimeTargets); - } - - dependencies.UnionWith(runtimeLibrary.Dependencies); - } - - if (compilationLibrary != null) - { - AddCompilationAssemblies(libraryObject, compilationLibrary.Assemblies); - - dependencies.UnionWith(compilationLibrary.Dependencies); - } - - AddDependencies(libraryObject, dependencies); - if (compilationLibrary != null && runtimeLibrary == null) - { - libraryObject.Add(DependencyContextStrings.CompilationOnlyPropertyName, true); - } - return libraryObject; - } - - private void AddRuntimeSpecificAssetGroups(JObject runtimeTargets, string assetType, IEnumerable assetGroups) - { - foreach (var group in assetGroups.Where(g => !string.IsNullOrEmpty(g.Runtime))) - { - if (group.AssetPaths.Any()) - { - AddRuntimeSpecificAssets(runtimeTargets, group.AssetPaths, group.Runtime, assetType); - } - else - { - // Add a placeholder item - // We need to generate a pseudo-path because there could be multiple different asset groups with placeholders - // Only the last path segment matters, the rest is basically just a GUID. - var pseudoPathFolder = assetType == DependencyContextStrings.RuntimeAssetType ? - "lib" : - "native"; - runtimeTargets[$"runtime/{group.Runtime}/{pseudoPathFolder}/_._"] = new JObject( - new JProperty(DependencyContextStrings.RidPropertyName, group.Runtime), - new JProperty(DependencyContextStrings.AssetTypePropertyName, assetType)); - } - } - } - - private void AddRuntimeSpecificAssets(JObject target, IEnumerable assets, string runtime, string assetType) - { - foreach (var asset in assets) - { - target.Add(new JProperty(NormalizePath(asset), - new JObject( - new JProperty(DependencyContextStrings.RidPropertyName, runtime), - new JProperty(DependencyContextStrings.AssetTypePropertyName, assetType) - ) - )); - } - } - - private JObject WriteAssetList(IEnumerable assetPaths) - { - return new JObject(assetPaths.Select(assembly => new JProperty(NormalizePath(assembly), new JObject()))); - } - - private JObject WriteLibraries(DependencyContext context) - { - var allLibraries = - context.RuntimeLibraries.Cast().Concat(context.CompileLibraries) - // TODO: remove the hack of calling "ToLowerInvariant()" on library Name and Version once - // https://github.com/dotnet/core-setup/pull/64/ is merged and taken into the CLI - .GroupBy(library => library.Name.ToLowerInvariant() + DependencyContextStrings.VersionSeperator + library.Version.ToLowerInvariant()); - - return new JObject(allLibraries.Select(libraries => new JProperty(libraries.Key, WriteLibrary(libraries.First())))); - } - - private JObject WriteLibrary(Library library) - { - return new JObject( - new JProperty(DependencyContextStrings.TypePropertyName, library.Type), - new JProperty(DependencyContextStrings.ServiceablePropertyName, library.Serviceable), - new JProperty(DependencyContextStrings.Sha512PropertyName, library.Hash) - ); - } - - private string NormalizePath(string path) - { - return path.Replace('\\', '/'); - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/IDependencyContextReader.cs b/src/Microsoft.Extensions.DependencyModel/IDependencyContextReader.cs deleted file mode 100644 index 0603b5b66..000000000 --- a/src/Microsoft.Extensions.DependencyModel/IDependencyContextReader.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.IO; - -namespace Microsoft.Extensions.DependencyModel -{ - public interface IDependencyContextReader: IDisposable - { - DependencyContext Read(Stream stream); - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/JsonTextReaderExtensions.cs b/src/Microsoft.Extensions.DependencyModel/JsonTextReaderExtensions.cs deleted file mode 100644 index bf2122f03..000000000 --- a/src/Microsoft.Extensions.DependencyModel/JsonTextReaderExtensions.cs +++ /dev/null @@ -1,77 +0,0 @@ -// 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; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Microsoft.Extensions.DependencyModel -{ - internal static class JsonTextReaderExtensions - { - internal static bool TryReadStringProperty(this JsonTextReader reader, out string name, out string value) - { - name = null; - value = null; - if (reader.Read() && reader.TokenType == JsonToken.PropertyName) - { - name = (string)reader.Value; - value = reader.ReadAsString(); - return true; - } - - return false; - } - - internal static void ReadStartObject(this JsonTextReader reader) - { - reader.Read(); - CheckStartObject(reader); - } - - internal static void CheckStartObject(this JsonTextReader reader) - { - if (reader.TokenType != JsonToken.StartObject) - { - throw CreateUnexpectedException(reader, "{"); - } - } - - internal static void CheckEndObject(this JsonTextReader reader) - { - if (reader.TokenType != JsonToken.EndObject) - { - throw CreateUnexpectedException(reader, "}"); - } - } - - internal static string[] ReadStringArray(this JsonTextReader reader) - { - reader.Read(); - if (reader.TokenType != JsonToken.StartArray) - { - throw CreateUnexpectedException(reader,"["); - } - - var items = new List(); - - while (reader.Read() && reader.TokenType == JsonToken.String) - { - items.Add((string)reader.Value); - } - - if (reader.TokenType != JsonToken.EndArray) - { - throw CreateUnexpectedException(reader, "]"); - } - - return items.ToArray(); - } - - internal static Exception CreateUnexpectedException(JsonTextReader reader, string expected) - { - return new FormatException($"Unexpected character encountered, excepted '{expected}' " + - $"at line {reader.LineNumber} position {reader.LinePosition} path {reader.Path}"); - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/Library.cs b/src/Microsoft.Extensions.DependencyModel/Library.cs deleted file mode 100644 index 5e9b074e5..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Library.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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; -using System.Linq; -using System.Collections.Generic; - -namespace Microsoft.Extensions.DependencyModel -{ - public class Library - { - public Library(string type, string name, string version, string hash, IEnumerable dependencies, bool serviceable) - { - if (string.IsNullOrEmpty(type)) - { - throw new ArgumentException(nameof(type)); - } - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(nameof(name)); - } - if (string.IsNullOrEmpty(version)) - { - throw new ArgumentException(nameof(version)); - } - if (dependencies == null) - { - throw new ArgumentNullException(nameof(dependencies)); - } - Type = type; - Name = name; - Version = version; - Hash = hash; - Dependencies = dependencies.ToArray(); - Serviceable = serviceable; - } - - public string Type { get; } - - public string Name { get; } - - public string Version { get; } - - public string Hash { get; } - - public IReadOnlyList Dependencies { get; } - - public bool Serviceable { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.xproj b/src/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.xproj deleted file mode 100644 index 8c6e7884f..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0.23107 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 688870c8-9843-4f9e-8576-d39290ad0f25 - Microsoft.Extensions.DependencyModel - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin - - - 2.0 - - - \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Properties/Properties.cs b/src/Microsoft.Extensions.DependencyModel/Properties/Properties.cs deleted file mode 100644 index b8c122eba..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Properties/Properties.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyMetadataAttribute("Serviceable", "True")] -[assembly: InternalsVisibleTo("Microsoft.Extensions.DependencyModel.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs deleted file mode 100644 index 38f7c1187..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs +++ /dev/null @@ -1,121 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.EnvironmentAbstractions; - -#if !NETSTANDARD1_3 - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class AppBaseCompilationAssemblyResolver : ICompilationAssemblyResolver - { - private static string RefsDirectoryName = "refs"; - private readonly IFileSystem _fileSystem; - private readonly string _basePath; - private readonly DependencyContextPaths _dependencyContextPaths; - - public AppBaseCompilationAssemblyResolver() - : this(FileSystemWrapper.Default) - { - } - - public AppBaseCompilationAssemblyResolver(string basePath) - : this(FileSystemWrapper.Default, basePath, DependencyContextPaths.Current) - { - } - - internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem) - : this(fileSystem, ApplicationEnvironment.ApplicationBasePath, DependencyContextPaths.Current) - { - } - - internal AppBaseCompilationAssemblyResolver(IFileSystem fileSystem, string basePath, DependencyContextPaths dependencyContextPaths) - { - _fileSystem = fileSystem; - _basePath = basePath; - _dependencyContextPaths = dependencyContextPaths; - } - - public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies) - { - var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase) || - string.Equals(library.Type, "msbuildproject", StringComparison.OrdinalIgnoreCase); - - var isPackage = string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase); - if (!isProject && - !isPackage && - !string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - var refsPath = Path.Combine(_basePath, RefsDirectoryName); - var isPublished = _fileSystem.Directory.Exists(refsPath); - - // Resolving reference assebmlies requires refs folder to exist - if (!isProject && !isPackage && !isPublished) - { - return false; - } - - var directories = new List() - { - _basePath - }; - - if (isPublished) - { - 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) - { - bool resolved = false; - var assemblyFile = Path.GetFileName(assembly); - foreach (var directory in directories) - { - string fullName; - if (ResolverUtils.TryResolveAssemblyFile(_fileSystem, directory, assemblyFile, out fullName)) - { - assemblies.Add(fullName); - resolved = true; - break; - } - } - - 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( - $"Can not find assembly file {assemblyFile} at '{string.Join(",", directories)}'"); - } - return false; - } - } - - return true; - } - } -} - -#endif diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/CompositeCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/CompositeCompilationAssemblyResolver.cs deleted file mode 100644 index c6daf2bf7..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/CompositeCompilationAssemblyResolver.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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.Collections.Generic; -using Microsoft.Extensions.DependencyModel.Resolution; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class CompositeCompilationAssemblyResolver: ICompilationAssemblyResolver - { - private readonly ICompilationAssemblyResolver[] _resolvers; - - public CompositeCompilationAssemblyResolver(ICompilationAssemblyResolver[] resolvers) - { - _resolvers = resolvers; - } - - public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies) - { - foreach (var resolver in _resolvers) - { - if (resolver.TryResolveAssemblyPaths(library, assemblies)) - { - return true; - } - } - return false;; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs deleted file mode 100644 index ef356d054..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/DotNetReferenceAssembliesPathResolver.cs +++ /dev/null @@ -1,57 +0,0 @@ -// 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 Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class DotNetReferenceAssembliesPathResolver - { - public static readonly string DotNetReferenceAssembliesPathEnv = "DOTNET_REFERENCE_ASSEMBLIES_PATH"; - - internal static string Resolve(IEnvironment envirnment, IFileSystem fileSystem) - { - var path = envirnment.GetEnvironmentVariable(DotNetReferenceAssembliesPathEnv); - if (!string.IsNullOrEmpty(path)) - { - return path; - } - - return GetDefaultDotNetReferenceAssembliesPath(fileSystem); - } - - public static string Resolve() - { - return Resolve(EnvironmentWrapper.Default, FileSystemWrapper.Default); - } - - private static string GetDefaultDotNetReferenceAssembliesPath(IFileSystem fileSystem) - { - var os = RuntimeEnvironment.OperatingSystemPlatform; - - if (os == Platform.Windows) - { - return null; - } - - if (os == Platform.Darwin && - fileSystem.Directory.Exists("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks")) - { - return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks"; - } - - if (fileSystem.Directory.Exists("/usr/local/lib/mono/xbuild-frameworks")) - { - return "/usr/local/lib/mono/xbuild-frameworks"; - } - - if (fileSystem.Directory.Exists("/usr/lib/mono/xbuild-frameworks")) - { - return "/usr/lib/mono/xbuild-frameworks"; - } - - return null; - } - } -} diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ICompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ICompilationAssemblyResolver.cs deleted file mode 100644 index b4eed2a57..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ICompilationAssemblyResolver.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Collections.Generic; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public interface ICompilationAssemblyResolver - { - bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies); - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs deleted file mode 100644 index 7497f0e08..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs +++ /dev/null @@ -1,75 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class PackageCacheCompilationAssemblyResolver: ICompilationAssemblyResolver - { - private readonly IFileSystem _fileSystem; - private readonly string _packageCacheDirectory; - - public PackageCacheCompilationAssemblyResolver() - : this(FileSystemWrapper.Default, EnvironmentWrapper.Default) - { - } - - public PackageCacheCompilationAssemblyResolver(string packageCacheDirectory) - : this(FileSystemWrapper.Default, packageCacheDirectory) - { - } - - internal PackageCacheCompilationAssemblyResolver(IFileSystem fileSystem, IEnvironment environment) - : this(fileSystem, GetDefaultPackageCacheDirectory(environment)) - { - } - - internal PackageCacheCompilationAssemblyResolver(IFileSystem fileSystem, string packageCacheDirectory) - { - _packageCacheDirectory = packageCacheDirectory; - _fileSystem = fileSystem; - } - - public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies) - { - if (!string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - if (!string.IsNullOrEmpty(_packageCacheDirectory)) - { - var hashSplitterPos = library.Hash.IndexOf('-'); - if (hashSplitterPos <= 0 || hashSplitterPos == library.Hash.Length - 1) - { - throw new InvalidOperationException($"Invalid hash entry '{library.Hash}' for package '{library.Name}'"); - } - - string packagePath; - if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, _packageCacheDirectory, out packagePath)) - { - var hashAlgorithm = library.Hash.Substring(0, hashSplitterPos); - var cacheHashFileName = $"{library.Name.ToLowerInvariant()}.{library.Version.ToLowerInvariant()}.nupkg.{hashAlgorithm}"; - var cacheHashPath = Path.Combine(packagePath, cacheHashFileName); - - if (_fileSystem.File.Exists(cacheHashPath) && - _fileSystem.File.ReadAllText(cacheHashPath) == library.Hash.Substring(hashSplitterPos + 1)) - { - assemblies.AddRange(ResolverUtils.ResolveFromPackagePath(_fileSystem, library, packagePath)); - return true; - } - } - } - return false; - } - - internal static string GetDefaultPackageCacheDirectory(IEnvironment environment) - { - return environment.GetEnvironmentVariable("DOTNET_PACKAGES_CACHE"); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs deleted file mode 100644 index f49f7815d..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs +++ /dev/null @@ -1,85 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class PackageCompilationAssemblyResolver: ICompilationAssemblyResolver - { - private readonly IFileSystem _fileSystem; - private readonly string _nugetPackageDirectory; - - public PackageCompilationAssemblyResolver() - : this(EnvironmentWrapper.Default, FileSystemWrapper.Default) - { - } - - public PackageCompilationAssemblyResolver(string nugetPackageDirectory) - : this(FileSystemWrapper.Default, nugetPackageDirectory) - { - } - - internal PackageCompilationAssemblyResolver(IEnvironment environment, - IFileSystem fileSystem) - : this(fileSystem, GetDefaultPackageDirectory(environment)) - { - } - - internal PackageCompilationAssemblyResolver(IFileSystem fileSystem, string nugetPackageDirectory) - { - _fileSystem = fileSystem; - _nugetPackageDirectory = nugetPackageDirectory; - } - - private static string GetDefaultPackageDirectory(IEnvironment environment) => - GetDefaultPackageDirectory(RuntimeEnvironment.OperatingSystemPlatform, environment); - - internal static string GetDefaultPackageDirectory(Platform osPlatform, IEnvironment environment) - { - var packageDirectory = environment.GetEnvironmentVariable("NUGET_PACKAGES"); - - if (!string.IsNullOrEmpty(packageDirectory)) - { - return packageDirectory; - } - - string basePath; - if (osPlatform == Platform.Windows) - { - basePath = environment.GetEnvironmentVariable("USERPROFILE"); - } - else - { - basePath = environment.GetEnvironmentVariable("HOME"); - } - if (string.IsNullOrEmpty(basePath)) - { - return null; - } - return Path.Combine(basePath, ".nuget", "packages"); - } - - public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies) - { - if (string.IsNullOrEmpty(_nugetPackageDirectory) || - !string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - string packagePath; - - if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, _nugetPackageDirectory, out packagePath)) - { - assemblies.AddRange(ResolverUtils.ResolveFromPackagePath(_fileSystem, library, packagePath)); - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs deleted file mode 100644 index 9ad6b3d41..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ReferenceAssemblyPathResolver.cs +++ /dev/null @@ -1,141 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - public class ReferenceAssemblyPathResolver: ICompilationAssemblyResolver - { - private readonly IFileSystem _fileSystem; - private readonly string _defaultReferenceAssembliesPath; - private readonly string[] _fallbackSearchPaths; - - public ReferenceAssemblyPathResolver() - : this(FileSystemWrapper.Default, EnvironmentWrapper.Default) - { - } - - public ReferenceAssemblyPathResolver(string defaultReferenceAssembliesPath, string[] fallbackSearchPaths) - : this(FileSystemWrapper.Default, defaultReferenceAssembliesPath, fallbackSearchPaths) - { - } - - internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, IEnvironment environment) - : this(fileSystem, - GetDefaultReferenceAssembliesPath(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment), - GetFallbackSearchPaths(fileSystem, RuntimeEnvironment.OperatingSystemPlatform, environment)) - { - } - - internal ReferenceAssemblyPathResolver(IFileSystem fileSystem, string defaultReferenceAssembliesPath, string[] fallbackSearchPaths) - { - _fileSystem = fileSystem; - _defaultReferenceAssembliesPath = defaultReferenceAssembliesPath; - _fallbackSearchPaths = fallbackSearchPaths; - } - - public bool TryResolveAssemblyPaths(CompilationLibrary library, List assemblies) - { - if (!string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - foreach (var assembly in library.Assemblies) - { - string fullName; - if (!TryResolveReferenceAssembly(assembly, out fullName)) - { - throw new InvalidOperationException($"Can not find reference assembly '{assembly}' file for package {library.Name}"); - } - assemblies.Add(fullName); - } - return true; - } - - private bool TryResolveReferenceAssembly(string path, out string fullPath) - { - fullPath = null; - - if (_defaultReferenceAssembliesPath != null) - { - var relativeToReferenceAssemblies = Path.Combine(_defaultReferenceAssembliesPath, path); - if (_fileSystem.File.Exists(relativeToReferenceAssemblies)) - { - fullPath = relativeToReferenceAssemblies; - return true; - } - } - - var name = Path.GetFileName(path); - foreach (var fallbackPath in _fallbackSearchPaths) - { - var fallbackFile = Path.Combine(fallbackPath, name); - if (_fileSystem.File.Exists(fallbackFile)) - { - fullPath = fallbackFile; - return true; - } - } - - return false; - } - - internal static string[] GetFallbackSearchPaths(IFileSystem fileSystem, Platform platform, IEnvironment environment) - { - if (platform != Platform.Windows) - { - return new string[0]; - } - - var net20Dir = Path.Combine(environment.GetEnvironmentVariable("WINDIR"), "Microsoft.NET", "Framework", "v2.0.50727"); - - if (!fileSystem.Directory.Exists(net20Dir)) - { - return new string[0]; - } - return new[] { net20Dir }; - } - - internal static string GetDefaultReferenceAssembliesPath(IFileSystem fileSystem, Platform platform, IEnvironment environment) - { - // Allow setting the reference assemblies path via an environment variable - var referenceAssembliesPath = DotNetReferenceAssembliesPathResolver.Resolve(environment, fileSystem); - if (!string.IsNullOrEmpty(referenceAssembliesPath)) - { - return referenceAssembliesPath; - } - - if (platform != Platform.Windows) - { - // There is no reference assemblies path outside of windows - // The environment variable can be used to specify one - return null; - } - - // References assemblies are in %ProgramFiles(x86)% on - // 64 bit machines - var programFiles = environment.GetEnvironmentVariable("ProgramFiles(x86)"); - - if (string.IsNullOrEmpty(programFiles)) - { - // On 32 bit machines they are in %ProgramFiles% - programFiles = environment.GetEnvironmentVariable("ProgramFiles"); - } - - if (string.IsNullOrEmpty(programFiles)) - { - // Reference assemblies aren't installed - return null; - } - - return Path.Combine( - programFiles, - "Reference Assemblies", "Microsoft", "Framework"); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs deleted file mode 100644 index e105ad8c5..000000000 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Resolution -{ - internal static class ResolverUtils - { - internal static bool TryResolvePackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, out string packagePath) - { - packagePath = Path.Combine( - basePath, - library.Name.ToLowerInvariant(), - library.Version.ToLowerInvariant()); - - if (fileSystem.Directory.Exists(packagePath)) - { - return true; - } - return false; - } - - internal static IEnumerable ResolveFromPackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath) - { - foreach (var assembly in library.Assemblies) - { - string fullName; - if (!TryResolveAssemblyFile(fileSystem, basePath, assembly, out fullName)) - { - throw new InvalidOperationException($"Can not find assembly file for package {library.Name} at '{fullName}'"); - } - yield return fullName; - } - } - - internal static bool TryResolveAssemblyFile(IFileSystem fileSystem, string basePath, string assemblyPath, out string fullName) - { - fullName = Path.Combine(basePath, assemblyPath); - if (fileSystem.File.Exists(fullName)) - { - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/ResourceAssembly.cs b/src/Microsoft.Extensions.DependencyModel/ResourceAssembly.cs deleted file mode 100644 index 4a59c054a..000000000 --- a/src/Microsoft.Extensions.DependencyModel/ResourceAssembly.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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 ResourceAssembly - { - public ResourceAssembly(string path, string locale) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentException(nameof(path)); - } - if (string.IsNullOrEmpty(locale)) - { - throw new ArgumentException(nameof(locale)); - } - Locale = locale; - Path = path; - } - - public string Locale { get; set; } - - public string Path { get; set; } - - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/RuntimeAssembly.cs b/src/Microsoft.Extensions.DependencyModel/RuntimeAssembly.cs deleted file mode 100644 index 4dfd497fb..000000000 --- a/src/Microsoft.Extensions.DependencyModel/RuntimeAssembly.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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; -using System.Reflection; - -namespace Microsoft.Extensions.DependencyModel -{ - public class RuntimeAssembly - { - private const string NativeImageSufix = ".ni"; - private readonly string _assemblyName; - - public RuntimeAssembly(string assemblyName, string path) - { - if (string.IsNullOrEmpty(assemblyName)) - { - throw new ArgumentException(nameof(assemblyName)); - } - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentException(nameof(path)); - } - _assemblyName = assemblyName; - Path = path; - } - - public AssemblyName Name => new AssemblyName(_assemblyName); - - public string Path { get; } - - public static RuntimeAssembly Create(string path) - { - var assemblyName = System.IO.Path.GetFileNameWithoutExtension(path); - if (assemblyName == null) - { - throw new ArgumentException($"Provided path has empty file name '{path}'", nameof(path)); - } - - if (assemblyName.EndsWith(NativeImageSufix)) - { - assemblyName = assemblyName.Substring(0, assemblyName.Length - NativeImageSufix.Length); - } - return new RuntimeAssembly(assemblyName, path); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/RuntimeAssetGroup.cs b/src/Microsoft.Extensions.DependencyModel/RuntimeAssetGroup.cs deleted file mode 100644 index d9eee3eb6..000000000 --- a/src/Microsoft.Extensions.DependencyModel/RuntimeAssetGroup.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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.Linq; -using System.Collections.Generic; - -namespace Microsoft.Extensions.DependencyModel -{ - public class RuntimeAssetGroup - { - public RuntimeAssetGroup(string runtime, params string[] assetPaths) : this(runtime, (IEnumerable)assetPaths) { } - - public RuntimeAssetGroup(string runtime, IEnumerable assetPaths) - { - Runtime = runtime; - AssetPaths = assetPaths.ToArray(); - } - - /// - /// The runtime ID associated with this group (may be empty if the group is runtime-agnostic) - /// - public string Runtime { get; } - - /// - /// Gets a list of assets provided in this runtime group - /// - public IReadOnlyList AssetPaths { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/RuntimeFallbacks.cs b/src/Microsoft.Extensions.DependencyModel/RuntimeFallbacks.cs deleted file mode 100644 index 626aa5b24..000000000 --- a/src/Microsoft.Extensions.DependencyModel/RuntimeFallbacks.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.Extensions.DependencyModel -{ - public class RuntimeFallbacks - { - public string Runtime { get; set; } - public IReadOnlyList Fallbacks { get; set; } - - public RuntimeFallbacks(string runtime, params string[] fallbacks) : this(runtime, (IEnumerable)fallbacks) { } - public RuntimeFallbacks(string runtime, IEnumerable fallbacks) - { - if (string.IsNullOrEmpty(runtime)) - { - throw new ArgumentException(nameof(runtime)); - } - if (fallbacks == null) - { - throw new ArgumentNullException(nameof(fallbacks)); - } - Runtime = runtime; - Fallbacks = fallbacks.ToArray(); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/RuntimeLibrary.cs b/src/Microsoft.Extensions.DependencyModel/RuntimeLibrary.cs deleted file mode 100644 index 8cf195dfe..000000000 --- a/src/Microsoft.Extensions.DependencyModel/RuntimeLibrary.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.Extensions.DependencyModel -{ - public class RuntimeLibrary : Library - { - public RuntimeLibrary( - string type, - string name, - string version, - string hash, - IReadOnlyList runtimeAssemblyGroups, - IReadOnlyList nativeLibraryGroups, - IEnumerable resourceAssemblies, - IEnumerable dependencies, - bool serviceable) - : base(type, name, version, hash, dependencies, serviceable) - { - if (runtimeAssemblyGroups == null) - { - throw new ArgumentNullException(nameof(runtimeAssemblyGroups)); - } - if (nativeLibraryGroups == null) - { - throw new ArgumentNullException(nameof(nativeLibraryGroups)); - } - if (resourceAssemblies == null) - { - throw new ArgumentNullException(nameof(resourceAssemblies)); - } - RuntimeAssemblyGroups = runtimeAssemblyGroups; - ResourceAssemblies = resourceAssemblies.ToArray(); - NativeLibraryGroups = nativeLibraryGroups; - - Assemblies = new RuntimeAssembly[0]; - NativeLibraries = new string[0]; - } - - // Temporary (legacy) properties: https://github.com/dotnet/cli/issues/1998 - public IReadOnlyList Assemblies { get; } - public IReadOnlyList NativeLibraries { get; } - - public IReadOnlyList RuntimeAssemblyGroups { get; } - - public IReadOnlyList NativeLibraryGroups { get; } - - public IReadOnlyList ResourceAssemblies { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/TargetInfo.cs b/src/Microsoft.Extensions.DependencyModel/TargetInfo.cs deleted file mode 100644 index 56bab154c..000000000 --- a/src/Microsoft.Extensions.DependencyModel/TargetInfo.cs +++ /dev/null @@ -1,34 +0,0 @@ -// 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; } - - } -} \ No newline at end of file diff --git a/src/Microsoft.Extensions.DependencyModel/project.json b/src/Microsoft.Extensions.DependencyModel/project.json deleted file mode 100644 index 41f49ab2f..000000000 --- a/src/Microsoft.Extensions.DependencyModel/project.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "description": "Abstractions for reading `.deps` files.", - "version": "1.0.1-beta-*", - "buildOptions": { - "warningsAsErrors": true, - "keyFile": "../../tools/Key.snk" - }, - "dependencies": { - "Microsoft.DotNet.InternalAbstractions": { - "target": "project" - }, - "Newtonsoft.Json": "9.0.1" - }, - "frameworks": { - "net451": {}, - "netstandard1.3": { - "imports": "portable-net45+wp80+win8+wpa81+dnxcore50", - "dependencies": { - "System.Diagnostics.Debug": "4.0.11", - "System.Dynamic.Runtime": "4.0.11", - "System.Linq": "4.1.0" - } - }, - "netstandard1.6": { - "imports": "portable-net45+wp80+win8+wpa81+dnxcore50", - "dependencies": { - "System.Diagnostics.Debug": "4.0.11", - "System.Dynamic.Runtime": "4.0.11", - "System.Linq": "4.1.0" - } - } - }, - "scripts": {}, - "packOptions": { - "repository": { - "type": "git", - "url": "git://github.com/dotnet/cli" - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/AppBaseResolverTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/AppBaseResolverTests.cs deleted file mode 100644 index c3fd2558e..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/AppBaseResolverTests.cs +++ /dev/null @@ -1,370 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using Microsoft.Extensions.EnvironmentAbstractions; -using Microsoft.Extensions.DependencyModel.Resolution; -using Xunit; -using FluentAssertions; - - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class AppBaseResolverTests - { - private static string BasePath = Path.Combine("Base","Path"); - 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] - public void ResolvesProjectType() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var resolver = CreateResolver(fileSystem); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ProjectType, - assemblies: TestLibraryFactory.EmptyAssemblies); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - Assert.True(result); - } - - [Fact] - public void ResolvesMsBuildProjectType() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var resolver = CreateResolver(fileSystem); - var library = TestLibraryFactory.Create( - TestLibraryFactory.MsBuildProjectType, - assemblies: TestLibraryFactory.EmptyAssemblies); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - Assert.True(result); - } - - [Fact] - public void ResolvesPackageType() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var resolver = CreateResolver(fileSystem); - var library = TestLibraryFactory.Create( - TestLibraryFactory.PackageType, - assemblies: TestLibraryFactory.EmptyAssemblies); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - Assert.True(result); - } - - [Fact] - public void ResolvesReferenceAssemblyType() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var resolver = CreateResolver(fileSystem); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.EmptyAssemblies); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - Assert.True(result); - } - - [Fact] - public void RequiresExistingRefsFolderForNonProjects() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.TwoAssemblies); - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.False(result); - assemblies.Should().HaveCount(0); - } - - [Fact] - public void ResolvesProjectWithoutRefsFolder() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ProjectType, - assemblies: TestLibraryFactory.TwoAssemblies); - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.True(result); - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.DefaultAssembly)); - assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.SecondAssembly)); - } - - [Fact] - public void RequiresAllLibrariesToExist() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly) - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.TwoAssemblies); - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var exception = Assert.Throws(() => resolver.TryResolveAssemblyPaths(library, assemblies)); - exception.Message.Should() - .Contain(BasePath) - .And.Contain(BasePathRefs) - .And.Contain(TestLibraryFactory.SecondAssembly); - } - - [Fact] - public void ResolvesIfAllAreInBaseDir() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly) - .AddFiles(BasePathRefs, "Dummy.dll") - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.TwoAssemblies); - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.True(result); - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.DefaultAssembly)); - assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.SecondAssembly)); - } - - - [Fact] - public void ResolvesIfAllAreInRefDir() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.TwoAssemblies); - - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.True(result); - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.DefaultAssembly)); - assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.SecondAssembly)); - } - - [Fact] - public void ResolvesIfOneInBaseOtherInRefs() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly) - .AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.ReferenceAssemblyType, - assemblies: TestLibraryFactory.TwoAssemblies); - - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.True(result); - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.DefaultAssembly)); - assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.SecondAssembly)); - } - - [Fact] - public void PrefersRefs() - { - var fileSystem = FileSystemMockBuilder - .Create() - .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly) - .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly) - .AddFile(SharedFxPath, TestLibraryFactory.DefaultAssembly) - .AddFile(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly) - .Build(); - var library = TestLibraryFactory.Create( - TestLibraryFactory.PackageType - ); - - var resolver = CreateResolver(fileSystem); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - Assert.True(result); - assemblies.Should().HaveCount(1); - 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(); - 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(); - - 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(); - - 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(); - - 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(); - - Assert.Throws(() => 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(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - Assert.False(result); - } - - private static AppBaseCompilationAssemblyResolver CreateResolver(IFileSystem fileSystem) - { - return new AppBaseCompilationAssemblyResolver(fileSystem, BasePath, DependencyContextPaths); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/CompositeResolverTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/CompositeResolverTests.cs deleted file mode 100644 index eb407f548..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/CompositeResolverTests.cs +++ /dev/null @@ -1,94 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.DependencyModel; -using Microsoft.Extensions.DependencyModel.Resolution; -using Moq; -using Xunit; -using FluentAssertions; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class CompositeResolverTests - { - [Fact] - public void ReturnsFirstSuccesfullResolve() - { - var fail = new Mock(); - var success = new Mock(); - success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>())) - .Returns(true); - - var failTwo = new Mock(); - - var resolvers = new[] - { - fail.Object, - success.Object, - failTwo.Object - }; - - var resolver = new CompositeCompilationAssemblyResolver(resolvers); - var result = resolver.TryResolveAssemblyPaths(null, null); - - Assert.True(result); - - fail.Verify(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>()), - Times.Once()); - success.Verify(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>()), - Times.Once()); - failTwo.Verify(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>()), - Times.Never()); - } - - [Fact] - public void PassesLibraryToAllResolvers() - { - var fail = new Mock(); - var failTwo = new Mock(); - var resolvers = new[] - { - fail.Object, - failTwo.Object - }; - - var library = TestLibraryFactory.Create(); - - var resolver = new CompositeCompilationAssemblyResolver(resolvers); - var result = resolver.TryResolveAssemblyPaths(library, null); - - fail.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once()); - failTwo.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once()); - } - - [Fact] - public void PopulatedAssemblies() - { - var fail = new Mock(); - var success = new Mock(); - success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny(), It.IsAny>())) - .Returns(true) - .Callback((CompilationLibrary l, List a) => - { - a.Add("Assembly"); - }); - - var resolvers = new[] - { - fail.Object, - success.Object - }; - - var assemblies = new List(); - var library = TestLibraryFactory.Create(); - - var resolver = new CompositeCompilationAssemblyResolver(resolvers); - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - assemblies.Should().Contain("Assembly"); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs deleted file mode 100644 index 97e639779..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextBuilderTests.cs +++ /dev/null @@ -1,412 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using FluentAssertions; -using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; -using NuGet.Frameworks; -using NuGet.Versioning; -using Xunit; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class DependencyContextBuilderTests - { - private string _referenceAssembliesPath = Path.Combine("reference", "assemblies"); - private NuGetFramework _defaultFramework; - private string _defaultName = "Library.Name"; - private string _defaultHash = "Hash"; - private NuGetVersion _defaultVersion = new NuGetVersion(1, 2, 3, new []{"dev"}, string.Empty); - - public DependencyContext Build(CommonCompilerOptions compilerOptions = null, - IEnumerable compilationExports = null, - IEnumerable runtimeExports = null, - bool portable = false, - NuGetFramework target = null, - string runtime = null) - { - _defaultFramework = NuGetFramework.Parse("net451"); - return new DependencyContextBuilder(_referenceAssembliesPath).Build( - compilerOptions, - compilationExports ?? new LibraryExport[] { }, - runtimeExports ?? new LibraryExport[] {}, - portable, - target ?? _defaultFramework, - runtime ?? string.Empty); - } - - [Fact] - public void PreservesCompilationOptions() - { - var context = Build(new CommonCompilerOptions() - { - AllowUnsafe = true, - Defines = new[] { "Define", "D" }, - DelaySign = true, - EmitEntryPoint = true, - GenerateXmlDocumentation = true, - KeyFile = "Key.snk", - LanguageVersion = "C#8", - Optimize = true, - Platform = "Platform", - PublicSign = true, - WarningsAsErrors = true - }); - - context.CompilationOptions.AllowUnsafe.Should().Be(true); - context.CompilationOptions.DelaySign.Should().Be(true); - context.CompilationOptions.EmitEntryPoint.Should().Be(true); - context.CompilationOptions.GenerateXmlDocumentation.Should().Be(true); - context.CompilationOptions.Optimize.Should().Be(true); - context.CompilationOptions.PublicSign.Should().Be(true); - context.CompilationOptions.WarningsAsErrors.Should().Be(true); - - context.CompilationOptions.Defines.Should().BeEquivalentTo(new[] { "Define", "D" }); - context.CompilationOptions.KeyFile.Should().Be("Key.snk"); - context.CompilationOptions.LanguageVersion.Should().Be("C#8"); - context.CompilationOptions.Platform.Should().Be("Platform"); - } - - - [Fact] - public void AlowsNullCompilationOptions() - { - var context = Build(compilerOptions: null); - - context.CompilationOptions.Should().Be(CompilationOptions.Default); - } - - [Fact] - public void SetsPortableFlag() - { - var context = Build(portable: true); - - context.Target.IsPortable.Should().BeTrue(); - } - - [Fact] - public void FillsRuntimeAndTarget() - { - var context = Build(target: new NuGetFramework("SomeFramework",new Version(1,2)), runtime: "win8-x86"); - context.Target.Runtime.Should().Be("win8-x86"); - context.Target.Framework.Should().Be("SomeFramework,Version=v1.2"); - } - - [Fact] - public void SetsServiceableToTrueForPackageDescriptions() - { - var context = Build(runtimeExports: new[] - { - Export(PackageDescription("Pack.Age", servicable: false)) - }); - - var lib = context.RuntimeLibraries.Single(); - lib.Serviceable.Should().BeTrue(); - } - - [Fact] - public void TakesServicableFromPackageDescription() - { - var context = Build(runtimeExports: new[] - { - Export(PackageDescription("Pack.Age", servicable: true)) - }); - - var lib = context.RuntimeLibraries.Single(); - lib.Serviceable.Should().BeTrue(); - } - - [Fact] - public void FillsRuntimeLibraryProperties() - { - var context = Build(runtimeExports: new[] - { - Export( - PackageDescription( - "Pack.Age", - servicable: true, - hash: "Hash", - version: new NuGetVersion(1, 2, 3), - dependencies: new[] - { - new LibraryRange("System.Collections", - new VersionRange(new NuGetVersion(2, 1, 2)), - LibraryType.ReferenceAssembly, - LibraryDependencyType.Default) - }), - resourceAssemblies: new[] - { - new LibraryResourceAssembly( - new LibraryAsset("Dll", "en-US/Pack.Age.resources.dll", ""), - "en-US" - ) - }, - runtimeAssemblyGroups: new[] - { - new LibraryAssetGroup( - new LibraryAsset("Dll", "lib/Pack.Age.dll", "")), - new LibraryAssetGroup("win8-x64", - new LibraryAsset("Dll", "win8-x64/Pack.Age.dll", "")) - }, - nativeLibraryGroups: new [] - { - new LibraryAssetGroup("win8-x64", - new LibraryAsset("Dll", "win8-x64/Pack.Age.native.dll", "")) - }), - Export( - ReferenceAssemblyDescription("System.Collections", - version: new NuGetVersion(3, 3, 3)), - runtimeAssemblyGroups: new[] - { - new LibraryAssetGroup( - new LibraryAsset("Dll", "System.Collections.dll", "System.Collections.dll")) - }) - }); - - context.RuntimeLibraries.Should().HaveCount(2); - - var lib = context.RuntimeLibraries.Should().Contain(l => l.Name == "Pack.Age").Subject; - lib.Type.Should().Be("package"); - lib.Serviceable.Should().BeTrue(); - lib.Hash.Should().Be("sha512-Hash"); - lib.Version.Should().Be("1.2.3"); - lib.Dependencies.Should().OnlyContain(l => l.Name == "System.Collections" && l.Version == "3.3.3"); - lib.ResourceAssemblies.Should().OnlyContain(l => l.Path == "en-US/Pack.Age.resources.dll" && l.Locale == "en-US"); - - lib.RuntimeAssemblyGroups.GetDefaultAssets().Should().OnlyContain(l => l == "lib/Pack.Age.dll"); - lib.RuntimeAssemblyGroups.GetRuntimeAssets("win8-x64").Should().OnlyContain(l => l == "win8-x64/Pack.Age.dll"); - lib.NativeLibraryGroups.GetRuntimeAssets("win8-x64").Should().OnlyContain(l => l == "win8-x64/Pack.Age.native.dll"); - - var asm = context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Collections").Subject; - asm.Type.Should().Be("referenceassembly"); - asm.Version.Should().Be("3.3.3"); - asm.Hash.Should().BeEmpty(); - asm.Dependencies.Should().BeEmpty(); - asm.RuntimeAssemblyGroups.GetDefaultAssets().Should().OnlyContain(l => l == "System.Collections.dll"); - } - - [Fact] - public void FiltersDuplicatedDependencies() - { - var context = Build(runtimeExports: new[] - { - Export(PackageDescription("Pack.Age", - dependencies: new[] - { - new LibraryRange("System.Collections", - new VersionRange(new NuGetVersion(2, 0, 0)), - LibraryType.ReferenceAssembly, - LibraryDependencyType.Default), - new LibraryRange("System.Collections", - new VersionRange(new NuGetVersion(2, 1, 2)), - LibraryType.Package, - LibraryDependencyType.Default) - }) - ), - Export(ReferenceAssemblyDescription("System.Collections", - version: new NuGetVersion(2, 0, 0))) - }); - - context.RuntimeLibraries.Should().HaveCount(2); - - var lib = context.RuntimeLibraries.Should().Contain(l => l.Name == "Pack.Age").Subject; - lib.Dependencies.Should().HaveCount(1); - lib.Dependencies.Should().OnlyContain(l => l.Name == "System.Collections" && l.Version == "2.0.0"); - } - - [Fact] - public void FillsCompileLibraryProperties() - { - var context = Build(compilationExports: new[] - { - Export(PackageDescription("Pack.Age", - servicable: true, - hash: "Hash", - version: new NuGetVersion(1, 2, 3), - dependencies: new[] - { - new LibraryRange("System.Collections", - new VersionRange(new NuGetVersion(2, 1, 2)), - LibraryType.ReferenceAssembly, - LibraryDependencyType.Default) - }), - compilationAssemblies: new[] - { - new LibraryAsset("Dll", "lib/Pack.Age.dll", ""), - } - ), - Export(ReferenceAssemblyDescription("System.Collections", - version: new NuGetVersion(3, 3, 3)), - compilationAssemblies: new[] - { - new LibraryAsset("Dll", "", "System.Collections.dll"), - }) - }); - - context.CompileLibraries.Should().HaveCount(2); - - var lib = context.CompileLibraries.Should().Contain(l => l.Name == "Pack.Age").Subject; - lib.Type.Should().Be("package"); - lib.Serviceable.Should().BeTrue(); - lib.Hash.Should().Be("sha512-Hash"); - lib.Version.Should().Be("1.2.3"); - lib.Dependencies.Should().OnlyContain(l => l.Name == "System.Collections" && l.Version == "3.3.3"); - lib.Assemblies.Should().OnlyContain(a => a == "lib/Pack.Age.dll"); - - var asm = context.CompileLibraries.Should().Contain(l => l.Name == "System.Collections").Subject; - asm.Type.Should().Be("referenceassembly"); - asm.Version.Should().Be("3.3.3"); - asm.Hash.Should().BeEmpty(); - asm.Dependencies.Should().BeEmpty(); - asm.Assemblies.Should().OnlyContain(a => a == "System.Collections.dll"); - } - - [Fact] - public void FillsResources() - { - var context = Build(runtimeExports: new[] - { - Export(PackageDescription("Pack.Age", version: new NuGetVersion(1, 2, 3)), - resourceAssemblies: new [] - { - new LibraryResourceAssembly(new LibraryAsset("Dll", "resources/en-US/Pack.Age.dll", ""), "en-US") - }) - }); - - context.RuntimeLibraries.Should().HaveCount(1); - - var lib = context.RuntimeLibraries.Should().Contain(l => l.Name == "Pack.Age").Subject; - lib.ResourceAssemblies.Should().OnlyContain(l => l.Locale == "en-US" && l.Path == "resources/en-US/Pack.Age.dll"); - } - - [Fact] - public void ReferenceAssembliesPathRelativeToDefaultRoot() - { - var context = Build(compilationExports: new[] - { - Export(ReferenceAssemblyDescription("System.Collections", - version: new NuGetVersion(3, 3, 3)), - compilationAssemblies: new[] - { - new LibraryAsset("Dll", "", Path.Combine(_referenceAssembliesPath, "sub", "System.Collections.dll")) - }) - }); - - var asm = context.CompileLibraries.Should().Contain(l => l.Name == "System.Collections").Subject; - asm.Assemblies.Should().OnlyContain(a => a == Path.Combine("sub", "System.Collections.dll")); - } - - [Fact] - public void SkipsBuildDependencies() - { - var context = Build(compilationExports: new[] - { - Export(PackageDescription("Pack.Age", - dependencies: new[] - { - new LibraryRange("System.Collections", - new VersionRange(new NuGetVersion(2, 1, 2)), - LibraryType.ReferenceAssembly, - LibraryDependencyType.Build) - }) - ), - Export(ReferenceAssemblyDescription("System.Collections", - version: new NuGetVersion(3, 3, 3))) - }); - - var lib = context.CompileLibraries.Should().Contain(l => l.Name == "Pack.Age").Subject; - lib.Dependencies.Should().BeEmpty(); - } - - [Fact] - public void GeneratesRuntimeSignatureOutOfPackageNamesAndVersions() - { - var context = Build(runtimeExports: new[] - { - Export(PackageDescription("Pack.Age", new NuGetVersion(1, 2, 3))), - Export(PackageDescription("Pack.Age", new NuGetVersion(1, 2, 3))), - }); - - context.Target.RuntimeSignature.Should().Be("d0fc00006ed69e4aae80383dda08599a6892fd31"); - } - - - private LibraryExport Export( - LibraryDescription description, - IEnumerable compilationAssemblies = null, - IEnumerable runtimeAssemblyGroups = null, - IEnumerable nativeLibraryGroups = null, - IEnumerable resourceAssemblies = null) - { - return LibraryExportBuilder.Create(description) - .WithCompilationAssemblies(compilationAssemblies) - .WithRuntimeAssemblyGroups(runtimeAssemblyGroups) - .WithNativeLibraryGroups(nativeLibraryGroups) - .WithResourceAssemblies(resourceAssemblies) - .Build(); - } - - private PackageDescription PackageDescription( - string name = null, - NuGetVersion version = null, - string hash = null, - IEnumerable dependencies = null, - bool? servicable = null) - { - return new PackageDescription( - "PATH", - new LockFilePackageLibrary() - { - Files = new string[] { }, - IsServiceable = servicable ?? false, - Name = name ?? _defaultName, - Version = version ?? _defaultVersion, - Sha512 = hash ?? _defaultHash - }, - new LockFileTargetLibrary(), - dependencies ?? Enumerable.Empty(), - true, - true); - } - - private ProjectDescription ProjectDescription( - string name = null, - NuGetVersion version = null, - IEnumerable dependencies = null) - { - return new ProjectDescription( - new LibraryRange( - name ?? _defaultName, - new VersionRange(version ?? _defaultVersion), - LibraryType.Project, - LibraryDependencyType.Default - ), - new Project(), - dependencies ?? Enumerable.Empty(), - new TargetFrameworkInformation(), - true); - } - - private LibraryDescription ReferenceAssemblyDescription( - string name = null, - NuGetVersion version = null) - { - return new LibraryDescription( - new LibraryIdentity( - name ?? _defaultName, - version ?? _defaultVersion, - LibraryType.ReferenceAssembly), - string.Empty, // Framework assemblies don't have hashes - "PATH", - Enumerable.Empty(), - _defaultFramework, - true, - true); - } - - - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs deleted file mode 100644 index 6d807ab78..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonReaderTest.cs +++ /dev/null @@ -1,370 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using FluentAssertions; -using Xunit; -using System.Diagnostics; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class DependencyContextJsonReaderTest - { - private DependencyContext Read(string text) - { - using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text))) - { - return new DependencyContextJsonReader().Read(stream); - } - } - - [Fact] - public void ReadsRuntimeTargetInfo() - { - var context = Read( -@"{ - ""runtimeTarget"": { - ""name"":"".NETCoreApp,Version=v1.0/osx.10.10-x64"", - ""signature"":""target-signature"" - }, - ""targets"": { - "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {}, - } -}"); - context.Target.IsPortable.Should().BeFalse(); - context.Target.Framework.Should().Be(".NETCoreApp,Version=v1.0"); - context.Target.Runtime.Should().Be("osx.10.10-x64"); - context.Target.RuntimeSignature.Should().Be("target-signature"); - } - - [Fact] - public void GroupsRuntimeAssets() - { - var context = Read(@" - { - ""targets"": { - "".NETStandard,Version=v1.5"": { - ""System.Banana/1.0.0"": { - ""runtimeTargets"": { - ""runtimes/unix/Banana.dll"": { ""rid"": ""unix"", ""assetType"": ""runtime"" }, - ""runtimes/win7/Banana.dll"": { ""rid"": ""win7"", ""assetType"": ""runtime"" }, - - ""runtimes/native/win7/Apple.dll"": { ""rid"": ""win7"", ""assetType"": ""native"" }, - ""runtimes/native/unix/libapple.so"": { ""rid"": ""unix"", ""assetType"": ""native"" } - } - } - } - }, - ""libraries"": { - ""System.Banana/1.0.0"": { - ""type"": ""package"", - ""serviceable"": false, - ""sha512"": ""HASH-System.Banana"" - }, - } - }"); - context.RuntimeLibraries.Should().HaveCount(1); - var runtimeLib = context.RuntimeLibraries.Single(); - runtimeLib.RuntimeAssemblyGroups.Should().HaveCount(2); - runtimeLib.RuntimeAssemblyGroups.All(g => g.AssetPaths.Count == 1).Should().BeTrue(); - - runtimeLib.NativeLibraryGroups.Should().HaveCount(2); - runtimeLib.NativeLibraryGroups.All(g => g.AssetPaths.Count == 1).Should().BeTrue(); - } - - [Fact] - public void SetsPortableIfRuntimeTargetHasNoRid() - { - var context = Read( -@"{ - ""targets"": { - "".NETCoreApp,Version=v1.0"": {} - } -}"); - context.Target.IsPortable.Should().BeTrue(); - } - - [Fact] - public void SetsNotPortableIfRuntimeTargetHasRid() - { - var context = Read( -@"{ - ""runtimeTarget"": { - ""name"": "".NETCoreApp,Version=v1.0/osx.10.10-x64"" - }, - ""targets"": { - "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {} - } -}"); - context.Target.IsPortable.Should().BeFalse(); - } - - [Fact] - public void ReadsMainTarget() - { - var context = Read( -@"{ - ""targets"": { - "".NETCoreApp,Version=v1.0"": {} - } -}"); - context.Target.Framework.Should().Be(".NETCoreApp,Version=v1.0"); - } - - [Fact] - public void ReadsRuntimeGraph() - { - var context = Read( -@"{ - ""targets"": { - "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {}, - }, - ""runtimes"": { - ""osx.10.10-x64"": [ ], - ""osx.10.11-x64"": [ ""osx"" ], - ""rhel.7-x64"": [ ""linux-x64"", ""unix"" ] - } -}"); - context.RuntimeGraph.Should().Contain(p => p.Runtime == "osx.10.10-x64").Which - .Fallbacks.Should().BeEquivalentTo(); - - context.RuntimeGraph.Should().Contain(p => p.Runtime == "osx.10.11-x64").Which - .Fallbacks.Should().BeEquivalentTo("osx"); - - context.RuntimeGraph.Should().Contain(p => p.Runtime == "rhel.7-x64").Which - .Fallbacks.Should().BeEquivalentTo("linux-x64", "unix"); - } - - [Fact] - public void ReadsCompilationTarget() - { - var context = Read( -@"{ - ""targets"": { - "".NETCoreApp,Version=v1.0"": { - ""MyApp/1.0.1"": { - ""dependencies"": { - ""AspNet.Mvc"": ""1.0.0"" - }, - ""compile"": { - ""MyApp.dll"": { } - } - }, - ""System.Banana/1.0.0"": { - ""dependencies"": { - ""System.Foo"": ""1.0.0"" - }, - ""compile"": { - ""ref/dotnet5.4/System.Banana.dll"": { } - } - } - } - }, - ""libraries"":{ - ""MyApp/1.0.1"": { - ""type"": ""project"" - }, - ""System.Banana/1.0.0"": { - ""type"": ""package"", - ""serviceable"": false, - ""sha512"": ""HASH-System.Banana"" - }, - } -}"); - context.CompileLibraries.Should().HaveCount(2); - var project = context.CompileLibraries.Should().Contain(l => l.Name == "MyApp").Subject; - project.Version.Should().Be("1.0.1"); - project.Assemblies.Should().BeEquivalentTo("MyApp.dll"); - project.Type.Should().Be("project"); - - var package = context.CompileLibraries.Should().Contain(l => l.Name == "System.Banana").Subject; - package.Version.Should().Be("1.0.0"); - package.Assemblies.Should().BeEquivalentTo("ref/dotnet5.4/System.Banana.dll"); - package.Hash.Should().Be("HASH-System.Banana"); - package.Type.Should().Be("package"); - package.Serviceable.Should().Be(false); - } - - [Fact] - public void DoesNotReadRuntimeLibraryFromCompilationOnlyEntries() - { - var context = Read( -@"{ - ""targets"": { - "".NETCoreApp,Version=v1.0"": { - ""MyApp/1.0.1"": { - ""dependencies"": { - ""AspNet.Mvc"": ""1.0.0"" - }, - ""compile"": { - ""MyApp.dll"": { } - } - }, - ""System.Banana/1.0.0"": { - ""dependencies"": { - ""System.Foo"": ""1.0.0"" - }, - ""compileOnly"": true, - ""compile"": { - ""ref/dotnet5.4/System.Banana.dll"": { } - } - } - } - }, - ""libraries"":{ - ""MyApp/1.0.1"": { - ""type"": ""project"" - }, - ""System.Banana/1.0.0"": { - ""type"": ""package"", - ""serviceable"": false, - ""sha512"": ""HASH-System.Banana"" - }, - } -}"); - context.CompileLibraries.Should().HaveCount(2); - context.RuntimeLibraries.Should().HaveCount(1); - context.RuntimeLibraries[0].Name.Should().Be("MyApp"); - } - - - [Fact] - public void ReadsRuntimeLibrariesWithSubtargetsFromMainTargetForPortable() - { - var context = Read( -@"{ - ""runtimeTarget"": { - ""name"": "".NETCoreApp,Version=v1.0"" - }, - ""targets"": { - "".NETCoreApp,Version=v1.0"": { - ""MyApp/1.0.1"": { - ""dependencies"": { - ""AspNet.Mvc"": ""1.0.0"" - }, - ""runtime"": { - ""MyApp.dll"": { } - } - }, - ""System.Banana/1.0.0"": { - ""dependencies"": { - ""System.Foo"": ""1.0.0"" - }, - ""runtime"": { - ""lib/dotnet5.4/System.Banana.dll"": { } - }, - ""runtimeTargets"": { - ""lib/win7/System.Banana.dll"": { ""assetType"": ""runtime"", ""rid"": ""win7-x64""}, - ""lib/win7/Banana.dll"": { ""assetType"": ""native"", ""rid"": ""win7-x64""} - }, - ""resources"": { - ""System.Banana.resources.dll"": { ""locale"": ""en-US"" } - } - } - } - }, - ""libraries"":{ - ""MyApp/1.0.1"": { - ""type"": ""project"", - }, - ""System.Banana/1.0.0"": { - ""type"": ""package"", - ""serviceable"": false, - ""sha512"": ""HASH-System.Banana"" - }, - } -}"); - context.CompileLibraries.Should().HaveCount(2); - var project = context.RuntimeLibraries.Should().Contain(l => l.Name == "MyApp").Subject; - project.Version.Should().Be("1.0.1"); - project.RuntimeAssemblyGroups.GetDefaultAssets().Should().Contain("MyApp.dll"); - project.Type.Should().Be("project"); - - - var package = context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana").Subject; - package.Version.Should().Be("1.0.0"); - package.Hash.Should().Be("HASH-System.Banana"); - package.Type.Should().Be("package"); - package.Serviceable.Should().Be(false); - package.ResourceAssemblies.Should().Contain(a => a.Path == "System.Banana.resources.dll") - .Subject.Locale.Should().Be("en-US"); - - package.RuntimeAssemblyGroups.GetDefaultAssets().Should().Contain("lib/dotnet5.4/System.Banana.dll"); - package.RuntimeAssemblyGroups.GetRuntimeAssets("win7-x64").Should().Contain("lib/win7/System.Banana.dll"); - package.NativeLibraryGroups.GetRuntimeAssets("win7-x64").Should().Contain("lib/win7/Banana.dll"); - } - - [Fact] - public void ReadsRuntimeTargetPlaceholdersAsEmptyGroups() - { - var context = Read( -@"{ - ""runtimeTarget"": { - ""name"": "".NETCoreApp,Version=v1.0"" - }, - ""targets"": { - "".NETCoreApp,Version=v1.0"": { - ""System.Banana/1.0.0"": { - ""runtimeTargets"": { - ""runtime/win7-x64/lib/_._"": { ""assetType"": ""runtime"", ""rid"": ""win7-x64""}, - ""runtime/linux-x64/native/_._"": { ""assetType"": ""native"", ""rid"": ""linux-x64""}, - }, - } - } - }, - ""libraries"":{ - ""System.Banana/1.0.0"": { - ""type"": ""package"", - ""serviceable"": false, - ""sha512"": ""HASH-System.Banana"" - }, - } -}"); - context.CompileLibraries.Should().HaveCount(1); - - var package = context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana").Subject; - - package.RuntimeAssemblyGroups.Should().Contain(g => g.Runtime == "win7-x64") - .Which.AssetPaths.Should().BeEmpty(); - package.NativeLibraryGroups.Should().Contain(g => g.Runtime == "linux-x64") - .Which.AssetPaths.Should().BeEmpty(); - } - - [Fact] - public void ReadsCompilationOptions() - { - var context = Read( -@"{ - ""compilationOptions"": { - ""allowUnsafe"": true, - ""defines"": [""MY"", ""DEFINES""], - ""delaySign"": true, - ""emitEntryPoint"": true, - ""xmlDoc"": true, - ""keyFile"": ""Key.snk"", - ""languageVersion"": ""C#8"", - ""platform"": ""Platform"", - ""publicSign"": true, - ""warningsAsErrors"": true, - ""optimize"": true - }, - ""targets"": { - "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {}, - } -}"); - context.CompilationOptions.AllowUnsafe.Should().Be(true); - context.CompilationOptions.Defines.Should().BeEquivalentTo(new [] {"MY", "DEFINES"}); - context.CompilationOptions.DelaySign.Should().Be(true); - context.CompilationOptions.EmitEntryPoint.Should().Be(true); - context.CompilationOptions.GenerateXmlDocumentation.Should().Be(true); - context.CompilationOptions.KeyFile.Should().Be("Key.snk"); - context.CompilationOptions.LanguageVersion.Should().Be("C#8"); - context.CompilationOptions.Optimize.Should().Be(true); - context.CompilationOptions.Platform.Should().Be("Platform"); - context.CompilationOptions.PublicSign.Should().Be(true); - context.CompilationOptions.WarningsAsErrors.Should().Be(true); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs deleted file mode 100644 index 3b43e5f2a..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextJsonWriterTests.cs +++ /dev/null @@ -1,518 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Xunit; -using FluentAssertions; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class DependencyContextJsonWriterTests - { - public JObject Save(DependencyContext dependencyContext) - { - using (var memoryStream = new MemoryStream()) - { - new DependencyContextWriter().Write(dependencyContext, memoryStream); - using (var readStream = new MemoryStream(memoryStream.ToArray())) - { - using (var textReader = new StreamReader(readStream)) - { - using (var reader = new JsonTextReader(textReader)) - { - return JObject.Load(reader); - } - } - } - } - } - - public DependencyContext Create( - string target = null, - string runtime = null, - bool? isPortable = null, - CompilationOptions compilationOptions = null, - CompilationLibrary[] compileLibraries = null, - RuntimeLibrary[] runtimeLibraries = null, - IReadOnlyList runtimeGraph = null, - string runtimeSignature = null) - { - return new DependencyContext(new TargetInfo( - target ?? "DefaultTarget", - runtime ?? string.Empty, - runtimeSignature ?? string.Empty, - isPortable ?? false), - compilationOptions ?? CompilationOptions.Default, - compileLibraries ?? new CompilationLibrary[0], - runtimeLibraries ?? new RuntimeLibrary[0], - runtimeGraph ?? new RuntimeFallbacks[0] - ); - } - - [Fact] - public void SavesRuntimeGraph() - { - var result = Save(Create( - "Target", - "Target/runtime", - runtimeGraph: new[] - { - new RuntimeFallbacks("win7-x64", new [] { "win6", "win5"}), - new RuntimeFallbacks("win8-x64", new [] { "win7-x64"}), - })); - - var rids = result.Should().HaveProperty("runtimes") - .Subject.Should().BeOfType().Subject; - - rids.Should().HaveProperty("win7-x64") - .Subject.Should().BeOfType() - .Which.Values().ShouldBeEquivalentTo(new[] { "win6", "win5" }); - - rids.Should().HaveProperty("win8-x64") - .Subject.Should().BeOfType() - .Which.Values().ShouldBeEquivalentTo(new[] { "win7-x64" }); - } - - [Fact] - public void WritesRuntimeTargetPropertyIfNotPortable() - { - var result = Save(Create( - "Target", - "runtime", - false, - runtimeSignature: "runtimeSignature") - ); - result.Should().HavePropertyAsObject("runtimeTarget") - .Which.Should().HavePropertyValue("name", "Target/runtime"); - result.Should().HavePropertyAsObject("runtimeTarget") - .Which.Should().HavePropertyValue("signature", "runtimeSignature"); - } - - [Fact] - public void WritesMainTargetNameToRuntimeTargetIfPortable() - { - var result = Save(Create( - "Target", - "runtime", - true, - runtimeSignature: "runtimeSignature") - ); - result.Should().HavePropertyAsObject("runtimeTarget") - .Which.Should().HavePropertyValue("name", "Target"); - result.Should().HavePropertyAsObject("runtimeTarget") - .Which.Should().HavePropertyValue("signature", "runtimeSignature"); - } - - [Fact] - public void WritesCompilationLibraries() - { - var result = Save(Create( - "Target", - "runtime", - true, - compileLibraries: new[] - { - new CompilationLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] {"Banana.dll"}, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ) - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject; - dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0"); - library.Should().HavePropertyAsObject("compile") - .Subject.Should().HaveProperty("Banana.dll"); - - //libraries - var libraries = result.Should().HavePropertyAsObject("libraries").Subject; - library = libraries.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - library.Should().HavePropertyValue("sha512", "HASH"); - library.Should().HavePropertyValue("type", "package"); - library.Should().HavePropertyValue("serviceable", true); - } - - [Fact] - public void WritesRuntimeLibrariesToRuntimeTarget() - { - var result = Save(Create( - "Target", - "runtime", - true, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { - new RuntimeAssetGroup(string.Empty, "Banana.dll"), - new RuntimeAssetGroup("win7-x64", "Banana.Win7-x64.dll") - }, - new [] { - new RuntimeAssetGroup(string.Empty, "runtimes\\linux\\native\\native.so"), - new RuntimeAssetGroup("win7-x64", "native\\Banana.Win7-x64.so") - }, - new [] { new ResourceAssembly("en-US\\Banana.Resource.dll", "en-US")}, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ), - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject; - dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0"); - - library.Should().HavePropertyAsObject("runtime") - .Subject.Should().HaveProperty("Banana.dll"); - library.Should().HavePropertyAsObject("native") - .Subject.Should().HaveProperty("runtimes/linux/native/native.so"); - - var runtimeTargets = library.Should().HavePropertyAsObject("runtimeTargets").Subject; - - var runtimeAssembly = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.dll").Subject; - runtimeAssembly.Should().HavePropertyValue("rid", "win7-x64"); - runtimeAssembly.Should().HavePropertyValue("assetType", "runtime"); - - var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("native/Banana.Win7-x64.so").Subject; - nativeLibrary.Should().HavePropertyValue("rid", "win7-x64"); - nativeLibrary.Should().HavePropertyValue("assetType", "native"); - - var resourceAssemblies = library.Should().HavePropertyAsObject("resources").Subject; - var resourceAssembly = resourceAssemblies.Should().HavePropertyAsObject("en-US/Banana.Resource.dll").Subject; - resourceAssembly.Should().HavePropertyValue("locale", "en-US"); - - //libraries - var libraries = result.Should().HavePropertyAsObject("libraries").Subject; - library = libraries.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - library.Should().HavePropertyValue("sha512", "HASH"); - library.Should().HavePropertyValue("type", "package"); - library.Should().HavePropertyValue("serviceable", true); - } - - [Fact] - public void MergesRuntimeAndCompileLibrariesForPortable() - { - var result = Save(Create( - "Target", - "runtime", - true, - compileLibraries: new[] - { - new CompilationLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { "ref/Banana.dll" }, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ) - }, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { - new RuntimeAssetGroup(string.Empty, "Banana.dll"), - new RuntimeAssetGroup("win7-x64", "Banana.Win7-x64.dll") - }, - new [] { - new RuntimeAssetGroup(string.Empty, "native.dll"), - new RuntimeAssetGroup("win7-x64", "Banana.Win7-x64.so") - }, - new ResourceAssembly[] {}, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ), - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject; - dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0"); - - library.Should().HavePropertyAsObject("runtime") - .Subject.Should().HaveProperty("Banana.dll"); - library.Should().HavePropertyAsObject("native") - .Subject.Should().HaveProperty("native.dll"); - - library.Should().HavePropertyAsObject("compile") - .Subject.Should().HaveProperty("ref/Banana.dll"); - - var runtimeTargets = library.Should().HavePropertyAsObject("runtimeTargets").Subject; - - var runtimeAssembly = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.dll").Subject; - runtimeAssembly.Should().HavePropertyValue("rid", "win7-x64"); - runtimeAssembly.Should().HavePropertyValue("assetType", "runtime"); - - var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.so").Subject; - nativeLibrary.Should().HavePropertyValue("rid", "win7-x64"); - nativeLibrary.Should().HavePropertyValue("assetType", "native"); - - //libraries - var libraries = result.Should().HavePropertyAsObject("libraries").Subject; - library = libraries.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - library.Should().HavePropertyValue("sha512", "HASH"); - library.Should().HavePropertyValue("type", "package"); - library.Should().HavePropertyValue("serviceable", true); - } - - [Fact] - public void WritesRuntimeTargetForNonPortable() - { - var result = Save(Create( - "Target", - "runtime", - false, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { - new RuntimeAssetGroup(string.Empty, "Banana.dll") - }, - new [] { - new RuntimeAssetGroup(string.Empty, "runtimes\\osx\\native\\native.dylib") - }, - new ResourceAssembly[] {}, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ), - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target/runtime").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject; - dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0"); - library.Should().HavePropertyAsObject("runtime") - .Subject.Should().HaveProperty("Banana.dll"); - library.Should().HavePropertyAsObject("native") - .Subject.Should().HaveProperty("runtimes/osx/native/native.dylib"); - - //libraries - var libraries = result.Should().HavePropertyAsObject("libraries").Subject; - library = libraries.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - library.Should().HavePropertyValue("sha512", "HASH"); - library.Should().HavePropertyValue("type", "package"); - library.Should().HavePropertyValue("serviceable", true); - } - - [Fact] - public void WritesPlaceholderRuntimeTargetsForEmptyGroups() - { - var result = Save(Create( - "Target", - "runtime", - true, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { - new RuntimeAssetGroup("win7-x64"), - new RuntimeAssetGroup("win7-x86", "lib\\x86Support.dll") - }, - new [] { - new RuntimeAssetGroup("linux-x64"), - new RuntimeAssetGroup("osx", "native\\OSXSupport.dylib") - }, - new ResourceAssembly[] { }, - new Dependency[] { }, - true - ), - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - - var runtimeTargets = library.Should().HavePropertyAsObject("runtimeTargets").Subject; - - var winPlaceholder = runtimeTargets.Should().HavePropertyAsObject("runtime/win7-x64/lib/_._").Subject; - winPlaceholder.Should().HavePropertyValue("rid", "win7-x64"); - winPlaceholder.Should().HavePropertyValue("assetType", "runtime"); - - var winRuntime = runtimeTargets.Should().HavePropertyAsObject("lib/x86Support.dll").Subject; - winPlaceholder.Should().HavePropertyValue("rid", "win7-x64"); - winPlaceholder.Should().HavePropertyValue("assetType", "runtime"); - - var linuxPlaceholder = runtimeTargets.Should().HavePropertyAsObject("runtime/linux-x64/native/_._").Subject; - linuxPlaceholder.Should().HavePropertyValue("rid", "linux-x64"); - linuxPlaceholder.Should().HavePropertyValue("assetType", "native"); - - var osxNative = runtimeTargets.Should().HavePropertyAsObject("native/OSXSupport.dylib").Subject; - osxNative.Should().HavePropertyValue("rid", "osx"); - osxNative.Should().HavePropertyValue("assetType", "native"); - } - - [Fact] - public void WritesResourceAssembliesForNonPortable() - { - var result = Save(Create( - "Target", - "runtime", - false, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new RuntimeAssetGroup[] { }, - new RuntimeAssetGroup[] { }, - new [] - { - new ResourceAssembly("en-US/Fruits.resources.dll", "en-US") - }, - new Dependency[] { }, - true - ), - })); - - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target/runtime").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var resources = library.Should().HavePropertyAsObject("resources").Subject; - var resource = resources.Should().HavePropertyAsObject("en-US/Fruits.resources.dll").Subject; - resource.Should().HavePropertyValue("locale", "en-US"); - } - - - [Fact] - public void WritesResourceAssembliesForPortable() - { - var result = Save(Create( - "Target", - "runtime", - true, - runtimeLibraries: new[] - { - new RuntimeLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new RuntimeAssetGroup[] { }, - new RuntimeAssetGroup[] { }, - new [] - { - new ResourceAssembly("en-US/Fruits.resources.dll", "en-US") - }, - new Dependency[] { }, - true - ), - })); - - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - var resources = library.Should().HavePropertyAsObject("resources").Subject; - var resource = resources.Should().HavePropertyAsObject("en-US/Fruits.resources.dll").Subject; - resource.Should().HavePropertyValue("locale", "en-US"); - } - - - [Fact] - public void WriteCompilationOnlyAttributeIfOnlyCompilationLibraryProvided() - { - var result = Save(Create( - "Target", - "runtime", - true, - compileLibraries: new[] - { - new CompilationLibrary( - "package", - "PackageName", - "1.2.3", - "HASH", - new [] { "ref/Banana.dll" }, - new [] { - new Dependency("Fruits.Abstract.dll","2.0.0") - }, - true - ) - })); - - // targets - var targets = result.Should().HavePropertyAsObject("targets").Subject; - var target = targets.Should().HavePropertyAsObject("Target").Subject; - var library = target.Should().HavePropertyAsObject("packagename/1.2.3").Subject; - library.Should().HavePropertyValue("compileOnly", true); - } - - - [Fact] - public void WritesCompilationOptions() - { - var result = Save(Create(compilationOptions: new CompilationOptions( - defines: new[] { "MY", "DEFINES" }, - languageVersion: "C#8", - platform: "Platform", - allowUnsafe: true, - warningsAsErrors: true, - optimize: true, - keyFile: "Key.snk", - delaySign: true, - debugType: null, - publicSign: true, - emitEntryPoint: true, - generateXmlDocumentation: true))); - - var options = result.Should().HavePropertyAsObject("compilationOptions").Subject; - options.Should().HavePropertyValue("allowUnsafe", true); - options.Should().HavePropertyValue("delaySign", true); - options.Should().HavePropertyValue("emitEntryPoint", true); - options.Should().HavePropertyValue("xmlDoc", true); - options.Should().HavePropertyValue("publicSign", true); - options.Should().HavePropertyValue("optimize", true); - options.Should().HavePropertyValue("warningsAsErrors", true); - options.Should().HavePropertyValue("allowUnsafe", true); - options.Should().HavePropertyValue("languageVersion", "C#8"); - options.Should().HavePropertyValue("keyFile", "Key.snk"); - options.Should().HaveProperty("defines") - .Subject.Values().Should().BeEquivalentTo(new[] { "MY", "DEFINES" }); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs deleted file mode 100644 index 1c8e07535..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextLoaderTests.cs +++ /dev/null @@ -1,186 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyModel; -using FluentAssertions; -using Xunit; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class DependencyContextLoaderTests - { - [Fact] - public void MergeMergesLibraries() - { - var compilationLibraries = new[] - { - CreateCompilation("PackageA"), - CreateCompilation("PackageB"), - }; - - var runtimeLibraries = new[] - { - CreateRuntime("PackageA"), - CreateRuntime("PackageB"), - }; - - var compilationLibrariesRedist = new[] - { - CreateCompilation("PackageB"), - CreateCompilation("PackageC"), - }; - - var runtimeLibrariesRedist = new[] - { - CreateRuntime("PackageB"), - CreateRuntime("PackageC"), - }; - - var context = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - compilationLibraries, - runtimeLibraries, - new RuntimeFallbacks[] { }); - - var contextRedist = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - compilationLibrariesRedist, - runtimeLibrariesRedist, - new RuntimeFallbacks[] { }); - - var result = context.Merge(contextRedist); - - result.CompileLibraries.Should().BeEquivalentTo(new[] - { - compilationLibraries[0], - compilationLibraries[1], - compilationLibrariesRedist[1], - }); - - result.RuntimeLibraries.Should().BeEquivalentTo(new[] - { - runtimeLibraries[0], - runtimeLibraries[1], - runtimeLibrariesRedist[1], - }); - } - - [Fact] - public void MergeMergesLibrariesWithDifferentCasing() - { - var compilationLibraries = new[] - { - CreateCompilation("PaCkAgEA"), - }; - - var runtimeLibraries = new[] - { - CreateRuntime("PaCkAgEA"), - }; - - var compilationLibrariesRedist = new[] - { - CreateCompilation("PackageA"), - }; - - var runtimeLibrariesRedist = new[] - { - CreateRuntime("PackageA"), - }; - - var context = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - compilationLibraries, - runtimeLibraries, - new RuntimeFallbacks[] { }); - - var contextRedist = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - compilationLibrariesRedist, - runtimeLibrariesRedist, - new RuntimeFallbacks[] { }); - - var result = context.Merge(contextRedist); - - result.CompileLibraries.Should().BeEquivalentTo(new[] - { - compilationLibraries[0] - }); - - result.RuntimeLibraries.Should().BeEquivalentTo(new[] - { - runtimeLibraries[0] - }); - } - - public void MergeMergesRuntimeGraph() - { - var context = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - Enumerable.Empty(), - Enumerable.Empty(), - new RuntimeFallbacks[] - { - new RuntimeFallbacks("win8-x64", new [] { "win8" }), - }); - - var contextRedist = new DependencyContext( - CreateTargetInfo(), - CompilationOptions.Default, - Enumerable.Empty(), - Enumerable.Empty(), - new RuntimeFallbacks[] - { - new RuntimeFallbacks("win8", new [] { "win7-x64", "win7-x86" }), - }); - - var result = context.Merge(contextRedist); - result.RuntimeGraph.Should().Contain(g => g.Runtime == "win8-x64"). - Subject.Fallbacks.Should().BeEquivalentTo("win8"); - result.RuntimeGraph.Should().Contain(g => g.Runtime == "win8"). - Subject.Fallbacks.Should().BeEquivalentTo("win7-x64", "win7-x86"); - } - - private TargetInfo CreateTargetInfo() - { - return new TargetInfo( - "Framework", - "runtime", - "runtimeSignature", - true); - } - - private CompilationLibrary CreateCompilation(string name) - { - return new CompilationLibrary( - "project", - name, - "1.1.1", - "HASH", - new string[] { }, - new Dependency[] { }, - false); - } - - private RuntimeLibrary CreateRuntime(string name) - { - return new RuntimeLibrary( - "project", - name, - "1.1.1", - "HASH", - new RuntimeAssetGroup[] { }, - new RuntimeAssetGroup[] { }, - new ResourceAssembly[] { }, - new Dependency[] {}, - false); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs deleted file mode 100644 index 81927204f..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/DependencyContextTests.cs +++ /dev/null @@ -1,138 +0,0 @@ -using FluentAssertions; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class DependencyContextTests - { - [Theory] - [InlineData("System.Collections.dll", "System.Collections")] - [InlineData("System.Collections.ni.dll", "System.Collections")] - [InlineData("mscorlib", "mscorlib")] - public void GetRuntimeAssemblyNamesExtractsCorrectAssemblyName(string path, string expected) - { - var context = new DependencyContext(new TargetInfo(".NETStandard,Version=v1.3", string.Empty, string.Empty, true), - compilationOptions: CompilationOptions.Default, - compileLibraries: new CompilationLibrary[] { }, - runtimeLibraries: new[] { - new RuntimeLibrary("package", "System.Banana", "1.0.0", "hash", - new [] { - new RuntimeAssetGroup(string.Empty, Path.Combine("lib", path)) - }, - new RuntimeAssetGroup[] { }, - new ResourceAssembly[] { }, - new Dependency[] { }, - serviceable: false) - }, - runtimeGraph: new RuntimeFallbacks[] { }); - - var assets = context.GetDefaultAssemblyNames(); - assets.Should().OnlyContain(a => a.Name == expected); - } - - [Fact] - public void GetRuntimeAssemblyNamesReturnsRIDLessAssetsIfNoRIDSpecificAssetsInLibrary() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeAssemblyNames("win7-x64"); - assets.Should().OnlyContain(a => a.Name == "System.Collections"); - } - - [Fact] - public void GetRuntimeAssemblyNamesReturnsMostSpecificAssetIfRIDSpecificAssetInLibrary() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeAssemblyNames("win81-x64"); - assets.Should().OnlyContain(a => a.Name == "System.Collections"); - } - - [Fact] - public void GetRuntimeAssemblyNamesReturnsEmptyIfEmptyRuntimeGroupPresent() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeAssemblyNames("win10-x64"); - assets.Should().BeEmpty(); - } - - [Fact] - public void GetRuntimeNativeAssetsReturnsEmptyIfNoGroupsMatch() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeNativeAssets("win7-x64"); - assets.Should().BeEmpty(); - } - - [Fact] - public void GetRuntimeNativeAssetsReturnsMostSpecificAssetIfRIDSpecificAssetInLibrary() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeNativeAssets("linux-x64"); - assets.Should().BeEquivalentTo(Path.Combine("runtimes", "linux-x64", "native", "System.Banana.Native.so")); - } - - [Fact] - public void GetRuntimeNativeAssetsReturnsEmptyIfEmptyRuntimeGroupPresent() - { - var context = BuildTestContext(); - - var assets = context.GetRuntimeNativeAssets("rhel-x64"); - assets.Should().BeEmpty(); - } - - private DependencyContext BuildTestContext() - { - return new DependencyContext(new TargetInfo(".NETStandard,Version=v1.3", string.Empty, string.Empty, true), - compilationOptions: CompilationOptions.Default, - compileLibraries: new[] - { - new CompilationLibrary("package", "System.Banana", "1.0.0", "hash", - new [] { Path.Combine("ref", "netstandard1.3", "System.Banana.dll") }, - new Dependency[] { }, - serviceable: false) - }, - runtimeLibraries: new[] { - new RuntimeLibrary("package", "System.Banana", "1.0.0", "hash", - new [] { - new RuntimeAssetGroup(string.Empty, Path.Combine("lib", "netstandard1.3", "System.Collections.dll")), - new RuntimeAssetGroup("win10"), - new RuntimeAssetGroup("win8", Path.Combine("runtimes", "win8", "lib", "netstandard1.3", "System.Collections.dll")) - }, - new [] { - new RuntimeAssetGroup("rhel"), - new RuntimeAssetGroup("linux-x64", Path.Combine("runtimes", "linux-x64", "native", "System.Banana.Native.so")), - new RuntimeAssetGroup("osx-x64", Path.Combine("runtimes", "osx-x64", "native", "System.Banana.Native.dylib")), - - // Just here to test we don't fall back through it for the other cases. There's - // no such thing as a "unix" native asset since there's no common executable format :) - new RuntimeAssetGroup("unix", Path.Combine("runtimes", "osx-x64", "native", "System.Banana.Native")) - }, - new ResourceAssembly[] { }, - new Dependency[] { }, - serviceable: false) - }, - runtimeGraph: new[] { - new RuntimeFallbacks("win10-x64", "win10", "win81-x64", "win81", "win8-x64", "win8", "win7-x64", "win7", "win-x64", "win", "any", "base"), - new RuntimeFallbacks("win81-x64", "win81", "win8-x64", "win8", "win7-x64", "win7", "win-x64", "win", "any", "base"), - new RuntimeFallbacks("win8-x64", "win8", "win7-x64", "win7", "win-x64", "win", "any", "base"), - new RuntimeFallbacks("win7-x64", "win7", "win-x64", "win", "any", "base"), - new RuntimeFallbacks("ubuntu-x64", "ubuntu", "linux-x64", "linux", "unix", "any", "base"), - new RuntimeFallbacks("ubuntu.16.04-x64", "ubuntu", "linux-x64", "linux", "unix", "any", "base"), - new RuntimeFallbacks("rhel-x64", "rhel", "linux-x64", "linux", "unix", "any", "base"), - new RuntimeFallbacks("fedora.23-x64", "fedora", "linux-x64", "linux", "unix", "any", "base"), - new RuntimeFallbacks("opensuse.13.2-x64", "opensuse", "linux-x64", "linux", "unix", "any", "base"), - new RuntimeFallbacks("osx-x64", "osx", "unix", "any", "base"), - }); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/EnvironmentMockBuilder.cs b/test/Microsoft.Extensions.DependencyModel.Tests/EnvironmentMockBuilder.cs deleted file mode 100644 index 55e55065c..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/EnvironmentMockBuilder.cs +++ /dev/null @@ -1,48 +0,0 @@ -// 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.Collections.Generic; -using Microsoft.Extensions.EnvironmentAbstractions; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class EnvironmentMockBuilder - { - private Dictionary _variables = new Dictionary(); - - internal static IEnvironment Empty { get; } = Create().Build(); - - public static EnvironmentMockBuilder Create() - { - return new EnvironmentMockBuilder(); - } - - public EnvironmentMockBuilder AddVariable(string name, string value) - { - _variables.Add(name, value); - return this; - } - - internal IEnvironment Build() - { - return new EnvironmentMock(_variables); - } - - private class EnvironmentMock : IEnvironment - { - private Dictionary _variables; - - public EnvironmentMock(Dictionary variables) - { - _variables = variables; - } - - public string GetEnvironmentVariable(string name) - { - string value = null; - _variables.TryGetValue(name, out value); - return value; - } - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/FunctionalTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/FunctionalTests.cs deleted file mode 100644 index c0e4de7e5..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/FunctionalTests.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.TestFramework; -using Microsoft.DotNet.Tools.Test.Utilities; -using FluentAssertions; -using Xunit; - -namespace Microsoft.Extensions.DependencyModel -{ - public class FunctionalTests : TestBase - { - private readonly string _testProjectsRoot; - - public FunctionalTests() - { - _testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects"); - } - - [Theory] - [InlineData("TestApp", true)] - [InlineData("TestAppPortable", true)] - [InlineData("TestAppDeps", false)] - [InlineData("TestAppPortableDeps", false)] - public void RunTest(string appname, bool checkCompilation) - { - var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", appname); - var testProject = Path.Combine(testProjectPath, "project.json"); - - var runCommand = new RunCommand(testProject); - var result = runCommand.ExecuteWithCapturedOutput(); - result.Should().Pass(); - ValidateRuntimeLibraries(result, appname); - if (checkCompilation) - { - ValidateCompilationLibraries(result, appname); - } - } - - [Theory] - [InlineData("TestApp", false, true)] - [InlineData("TestAppPortable", true, true)] - [InlineData("TestAppDeps", false, false)] - [InlineData("TestAppPortableDeps", true, false)] - public void PublishTest(string appname, bool portable, bool checkCompilation) - { - var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", appname); - var testProject = Path.Combine(testProjectPath, "project.json"); - - var publishCommand = new PublishCommand(testProject); - publishCommand.Execute().Should().Pass(); - - var exeName = portable ? publishCommand.GetPortableOutputName() : publishCommand.GetOutputExecutable(); - - var result = TestExecutable(publishCommand.GetOutputDirectory(portable).FullName, exeName, string.Empty); - ValidateRuntimeLibraries(result, appname); - if (checkCompilation) - { - ValidateCompilationLibraries(result, appname); - } - } - - [WindowsOnlyFact] - public void RunTestFullClr() - { - var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestAppFullClr"); - var testProject = Path.Combine(testProjectPath, "project.json"); - - var runCommand = new RunCommand(testProject); - var result = runCommand.ExecuteWithCapturedOutput(); - result.Should().Pass(); - ValidateRuntimeLibrariesFullClr(result, "TestAppFullClr"); - ValidateCompilationLibrariesFullClr(result, "TestAppFullClr"); - } - - [WindowsOnlyFact] - public void PublishTestFullClr() - { - var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestAppFullClr"); - var testProject = Path.Combine(testProjectPath, "project.json"); - - var publishCommand = new PublishCommand(testProject); - publishCommand.Execute().Should().Pass(); - - var result = TestExecutable(publishCommand.GetOutputDirectory().FullName, publishCommand.GetOutputExecutable(), string.Empty); - ValidateRuntimeLibrariesFullClr(result, "TestAppFullClr"); - ValidateCompilationLibrariesFullClr(result, "TestAppFullClr"); - } - - private void ValidateRuntimeLibrariesFullClr(CommandResult result, string appname) - { - // entry assembly - result.Should().HaveStdOutContaining($"Runtime {appname.ToLowerInvariant()}:{appname}"); - // project dependency - result.Should().HaveStdOutContaining("Runtime dependencycontextvalidator:DependencyContextValidator"); - } - - private void ValidateCompilationLibrariesFullClr(CommandResult result, string appname) - { - // entry assembly - result.Should().HaveStdOutContaining($"Compilation {appname.ToLowerInvariant()}:{appname}.exe"); - // project dependency - result.Should().HaveStdOutContaining("Compilation dependencycontextvalidator:DependencyContextValidator.dll"); - // system assembly - result.Should().HaveStdOutContaining("Compilation mscorlib:mscorlib.dll"); - } - - - private void ValidateRuntimeLibraries(CommandResult result, string appname) - { - // entry assembly - result.Should().HaveStdOutContaining($"Runtime {appname.ToLowerInvariant()}:{appname}"); - // project dependency - result.Should().HaveStdOutContaining("Runtime dependencycontextvalidator:DependencyContextValidator"); - // system assembly - result.Should().HaveStdOutContainingIgnoreCase("Runtime System.Linq:System.Linq"); - } - - private void ValidateCompilationLibraries(CommandResult result, string appname) - { - // entry assembly - result.Should().HaveStdOutContaining($"Compilation {appname.ToLowerInvariant()}:{appname}.dll"); - // project dependency - result.Should().HaveStdOutContaining("Compilation dependencycontextvalidator:DependencyContextValidator.dll"); - // system assembly - result.Should().HaveStdOutContainingIgnoreCase("Compilation System.Linq:System.Linq.dll"); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/JsonAssetions.cs b/test/Microsoft.Extensions.DependencyModel.Tests/JsonAssetions.cs deleted file mode 100644 index 214d0c2dc..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/JsonAssetions.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using FluentAssertions; -using FluentAssertions.Execution; -using FluentAssertions.Primitives; -using Newtonsoft.Json.Linq; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public static class JsonAssertionExtensions - { - public static JsonAssetions Should(this JToken jToken) - { - return new JsonAssetions(jToken); - } - } - - public class JsonAssetions: ReferenceTypeAssertions - { - public JsonAssetions(JToken token) - { - Subject = token; - } - - protected override string Context => nameof(JToken); - - public AndWhichConstraint HaveProperty(string expected) - { - var token = Subject[expected]; - Execute.Assertion - .ForCondition(token != null) - .FailWith($"Expected {Subject} to have property '" + expected + "'"); - - return new AndWhichConstraint(this, token); - } - - public AndConstraint NotHaveProperty(string expected) - { - var token = Subject[expected]; - Execute.Assertion - .ForCondition(token == null) - .FailWith($"Expected {Subject} not to have property '" + expected + "'"); - - return new AndConstraint(this); - } - - public AndWhichConstraint HavePropertyAsObject(string expected) - { - return HaveProperty(expected).Subject.Should().BeOfType(); - } - - public AndConstraint HavePropertyValue(string expected, T value) - { - return HaveProperty(expected).Subject.Value().Should().Be(value); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/Microsoft.Extensions.DependencyModel.Tests.xproj b/test/Microsoft.Extensions.DependencyModel.Tests/Microsoft.Extensions.DependencyModel.Tests.xproj deleted file mode 100644 index f6f7d2856..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/Microsoft.Extensions.DependencyModel.Tests.xproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - 14.0.23107 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 4a4711d8-4312-49fc-87b5-4f183f4c6a51 - Microsoft.Extensions.DependencyModel.Tests - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin - - - 2.0 - - - - - - \ No newline at end of file diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs deleted file mode 100644 index 91735cd6b..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs +++ /dev/null @@ -1,139 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using FluentAssertions; -using Microsoft.Extensions.EnvironmentAbstractions; -using Microsoft.Extensions.DependencyModel.Resolution; -using Xunit; -using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class PackageCacheResolverTest - { - private static string CachePath = Path.Combine("cache", "directory", "location"); - - [Fact] - public void SholdUseEnvironmentVariableToGetDefaultLocation() - { - var result = PackageCacheCompilationAssemblyResolver.GetDefaultPackageCacheDirectory(GetDefaultEnvironment()); - - result.Should().Be(CachePath); - } - - [Fact] - public void SkipsNonPackage() - { - var resolver = new PackageCacheCompilationAssemblyResolver(); - var library = F.Create( - F.PackageType, - assemblies: F.EmptyAssemblies); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - result.Should().BeFalse(); - } - - [Theory] - [InlineData("INVALIDHASHVALUE")] - [InlineData("INVALIDHASHVALUE-")] - [InlineData("-INVALIDHASHVALUE")] - public void FailsOnInvalidHash(string hash) - { - var resolver = new PackageCacheCompilationAssemblyResolver(FileSystemMockBuilder.Empty, CachePath); - var library = F.Create(hash: hash); - - var exception = Assert.Throws(() => resolver.TryResolveAssemblyPaths(library, null)); - exception.Message.Should() - .Contain(library.Hash) - .And.Contain(library.Name); - } - - [Fact] - public void ChecksHashFile() - { - var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); - var fileSystem = FileSystemMockBuilder.Create() - .AddFile( - GetHashFilePath(packagePath), - "WRONGHASH" - ) - .AddFiles(packagePath, F.DefaultAssemblies) - .Build(); - - var resolver = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(F.Create(), assemblies); - result.Should().BeFalse(); - } - - [Fact] - public void ResolvesAllAssemblies() - { - var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); - var fileSystem = FileSystemMockBuilder.Create() - .AddFile( - GetHashFilePath(packagePath), - F.DefaultHashValue - ) - .AddFiles(packagePath, F.TwoAssemblies) - .Build(); - var library = F.Create(assemblies: F.TwoAssemblies); - - var resolver = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath)); - assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath)); - } - - - [Fact] - public void FailsWhenOneOfAssembliesNotFound() - { - var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); - var fileSystem = FileSystemMockBuilder.Create() - .AddFile( - GetHashFilePath(packagePath), - F.DefaultHashValue - ) - .AddFiles(packagePath, F.DefaultAssemblyPath) - .Build(); - var library = F.Create(assemblies: F.TwoAssemblies); - - var resolver = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath); - var assemblies = new List(); - - var exception = Assert.Throws(() => resolver.TryResolveAssemblyPaths(library, assemblies)); - exception.Message.Should() - .Contain(F.SecondAssemblyPath) - .And.Contain(library.Name); - } - - private IEnvironment GetDefaultEnvironment() - { - return EnvironmentMockBuilder.Create() - .AddVariable("DOTNET_PACKAGES_CACHE", CachePath) - .Build(); - } - - private static string GetPackagesPath(string id, string version) - { - return PackageResolverTest.GetPackagesPath(CachePath, id, version); - } - - private static string GetHashFilePath(string packagePath) - { - return Path.Combine( - packagePath, - $"{F.DefaultPackageName.ToLowerInvariant()}.{F.DefaultVersion.ToLowerInvariant()}.nupkg.{F.DefaultHashAlgoritm}"); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs deleted file mode 100644 index dd69f512b..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs +++ /dev/null @@ -1,101 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using FluentAssertions; -using Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.DependencyModel.Resolution; -using Xunit; -using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class PackageResolverTest - { - private static string PackagesPath = Path.Combine("package", "directory", "location"); - - [Fact] - public void ShouldUseEnvironmentVariableToGetDefaultLocation() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("NUGET_PACKAGES", PackagesPath) - .Build(); - - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Unknown, environment); - result.Should().Be(PackagesPath); - } - - - [Fact] - public void ShouldUseNugetUnderUserProfileOnWindows() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("USERPROFILE", "User Profile") - .Build(); - - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Windows, environment); - result.Should().Be(Path.Combine("User Profile", ".nuget", "packages")); - } - - [Fact] - public void ShouldUseNugetUnderHomeOnNonWindows() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("HOME", "User Home") - .Build(); - - var result = PackageCompilationAssemblyResolver.GetDefaultPackageDirectory(Platform.Linux, environment); - result.Should().Be(Path.Combine("User Home", ".nuget", "packages")); - } - - [Fact] - public void ResolvesAllAssemblies() - { - var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(packagePath, F.TwoAssemblies) - .Build(); - var library = F.Create(assemblies: F.TwoAssemblies); - - var resolver = new PackageCompilationAssemblyResolver(fileSystem, PackagesPath); - var assemblies = new List(); - - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - assemblies.Should().HaveCount(2); - assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath)); - assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath)); - } - - - [Fact] - public void FailsWhenOneOfAssembliesNotFound() - { - var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(packagePath, F.DefaultAssemblyPath) - .Build(); - var library = F.Create(assemblies: F.TwoAssemblies); - - var resolver = new PackageCompilationAssemblyResolver(fileSystem, PackagesPath); - var assemblies = new List(); - - var exception = Assert.Throws(() => resolver.TryResolveAssemblyPaths(library, assemblies)); - exception.Message.Should() - .Contain(F.SecondAssemblyPath) - .And.Contain(library.Name); - } - - private static string GetPackagesPath(string id, string version) - { - return GetPackagesPath(PackagesPath, id, version); - } - - internal static string GetPackagesPath(string basePath, string id, string version) - { - return Path.Combine(basePath, id.ToLowerInvariant(), version.ToLowerInvariant()); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs b/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs deleted file mode 100644 index 5895ea994..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/ReferenceAssemblyResolverTests.cs +++ /dev/null @@ -1,142 +0,0 @@ -// 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; -using System.Collections.Generic; -using System.IO; -using FluentAssertions; -using Microsoft.DotNet.InternalAbstractions; -using Microsoft.Extensions.DependencyModel.Resolution; -using Xunit; -using F = Microsoft.Extensions.DependencyModel.Tests.TestLibraryFactory; - - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - public class ReferenceAssemblyResolverTests - { - private static string ReferencePath = Path.Combine("reference", "assembly", "directory", "location"); - - [Fact] - public void SkipsNonReferenceAssembly() - { - var resolver = new ReferenceAssemblyPathResolver(); - var library = F.Create( - F.PackageType); - - var result = resolver.TryResolveAssemblyPaths(library, null); - - result.Should().BeFalse(); - } - - [Fact] - public void UsesEnvironmentVariableForDefaultPath() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("DOTNET_REFERENCE_ASSEMBLIES_PATH", ReferencePath) - .Build(); - - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); - result.Should().Be(ReferencePath); - } - - [Fact] - public void LooksOnlyOnEnvironmentVariableOnNonWindows() - { - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Linux, EnvironmentMockBuilder.Empty); - result.Should().BeNull(); - } - - [Fact] - public void ReturnsProgramFiles86AsDefaultLocationOnWin64() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("ProgramFiles(x86)", "Program Files (x86)") - .AddVariable("ProgramFiles", "Program Files") - .Build(); - - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); - result.Should().Be(Path.Combine("Program Files (x86)", "Reference Assemblies", "Microsoft", "Framework")); - } - - [Fact] - public void ReturnsProgramFilesAsDefaultLocationOnWin32() - { - var environment = EnvironmentMockBuilder.Create() - .AddVariable("ProgramFiles", "Program Files") - .Build(); - - var result = ReferenceAssemblyPathResolver.GetDefaultReferenceAssembliesPath(FileSystemMockBuilder.Empty, Platform.Windows, environment); - result.Should().Be(Path.Combine("Program Files", "Reference Assemblies", "Microsoft", "Framework")); - } - - [Fact] - public void ReturnNet20PathAsFallbackOnWindows() - { - var net20Path = Path.Combine("Windows", "Microsoft.NET", "Framework", "v2.0.50727"); - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(net20Path, "some.dll") - .Build(); - - var environment = EnvironmentMockBuilder.Create() - .AddVariable("WINDIR", "Windows") - .Build(); - - var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, Platform.Windows, environment); - result.Should().Contain(net20Path); - } - - [Fact] - public void ChecksForRelativePathUnderDefaultLocation() - { - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(ReferencePath, F.DefaultAssemblyPath) - .Build(); - - var library = F.Create(libraryType: F.ReferenceAssemblyType); - var assemblies = new List(); - - var resolver = new ReferenceAssemblyPathResolver(fileSystem, ReferencePath, new string[] { }); - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - result.Should().BeTrue(); - assemblies.Should().Contain(Path.Combine(ReferencePath, F.DefaultAssemblyPath)); - } - - [Fact] - public void ChecksForFileNameInFallbackLocation() - { - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(ReferencePath, F.DefaultAssembly) - .Build(); - - var library = F.Create(libraryType: F.ReferenceAssemblyType); - var assemblies = new List(); - - var resolver = new ReferenceAssemblyPathResolver(fileSystem, null, new string[] { ReferencePath }); - var result = resolver.TryResolveAssemblyPaths(library, assemblies); - - result.Should().BeTrue(); - assemblies.Should().Contain(Path.Combine(ReferencePath, F.DefaultAssembly)); - } - - [Fact] - public void ShouldResolveAll() - { - var fileSystem = FileSystemMockBuilder.Create() - .AddFiles(ReferencePath, F.DefaultAssembly) - .Build(); - - var library = F.Create(libraryType: F.ReferenceAssemblyType, assemblies: F.TwoAssemblies); - var assemblies = new List(); - - var resolver = new ReferenceAssemblyPathResolver(fileSystem, null, new string[] { ReferencePath }); - - var exception = Assert.Throws(() => resolver.TryResolveAssemblyPaths(library, assemblies)); - - exception.Message.Should() - .Contain(F.SecondAssemblyPath) - .And.Contain(library.Name); - } - } -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/TestLibraryFactory.cs b/test/Microsoft.Extensions.DependencyModel.Tests/TestLibraryFactory.cs deleted file mode 100644 index a944ed309..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/TestLibraryFactory.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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.IO; - -namespace Microsoft.Extensions.DependencyModel.Tests -{ - static class TestLibraryFactory - { - public static readonly string DefaultType = "package"; - public static readonly string DefaultPackageName = "My.Package"; - public static readonly string DefaultVersion = "1.2.3.7"; - public static readonly Dependency[] DefaultDependencies = { }; - public static readonly bool DefaultServiceable = true; - - public static readonly string DefaultAssembly = "My.Package.dll"; - public static readonly string SecondAssembly = "My.PackageEx.dll"; - public static readonly string DefaultAssemblyPath = Path.Combine("ref", DefaultAssembly); - public static readonly string SecondAssemblyPath = Path.Combine("ref", SecondAssembly); - public static readonly string[] EmptyAssemblies = { }; - public static readonly string[] DefaultAssemblies = { DefaultAssemblyPath }; - public static readonly string[] TwoAssemblies = { DefaultAssemblyPath, SecondAssemblyPath }; - - public static readonly string DefaultHashValue = "HASHVALUE"; - public static readonly string DefaultHashAlgoritm = "ALG"; - public static readonly string DefaultHash = DefaultHashAlgoritm + "-" + DefaultHashValue; - - public static readonly string ProjectType = "project"; - public static readonly string MsBuildProjectType = "msbuildproject"; - public static readonly string ReferenceAssemblyType = "referenceassembly"; - public static readonly string PackageType = "package"; - - public static CompilationLibrary Create( - string libraryType = null, - string packageName = null, - string version = null, - string hash = null, - string[] assemblies = null, - Dependency[] dependencies = null, - bool? serviceable = null) - { - return new CompilationLibrary( - libraryType ?? DefaultType, - packageName ?? DefaultPackageName, - version ?? DefaultVersion, - hash ?? DefaultHash, - assemblies ?? DefaultAssemblies, - dependencies ?? DefaultDependencies, - serviceable ?? DefaultServiceable - ); - } - } - -} diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/project.json b/test/Microsoft.Extensions.DependencyModel.Tests/project.json deleted file mode 100644 index 2a88f7308..000000000 --- a/test/Microsoft.Extensions.DependencyModel.Tests/project.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "Microsoft.DotNet.Tools.Tests.Utilities Class Library", - "buildOptions": { - "keyFile": "../../tools/Key.snk" - }, - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "System.Diagnostics.TraceSource": "4.0.0", - "Microsoft.DotNet.Tools.Tests.Utilities": { - "target": "project" - }, - "Microsoft.DotNet.Cli.Utils": { - "target": "project" - }, - "FluentAssertions": "4.0.0", - "moq.netcore": "4.4.0-beta8", - "xunit": "2.1.0", - "dotnet-test-xunit": "1.0.0-rc2-192208-24" - }, - "frameworks": { - "netcoreapp1.0": { - "imports": [ - "dotnet5.4", - "portable-net451+win8" - ] - } - }, - "testRunner": "xunit" -}