-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Find implementation assemblies for reference assemblies in the .NET SDK #61526
Conversation
There are two parts to this: 1. A heuristic approach to finding implementation DLLs from the dotnet\shared folder, when a symbol comes from a reference DLL in the dotnet\packs folder. This works for things like System.Console, whose reference comes from System.Console.dll, and implementation is in the corresponding System.Console.dll in the shared folder 2. Loading implementation DLLs and following the type forwarding chain to the correct assembly for types that have been forwarded. This works for things like System.Attribute, which is in reference assembly System.Runtime.dll, but the implementation assembly System.Runtime.dll forwards the type to System.Private.CoreLib.dll
This is one of those situations where I've been fighting code for 2 days, but now it's 10 minutes before dinner time and so I hastily put up a PR to get a dopamine hit. All of that is to say don't be surprised if there is a glaring mistake. I also fully expect @tmat to tell me to just call the magical |
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/MetadataAsSource/MetadataAsSourceHelpers.cs
Outdated
Show resolved
Hide resolved
/// Uses various heuristics to try to find the implementation assembly for a reference assembly without | ||
/// loading | ||
/// </summary> | ||
public static bool TryFindImplementationAssemblyPath(string referencedDllPath, [NotNullWhen(true)] out string? implementationDllPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not ¯\_(ツ)_/¯
Though I wouldn't expect much difference. This only reads one XML file, and only the first line of that file. In fact, reading a file that is just <FileList FrameworkName="MyPack">
doesn't even throw an XmlException, because it doesn't read far enough to determine that it's invalid :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually.. because of the out parameter, this is a bit annoying. Is it really going to make any meaningful difference? Only the Read()
call becomes ReadAsync()
, there is nothing else that is async.
Reviewed iteration 3. |
Apologies for the diff, but I extracted some code from |
@tmat this is ready for another look. Will fix the other scenarios in follow ups, so this doesn't get too crowded. |
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/ImplementationAssemblyLookupService.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs
Outdated
Show resolved
Hide resolved
src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
{ | ||
// If there are no type forwards in this DLL, or not one for this type, then it means | ||
// we've found the right DLL | ||
if (typeForwards?.TryGetValue((typeSymbol.ContainingNamespace.MetadataName, typeSymbol.MetadataName), out var assemblyName) is null or false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/Features/Core/Portable/FeaturesResources.resx
@tmat anything else for this one? (other than fixing conflicts :P) |
# Conflicts: # src/Features/Core/Portable/MetadataAsSource/DecompilationMetadataAsSourceFileProvider.cs # src/Features/Core/Portable/PdbSourceDocument/PdbSourceDocumentMetadataAsSourceFileProvider.cs
Part of #55834
This makes Source Link work for projects targeting .NET 6 if a matching runtime is installed for the targeted SDK. It does cool things like this:
Still to do:
@tmat PTAL
FYI @chuckries @caslan @mikadumont