Skip to content

GitVersionTask does not work correctly with fsharp projects building an exe. #1831

@da9l

Description

@da9l

When adding the GitVersionTask to a fsharp fsproj that build an exe one get this error message when running dotnet build

C:\Users\...\repos\reproducegvdn\Program.fs(3,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration. [C:\Users\...\repos\reproducegvdn\reproducegvdn.fsproj]

My best guess is that the generated GitVersionInformation.fs file is placed last in the list of files to compile. The Program.fs containing the decorated main function must always be last. See below for details.

Shortest steps to reproduce:

md reproducebug
cd reproducebug
dotnet new console -lang f#
dotnet add package gitversiontask
git init
git add -A
git commit -m "Initial commit"
dotnet build

If one run with dotnet build --verbosity detailed one can find the following input to the fsc compiler (redacted for clarity). Notice the order of the files in the end.

C:\Program Files\dotnet\dotnet.exe "C:\Program Files\dotnet\sdk\2.2.300\FSharp\fsc.exe" -o:obj\Debug\netcoreapp2.2\reproducegvdn.dll
         -g
         --debug:portable
         --noframework
         --define:TRACE
         --define:DEBUG
         --define:NETCOREAPP
         --define:NETCOREAPP2_2
         --optimize-
         --tailcalls-
         ...
         --target:exe
         --warn:3
         --warnaserror:3239,76
         --fullpaths
         --flaterrors
         --highentropyva-
         --targetprofile:netcore
         --nocopyfsharpcore
         --simpleresolution
         C:\Users\...\AppData\Local\Temp\.NETCoreApp,Version=v2.2.AssemblyAttributes.fs
         obj\Debug\netcoreapp2.2\reproducegvdn.AssemblyInfo.fs
         Program.fs
         obj\Debug\netcoreapp2.2\AssemblyInfo_reproducegvdn_da4sk0i1.nf4.g.fs
         obj\Debug\netcoreapp2.2\GitVersionInformation_reproducegvdn_woodujve.ebf.g.fs

Same error with both SDK 2.2.300 and 3.0.100

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions