Emit a warning when referencing console applications exe's without a main
Create a solution with two Console Application projects:
ConsoleApplication1\Program.fs:
module SharedValue
let hello = "Hello" |> id
ConsoleApplication2\Program.fs (references ConsoleApplication1)
match SharedValue.hello with
| null -> printfn "SharedValue.hello is null!"
| _ -> printfn "all good"
Expected output: all good
Actual output: SharedValue.hello is null!
needless to say, getting a null value from an F# project is quite surprising.
Changing the type of ConsoleApplication1 to a Library fixes this.
i think is the same problem as fsharp/fsharp#326 , the console project doesn't initialize hello because you dont declare/execute the main function.
see @latkin 's comment for detailed explaination and workaround
@latkin @dsyme we need to add a warning? with c# you can reference the console app without problem, so is a bit unintuitive/annoying
Yrs, an explicit Main is required, and this is currently considered by design, for better or worse.
Adding a warning on referencing such a component may well be feasible.
What's best?
- warning (error?) if a console app doesnt have a main
- warning if a referenced fsharp assembly (discriminate on .exe extension?) doesn't have a main
#2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced
#2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced