Skip to content

Compile Error when referencing another project with EntryPoint #2366

Description

@Booksbaum

Description

When an application references another project with an EntryPoint (~main method), compilation fails with:

[...]/A/Program.fs(11,5): (11,9) error FSHARP: A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence. (code 433)

Repro code

(create directory for testing: mkdir tmp && cd tmp)

Create first project (in folder A)

dotnet new console -lang f# --output ./A

Create second project (in folder B)

dotnet new console -lang f# --output ./B

In B: Add reference to A

dotnet add ./B reference ./A

(
Because of #2365: Add module to top of Program.fs in both projects

@("module A") + (Get-Content .\A\Program.fs) | Out-File .\A\Program.fs
@("module B") + (Get-Content .\B\Program.fs) | Out-File .\B\Program.fs

)

Building:

dotnet build ./A
dotnet build ./B
dotnet fable ./A

-> all succeed

dotnet fable ./B

Fable: F# to JS compiler 3.1.2
Thanks to the contributor! @halfabench
B> cmd /C dotnet restore B.fsproj
  Determining projects to restore...
  All projects are up-to-date for restore.
Parsing B\B.fsproj...
Initializing F# compiler...
Compiling B\B.fsproj...
F# compilation finished in 1252ms
[...]/tmp/A/Program.fs(11,5): (11,9) error FSHARP: A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence. (code 433)
Compilation failed

Expected and actual results

Expected: should compile -- just like the .NET version.

Actual: compilation error (see output above)

Both Program.fs files contain a main method with EntryPointAttribute. I guess Fable directly includes files from the other project -- and has now an EntryPoint in another place than the last file.

Probably doesn't happen very often in practice (but emerges in ts2fable), and quite easy to handle: extract main method of A into separate project, or define a symbol and put the EntryPointAttribute inside #if directive.

Related information

  • Fable version: dotnet fable --version: 3.1.2
  • Dotnet version: dotnet --version: 5.0.102

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions