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
Description
When an application references another project with an
EntryPoint(~main method), compilation fails with:Repro code
(create directory for testing:
mkdir tmp && cd tmp)Create first project (in folder
A)Create second project (in folder
B)In
B: Add reference toA(
Because of #2365: Add module to top of
Program.fsin both projects)
Building:
-> all succeed
Expected and actual results
Expected: should compile -- just like the .NET version.
Actual: compilation error (see output above)
Both
Program.fsfiles contain a main method withEntryPointAttribute. I guess Fable directly includes files from the other project -- and has now anEntryPointin 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
Ainto separate project, or define a symbol and put the EntryPointAttribute inside#ifdirective.Related information
dotnet fable --version: 3.1.2dotnet --version: 5.0.102