diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 94f8b1a93..e988fae47 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -21,8 +21,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.ProjectMod EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testing.Abstractions", "src\Microsoft.Extensions.Testing.Abstractions\Microsoft.Extensions.Testing.Abstractions.xproj", "{DCDFE282-03DE-4DBC-B90C-CC3CE3EC8162}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.ProjectModel.Loader", "src\Microsoft.DotNet.ProjectModel.Loader\Microsoft.DotNet.ProjectModel.Loader.xproj", "{C7AF0290-EF0D-44DC-9EDC-600803B664F8}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{0722D325-24C8-4E83-B5AF-0A083E7F0749}" @@ -113,6 +111,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "shared-build-targets-utils" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "update-dependencies", "build_projects\update-dependencies\update-dependencies.xproj", "{A28BD8AC-DF15-4F58-8299-98A9AE2B8726}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.ProjectModel.Loader", "src\Microsoft.DotNet.ProjectModel.Loader\Microsoft.DotNet.ProjectModel.Loader.xproj", "{1C599FFD-FB52-4279-A8E5-465D3EC499E1}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.ProjectModel.Loader.Tests", "test\Microsoft.DotNet.ProjectModel.Loader.Tests\Microsoft.DotNet.ProjectModel.Loader.Tests.xproj", "{5DF6C9DA-6909-4EC0-909E-6913580BB4A4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -205,22 +207,6 @@ Global {DCDFE282-03DE-4DBC-B90C-CC3CE3EC8162}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {DCDFE282-03DE-4DBC-B90C-CC3CE3EC8162}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {DCDFE282-03DE-4DBC-B90C-CC3CE3EC8162}.RelWithDebInfo|x64.Build.0 = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Debug|x64.ActiveCfg = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Debug|x64.Build.0 = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Release|Any CPU.Build.0 = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Release|x64.ActiveCfg = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.Release|x64.Build.0 = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {C7AF0290-EF0D-44DC-9EDC-600803B664F8}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {08A68C6A-86F6-4ED2-89A7-B166D33E9F85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {08A68C6A-86F6-4ED2-89A7-B166D33E9F85}.Debug|Any CPU.Build.0 = Debug|Any CPU {08A68C6A-86F6-4ED2-89A7-B166D33E9F85}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -813,6 +799,54 @@ Global {A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {A28BD8AC-DF15-4F58-8299-98A9AE2B8726}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|x64.ActiveCfg = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Debug|x64.Build.0 = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|Any CPU.Build.0 = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|x64.ActiveCfg = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.Release|x64.Build.0 = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {1DBB7542-0345-4F4B-A84B-3B00B185D416}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|x64.ActiveCfg = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Debug|x64.Build.0 = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Release|Any CPU.Build.0 = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Release|x64.ActiveCfg = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.Release|x64.Build.0 = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {1C599FFD-FB52-4279-A8E5-465D3EC499E1}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Debug|x64.ActiveCfg = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Debug|x64.Build.0 = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Release|Any CPU.Build.0 = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Release|x64.ActiveCfg = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.Release|x64.Build.0 = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4}.RelWithDebInfo|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -823,7 +857,6 @@ Global {A16958E1-24C7-4F1E-B317-204AD91625DD} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {BD7833F8-3209-4682-BF75-B4BCA883E279} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {DCDFE282-03DE-4DBC-B90C-CC3CE3EC8162} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} - {C7AF0290-EF0D-44DC-9EDC-600803B664F8} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {08A68C6A-86F6-4ED2-89A7-B166D33E9F85} = {0722D325-24C8-4E83-B5AF-0A083E7F0749} {688870C8-9843-4F9E-8576-D39290AD0F25} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {65741CB1-8AEE-4C66-8198-10A7EA0E4258} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} @@ -866,5 +899,8 @@ Global {49BEB486-AB5A-4416-91EA-8CD34ABB0C9D} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} {B768BD29-12BF-4C7C-B093-03193FE244D1} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} {A28BD8AC-DF15-4F58-8299-98A9AE2B8726} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} + {1DBB7542-0345-4F4B-A84B-3B00B185D416} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} + {1C599FFD-FB52-4279-A8E5-465D3EC499E1} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} + {5DF6C9DA-6909-4EC0-909E-6913580BB4A4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection EndGlobal diff --git a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs index 3b5a088e1..cd83437aa 100644 --- a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs @@ -7,14 +7,19 @@ namespace TestProjectWithCultureSpecificResource { public class Program { - public static void Main(string[] args) + // This method is consumed by load context tests + public static string GetMessage() { var rm = new ResourceManager( "TestProjectWithCultureSpecificResource.Strings", typeof(Program).GetTypeInfo().Assembly); - Console.WriteLine(rm.GetString("hello")); - Console.WriteLine(rm.GetString("hello", new CultureInfo("fr"))); + return rm.GetString("hello") + Environment.NewLine + rm.GetString("hello", new CultureInfo("fr")); + } + + public static void Main(string[] args) + { + Console.WriteLine(GetMessage()); } } } diff --git a/src/Microsoft.DotNet.ProjectModel.Loader/LoaderProjectContextExtensions.cs b/src/Microsoft.DotNet.ProjectModel.Loader/LoaderProjectContextExtensions.cs index b51841d79..401492aae 100644 --- a/src/Microsoft.DotNet.ProjectModel.Loader/LoaderProjectContextExtensions.cs +++ b/src/Microsoft.DotNet.ProjectModel.Loader/LoaderProjectContextExtensions.cs @@ -3,47 +3,99 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.Loader; +using Microsoft.DotNet.ProjectModel.Compilation; +using Microsoft.Extensions.DependencyModel; namespace Microsoft.DotNet.ProjectModel.Loader { public static class LoaderProjectContextExtensions { public static AssemblyLoadContext CreateLoadContext( - this ProjectContext context, - string configuration = "Debug", - string outputPath = null) + this ProjectContext context, + string configuration) => CreateLoadContext(context, context.RuntimeIdentifier, configuration); + + public static AssemblyLoadContext CreateLoadContext( + this ProjectContext context, + string runtimeIdentifier, + string configuration) => CreateLoadContext(context, runtimeIdentifier, configuration); + + public static AssemblyLoadContext CreateLoadContext( + this ProjectContext context, + string runtimeIdentifier, + string configuration, + string outputPath) { var exporter = context.CreateExporter(configuration); var assemblies = new Dictionary(AssemblyNameComparer.OrdinalIgnoreCase); - var dllImports = new Dictionary(); + var nativeLibs = new Dictionary(); + var rids = DependencyContext.Default?.RuntimeGraph ?? Enumerable.Empty(); + var fallbacks = rids.FirstOrDefault(r => r.Runtime.Equals(runtimeIdentifier)); foreach (var export in exporter.GetAllExports()) { - // TODO: Handle resource assemblies - foreach (var asset in export.RuntimeAssemblyGroups.GetDefaultAssets()) + // Process managed assets + var group = string.IsNullOrEmpty(runtimeIdentifier) ? + export.RuntimeAssemblyGroups.GetDefaultGroup() : + GetGroup(export.RuntimeAssemblyGroups, runtimeIdentifier, fallbacks); + if(group != null) { - // REVIEW: Should we use the following? - // AssemblyLoadContext.GetAssemblyName(asset.ResolvedPath); - var assemblyName = new AssemblyName(asset.Name); - assemblies[assemblyName] = asset.ResolvedPath; + foreach(var asset in group.Assets) + { + assemblies[asset.GetAssemblyName()] = asset.ResolvedPath; + } } - foreach (var asset in export.NativeLibraryGroups.GetDefaultAssets()) + // Process native assets + group = string.IsNullOrEmpty(runtimeIdentifier) ? + export.NativeLibraryGroups.GetDefaultGroup() : + GetGroup(export.NativeLibraryGroups, runtimeIdentifier, fallbacks); + if(group != null) { - dllImports[asset.Name] = asset.ResolvedPath; + foreach(var asset in group.Assets) + { + nativeLibs[asset.Name] = asset.ResolvedPath; + } + } + + // Process resource assets + foreach(var asset in export.ResourceAssemblies) + { + var name = asset.Asset.GetAssemblyName(); + name.CultureName = asset.Locale; + assemblies[name] = asset.Asset.ResolvedPath; } } return new ProjectLoadContext( assemblies, - dllImports, + nativeLibs, // Add the project's output directory path to ensure project-to-project references get located new[] { context.GetOutputPaths(configuration, outputPath: outputPath).CompilationOutputPath }); } + private static LibraryAssetGroup GetGroup(IEnumerable groups, string runtimeIdentifier, RuntimeFallbacks fallbacks) + { + IEnumerable rids = new[] { runtimeIdentifier }; + if(fallbacks != null) + { + rids = Enumerable.Concat(rids, fallbacks.Fallbacks); + } + + foreach(var rid in rids) + { + var group = groups.GetRuntimeGroup(rid); + if(group != null) + { + return group; + } + } + return null; + } + private class AssemblyNameComparer : IEqualityComparer { public static readonly IEqualityComparer OrdinalIgnoreCase = new AssemblyNameComparer(); diff --git a/src/Microsoft.DotNet.ProjectModel.Loader/Microsoft.DotNet.ProjectModel.Loader.xproj b/src/Microsoft.DotNet.ProjectModel.Loader/Microsoft.DotNet.ProjectModel.Loader.xproj index 049c639a2..95b2a8b7f 100644 --- a/src/Microsoft.DotNet.ProjectModel.Loader/Microsoft.DotNet.ProjectModel.Loader.xproj +++ b/src/Microsoft.DotNet.ProjectModel.Loader/Microsoft.DotNet.ProjectModel.Loader.xproj @@ -6,12 +6,11 @@ - c7af0290-ef0d-44dc-9edc-600803b664f8 + 1c599ffd-fb52-4279-a8e5-465d3ec499e1 Microsoft.DotNet.ProjectModel.Loader ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin - 2.0 diff --git a/src/Microsoft.DotNet.ProjectModel.Loader/ProjectLoadContext.cs b/src/Microsoft.DotNet.ProjectModel.Loader/ProjectLoadContext.cs index 44418b167..fa92273b6 100644 --- a/src/Microsoft.DotNet.ProjectModel.Loader/ProjectLoadContext.cs +++ b/src/Microsoft.DotNet.ProjectModel.Loader/ProjectLoadContext.cs @@ -50,8 +50,8 @@ namespace Microsoft.DotNet.ProjectModel.Loader } public ProjectLoadContext(IDictionary assemblyPaths, - IDictionary nativeLibraries, - IEnumerable searchPaths) + IDictionary nativeLibraries, + IEnumerable searchPaths) { _assemblyPaths = assemblyPaths; _nativeLibraries = nativeLibraries; diff --git a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryAssetExtension.cs b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryAssetExtension.cs index 93b466639..534a114a2 100644 --- a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryAssetExtension.cs +++ b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryAssetExtension.cs @@ -1,12 +1,27 @@ // 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.IO; +using System.Reflection; namespace Microsoft.DotNet.ProjectModel.Compilation { public static class LibraryAssetExtensions { + private const string NativeImageSufix = ".ni"; + + public static AssemblyName GetAssemblyName(this LibraryAsset asset) + { + var name = asset.Name; + if (asset.Name.EndsWith(NativeImageSufix)) + { + name = name.Substring(0, name.Length - NativeImageSufix.Length); + } + + return new AssemblyName(name); + } + public static string GetTransformedFile(this LibraryAsset asset, string tempLocation, string tempName = null) { if (asset.Transform == null) diff --git a/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Microsoft.DotNet.ProjectModel.Loader.Tests.xproj b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Microsoft.DotNet.ProjectModel.Loader.Tests.xproj new file mode 100644 index 000000000..c0cd383ea --- /dev/null +++ b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Microsoft.DotNet.ProjectModel.Loader.Tests.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 5df6c9da-6909-4ec0-909e-6913580bb4a4 + Microsoft.DotNet.ProjectModel.Loader.Tests + .\obj + .\bin\ + v4.6.1 + + + + 2.0 + + + diff --git a/test/Microsoft.DotNet.ProjectModel.Loader.Tests/ProjectLoadContextTest.cs b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/ProjectLoadContextTest.cs new file mode 100644 index 000000000..1e3c562ea --- /dev/null +++ b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/ProjectLoadContextTest.cs @@ -0,0 +1,33 @@ +using System; +using System.Reflection; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.Extensions.DependencyModel; +using NuGet.Frameworks; +using Xunit; + +namespace Microsoft.DotNet.ProjectModel.Loader.Tests +{ + public class ProjectLoadContextTest : TestBase + { + [Fact] + public void LoadContextCanLoadProjectOutput() + { + var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithResource") + .WithLockFiles() + .WithBuildArtifacts(); + + var rid = DependencyContext.Default.Target.Runtime; + + var context = ProjectContext.Create(testInstance.TestRoot, NuGetFramework.Parse("netcoreapp1.0"), new[] { rid }); + var loadContext = context.CreateLoadContext(rid, Constants.DefaultConfiguration); + + // Load the project assembly + var asm = loadContext.LoadFromAssemblyName(new AssemblyName("TestProjectWithResource")); + + // Call Program.GetMessage() and assert the output + var message = (string)asm.GetType("TestProjectWithCultureSpecificResource").GetRuntimeMethod("GetMessage", Type.EmptyTypes).Invoke(null, new object[0]); + Assert.Equal("Hello World!" + Environment.NewLine + "Bonjour!", message); + } + } +} diff --git a/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Properties/AssemblyInfo.cs b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..d78c5952d --- /dev/null +++ b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Microsoft.DotNet.ProjectModel.Loader.Tests")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5df6c9da-6909-4ec0-909e-6913580bb4a4")] diff --git a/test/Microsoft.DotNet.ProjectModel.Loader.Tests/project.json b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/project.json new file mode 100644 index 000000000..8dae662a6 --- /dev/null +++ b/test/Microsoft.DotNet.ProjectModel.Loader.Tests/project.json @@ -0,0 +1,29 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "keyFile": "../../tools/test_key.snk" + }, + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0-rc3-004363" + }, + "Microsoft.DotNet.ProjectModel.Loader": { + "target": "project" + }, + "Microsoft.DotNet.Tools.Tests.Utilities": { + "target": "project" + }, + "xunit": "2.1.0", + "dotnet-test-xunit": "1.0.0-rc2-192208-24" + }, + "frameworks": { + "netcoreapp1.0": { + "imports": [ + "dotnet5.4", + "portable-net451+win8" + ] + } + }, + "testRunner": "xunit" +}