I am wondering whether it is possible to change a .NET console application entry point from Main
to Main2
method in the example below:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main");
}
//desired entry point
static void Main2(string[] args)
{
Console.WriteLine("Main2");
}
}
I investigated an IL code of those two. Here is Main
method:
.method private hidebysig static void
Main(
string[] args
) cil managed
{
.entrypoint
.maxstack 8
// other instructions
} // end of method Program::Main
And the Main2
method:
.method private hidebysig static void
Main2(
string[] args
) cil managed
{
.maxstack 8
//other instructions
} // end of method Program::Main2
The only difference is precense of the .entrypoint
instruction in the Main
method, which is - as far as I understand - detected by CLR when application is started.
Is there any way to influence csc
to mark other method with this instruction? Can other compilers do the trick?
EDIT
My question is different from this one, because I am asking about csc
compiler (and other complilers) behavior... specifically how to put the .entrypoint
instruction in the other place
Main2
instead ofMain
? At the moment this feels like an XY problem. – RiproaringToken for the MethodDef or File of the entry point for the image
in the CLI-Header, see ECMA-335 II.25.3.3. As you already have found, the ilasm compiler lets you define the entrypoint using the.entrypoint
directive. II.15.4.1.2 tells you what constraints are present for entrypoints. – Denims