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

Update ICSharpCode.Decompiler to 4.0-beta1 #29029

Merged
merged 5 commits into from
Aug 2, 2018

Conversation

siegfriedpammer
Copy link
Contributor

@siegfriedpammer siegfriedpammer commented Aug 2, 2018

This pull request updates the ILSpy decompiler integration to version 4.0-beta1, which uses System.Reflection.Metadata instead of Mono.Cecil for reading .NET metadata tables.

It also includes a fix for bad decompilation results in .NET Standard/Core projects (You can see the effects of missing references in this video).

Points open for discussion (maybe create issues?):

  • The decompiler is able to work with existing Stream or PEReader instances. We should pass either the Stream or SRM PEReader used by Roslyn to the decompiler to avoid loading referenced assemblies again just for decompilation.

@sharwell feel free to rebase the pull request to any other branch you think this change should go to. 😃

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small notes about comments but overall a welcome change


// Initialize a decompiler with default settings.
var decompiler = new CSharpDecompiler(assemblyDefinition.MainModule, new DecompilerSettings());
// TODO: Use language version currently used by the project.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This won't be necessary. As #24349 progresses and we favor the original source over decompiled source in more cases, the language version shown for these files will naturally vary from the current project. I don't want to define the Navigate to Decompiled Source in such a way that users expect the language version to match the current project because it will lead to questions/bugs about mismatched versions down the road.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine... it was just an idea I had this morning... 😃 I will remove this comment.

@@ -224,10 +225,13 @@ private string GetRootPathWithGuid_NoLock()
}

// Load the assembly.
var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyLocation, new ReaderParameters() { AssemblyResolver = new RoslynAssemblyResolver(compilation) });
// TODO: Use a different PEFile ctor overload that allows us to reuse the PEReader or Stream already created by Roslyn.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ These comments are best removed before merge, and follow-up issues filed for them. The follow-up issues can be created before or after merging the pull request, but when you remove the TODO comments you should either create the issues directly or add comments to the pull request with information necessary to create the issues (so we don't lose the info). 😄

Copy link
Contributor Author

@siegfriedpammer siegfriedpammer Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will have to always load the assembly being decompiled from disk, because Roslyn will load them in "metadata-only mode" I guess.

As for the other references, could you tell me how to access the PEReader or Stream used by Roslyn? Thanks!
I would be glad to implement this correctly right from the start.

@sharwell
Copy link
Member

sharwell commented Aug 2, 2018

@siegfriedpammer It looks like the Mono.Cecil dependency needs to be removed at the same time due to the build validation. Do you mind if I add a commit to your pull request branch with the necessary change?

@siegfriedpammer
Copy link
Contributor Author

I don't mind at all! 😄 Please go ahead. Thanks!

@sharwell
Copy link
Member

sharwell commented Aug 2, 2018

@siegfriedpammer Done! Hopefully that fixes the build.

@siegfriedpammer
Copy link
Contributor Author

I removed all TODO comments and added a summary to the PR description. Is there anything else to do?

@sharwell sharwell added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Aug 2, 2018
@sharwell sharwell added this to the 16.0 milestone Aug 2, 2018
@sharwell sharwell self-assigned this Aug 2, 2018

// Initialize a decompiler with default settings.
var decompiler = new CSharpDecompiler(assemblyDefinition.MainModule, new DecompilerSettings());
var settings = new DecompilerSettings(LanguageVersion.Latest);
var decompiler = new CSharpDecompiler(pefile, new RoslynAssemblyResolver(compilation), settings);
// Escape invalid identifiers to prevent Roslyn from failing to parse the generated code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line between comment and the var decompiler = … line.

@sharwell sharwell merged commit 1cd08cc into dotnet:master Aug 2, 2018
@siegfriedpammer siegfriedpammer deleted the decompiler-v4 branch November 3, 2019 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants