diff --git a/src/Compiler/AbstractIL/ilwrite.fs b/src/Compiler/AbstractIL/ilwrite.fs index 983159604c2..80bb791c25f 100644 --- a/src/Compiler/AbstractIL/ilwrite.fs +++ b/src/Compiler/AbstractIL/ilwrite.fs @@ -1154,7 +1154,7 @@ let canGenMethodDef (tdef: ILTypeDef) cenv (mdef: ILMethodDef) = | ILMemberAccess.Public -> true // When emitting a reference assembly, do not emit methods that are private/protected/internal unless they are virtual/abstract or provide an explicit interface implementation. | ILMemberAccess.Private | ILMemberAccess.Family | ILMemberAccess.Assembly | ILMemberAccess.FamilyOrAssembly - when mdef.IsVirtual || mdef.IsAbstract || mdef.IsNewSlot || mdef.IsFinal -> true + when mdef.IsVirtual || mdef.IsAbstract || mdef.IsNewSlot || mdef.IsFinal || mdef.IsEntryPoint -> true // When emitting a reference assembly, only generate internal methods if the assembly contains a System.Runtime.CompilerServices.InternalsVisibleToAttribute. | ILMemberAccess.FamilyOrAssembly | ILMemberAccess.Assembly when cenv.hasInternalsVisibleToAttrib -> true diff --git a/tests/fsharp/Compiler/CodeGen/EmittedIL/ReferenceAssemblyTests.fs b/tests/fsharp/Compiler/CodeGen/EmittedIL/ReferenceAssemblyTests.fs index 8ed8ef5cb9c..9020c5d85e3 100644 --- a/tests/fsharp/Compiler/CodeGen/EmittedIL/ReferenceAssemblyTests.fs +++ b/tests/fsharp/Compiler/CodeGen/EmittedIL/ReferenceAssemblyTests.fs @@ -982,4 +982,35 @@ extends [runtime]System.Object } } """ ] + + [] + let ``Build .exe with --refonly ensure it produces a main in the ref assembly`` () = + FSharp """module ReferenceAssembly +open System + +Console.WriteLine("Hello World!")""" + |> withOptions ["--refonly"] + |> withName "HasMainCheck" + |> asExe + |> compile + |> shouldSucceed + |> verifyIL [ + referenceAssemblyAttributeExpectedIL + """.class private abstract auto ansi sealed ''.$ReferenceAssembly + extends [mscorlib]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldnull + IL_0001: throw + } // end of method $ReferenceAssembly::main@ + +} // end of class ''.$ReferenceAssembly +""" + ] + |> ignore + // TODO: Add tests for internal functions, types, interfaces, abstract types (with and without IVTs), (private, internal, public) fields, properties (+ different visibility for getters and setters), events.