Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect the runtime/BCL required by an assembly? #8868

Closed
siegfriedpammer opened this issue Sep 4, 2017 · 5 comments
Closed

How to detect the runtime/BCL required by an assembly? #8868

siegfriedpammer opened this issue Sep 4, 2017 · 5 comments
Labels
area-AssemblyLoader-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@siegfriedpammer
Copy link

I am in the process of adding .NET Core/Standard support to ILSpy and I have a few questions:
Side note: we're using Cecil to read assemblies, but it seems basic support for .NET Core/Standard assembly references is still missing. See jbevain/cecil#306.

Detecting the required runtime/BCL in "old" .NET assemblies is straight forward:

  1. Look for a reference called mscorlib.
  2. Find the referenced version in the GAC and load it.

Is there a similar procedure for .NET Core / .NET Standard assemblies?
Is there some meta-data in the assembly header that specifies whether it is plain .NET, .NET Core or .NET Standard?

.NET Core:
Could be identified by System.Runtime references, although you cannot detect the version.

  1. I found that the assemblies are loaded from %ProgramFiles%\dotnet\shared\Microsoft.NETCore.App\<version>
  • Is this the only directory to look for .NET Core Runtime assemblies or is it configurable?
  1. What about nuget packages?
  • I found that there is <project>.runtimeconfig.dev.json and it contains a list of additional paths.
  • What if the json file is missing or does not contain any paths? Is it still possible to load the assembly and resolve its references?

.NET Standard:

  1. There's this netstandard reference and <project>.deps.json
  • How can I resolve all required assemblies from this information?
  • Is this still possible if the json file is missing?
@jkotas
Copy link
Member

jkotas commented Sep 4, 2017

Is this the only directory to look for .NET Core Runtime assemblies or is it configurable?

This is the default location. The shared .NET Core runtime can live anywhere on disk, or it can be in the app directory (self-contained applications - https://docs.microsoft.com/en-us/dotnet/core/deploying/).

What does ILSpy do for Mono? The logic for .NET Core may be similar to Mono.

.NET Standard

.NET Standard does not have any default implementation. The implementation comes from a concrete runtime (.NET Framework, .NET Core or Mono). If ILSpy needs implementation assemblies to work, it needs to pick a runtime compatible with given version of .NET Standard to get them from.

@siegfriedpammer
Copy link
Author

Currently ILSpy does support Mono only through the automated lookup implemented in Mono.Cecil. Actually I've never tried to use ILSpy with Mono, as it only runs on Windows.

I've created a basic implementation of .NET Core/Standard assemblies in icsharpcode/ILSpy#848. It currently implements .NET Standard by loading netstandard.dll from %ProgramFiles%\dotnet\shared\Microsoft.NETCore.App\<version>\, which in turn allows us to resolve all other references.

If there are any details that are missing in my implementation, it would be nice if someone, who knows more about .NET Core/Standard assembly loading, could tell us. Thank you very much!

@0xd4d
Copy link

0xd4d commented Sep 6, 2017

I'd first check all dirs in PATH env var. If dotnet.exe is in one of them, append shared\Microsoft.NETCore.App.

@siegfriedpammer
Copy link
Author

Thanks for your suggestion, I will implement that part soon. Is there any solution to resolving references if *.deps.json is missing?

@jkotas
Copy link
Member

jkotas commented Oct 25, 2017

I cannot think of any.

@jkotas jkotas closed this as completed Oct 25, 2017
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-AssemblyLoader-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

2 participants