-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Microsoft.Extensions.PlatformAbstractions package split into two
In order to make the transition to the .NET CLI a smooth process we split Microsoft.Extensions.PlatformAbstractions package into two:
Microsoft.Extensions.PlatformAbstractions- API's that would still exist in dotnet cli world:IRuntimeEnvironment,IApplicationEnvironmentMicrosoft.Extensions.PlatformAbstractions.Dnx- API's supported only by DNX:IAssemblyLoaderContainer,IAssemblyLoadContextAccessor,ILibraryManageraccessible usingDnxPlatformServices.Defaultstatic property.
Alternatives
IAssemblyLoadContextAccessormay be replaced by calls toAssebly.Load*on desktop CLR andAssemblyLoadContext.Default.Load*on CoreCLRIAssemblyLoaderContainerloaders may be replaced by implementingAssemblyLoadContexton CoreClr and subscribing toAppDomain.AssemblyResolveevent on desktop CLR.ILibraryManagermay be replaced by:
DependencyContext class from Microsoft.Extensions.DependencyModel shoud be used when you need to access dependencies at runtime and don't have access to project.json or project.lock.json. To use DependencyModel, preserveCompilationContext shoud be set to true in compilerOptions section of project.json which makes build system embed dependency info into assembly being build and copy compilation references on publish.
WorkspaceContext from Microsoft.DotNet.ProjectModel package if you want to operate on project`s source code.
DependencyModel sample
Lets say you want to list all dependencies your entry assembly was compiled against:
project.json
{
"compilationOptions": {
"preserveCompilationContext": true,
"emitEntryPoint": true
},
"dependencies" : {
"Microsoft.Extensions.DependencyModel": "1.0.0-*"
},
"frameworks": {
"net451": {
"frameworkAssemblies":
{
"System.Runtime": {}
}
}
}
}Program.cs
using System;
using Microsoft.Extensions.DependencyModel;
namespace DependencyList
{
public static class Program
{
public static void Main(string[] args)
{
// Default DependencyContext is retrieved from entry assembly
var deps = DependencyContext.Default;
Console.WriteLine($"Compilation depenencies");
foreach (var compilationLibrary in deps.CompileLibraries)
{
Console.WriteLine($"\tPackage {compilationLibrary.PackageName} {compilationLibrary.Version}");
// ResolveReferencePaths returns full paths to compilation assemblies
foreach (var resolveReferencePath in compilationLibrary.ResolveReferencePaths())
{
Console.WriteLine($"\t\tReference path: {resolveReferencePath}");
}
}
Console.WriteLine($"Runtime depenencies");
foreach (var compilationLibrary in deps.RuntimeLibraries)
{
Console.WriteLine($"\tPackage {compilationLibrary.PackageName} {compilationLibrary.Version}");
foreach (var assembly in compilationLibrary.Assemblies)
{
Console.WriteLine($"\t\tReference: {assembly.Name}");
}
}
}
}
}nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="dotnet-cli" value="https://www.myget.org/F/dotnet-cli/api/v3/index.json" />
</packageSources>
</configuration>Output
Compilation depenencies
Package MyTestApp 1.0.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\MyTestApp.exe
Package Microsoft.Extensions.DependencyModel 1.0.0-dev-001134
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\Microsoft.Extensions.DependencyModel.dll
Package Newtonsoft.Json 7.0.1
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\Newtonsoft.Json.dll
Package System.Runtime 4.0.10.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\System.Runtime.dll
Package mscorlib 4.0.0.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\mscorlib.dll
Package System 4.0.0.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\System.dll
Package System.Core 4.0.0.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\System.Core.dll
Package Microsoft.CSharp 4.0.0.0
Reference path: D:\MyTestApp\bin\.dotnetrun\ad9216fd95ff46a8929a709ebc2c170e\Debug\net451\refs\Microsoft.CSharp.dll
Runtime depenencies
Package MyTestApp 1.0.0
Reference: MyTestApp
Package Microsoft.Extensions.DependencyModel 1.0.0-dev-001134
Reference: Microsoft.Extensions.DependencyModel
Package Newtonsoft.Json 7.0.1
Reference: Newtonsoft.Json
Package System.Runtime 4.0.10.0
Package mscorlib 4.0.0.0
Package System 4.0.0.0
Package System.Core 4.0.0.0
Package Microsoft.CSharp 4.0.0.0