-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
Add support for async main method #1029
Conversation
Thank you for the contribution! Output from the build log:
|
Oops, sorry. I thought I was covered with the .editorconfig and VS. I used tidy.py this time. |
This happens to us whenever we are adding a new file. Seems to be a bug in VS because the templates do not respect the settings in .editorconfig. |
@@ -44,6 +45,11 @@ public static bool IsCompilerGeneratedStateMachine(Mono.Cecil.TypeDefinition typ | |||
return false; | |||
} | |||
|
|||
public static bool IsCompilerGeneratedMainMethod(MethodDefinition method) | |||
{ | |||
return method.Name.Equals("<Main>", StringComparison.Ordinal); |
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.
You should probably check, if the method is the entrypoint as well: method.Module.Assembly?.EntryPoint == method
. Ideally we should check whether the method body matches the Main(args).GetAwaiter().GetResult();
pattern, but I think this is not easily possible in a static context.
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.
Got it, I added the check.
Thank you very much for your contribution to ILSpy! |
Thanks, glad I could help. |
Adds the feature described in #1023
I had a bit of a hard time writing the test since, until now, all tests generated DLLs and we need to generate an EXE to test that the entry point is decompiled correctly. I created a second method called
RunForLibrary()
to replace the old one and set the necessary flags to generate DLLs. This way we can use theRun()
method to create an EXE file.At this point, I don't see any other way to identify the generated method but by its name (see Roslyn). I put the logic to identify the method in the
AsyncAwaitDecompiler
since more checks could be added in the future to distinguish it.