dotnet / Nerdbank.GitVersioning

Stamp your assemblies, packages and more with a unique version generated from a single, simple version.json file and include git commit IDs for non-official builds.
https://www.nuget.org/packages/Nerdbank.GitVersioning
MIT License
1.36k stars 166 forks source link

Compile errors in an F# project when setting NBGV_EmitThisAssemblyClass to false #1022

Closed Numpsy closed 8 months ago

Numpsy commented 8 months ago

Hi, I've been using GitVersioning in some F# projects, and it's all been working.

However, I tried setting the NBGV_EmitThisAssemblyClass property to false, and then started getting a build error from the generated Version.fs file:

error FS0010: Incomplete structured construct at or before this point in definition

Looking at the code, the version file with the default options is

namespace xxx
[<assembly: System.Reflection.AssemblyVersionAttribute("0.7.0.0")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute("0.7.59.18254")>]
[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("0.7.59-prerelease+474e680183")>]
do()
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
[<System.CodeDom.Compiler.GeneratedCode("Nerdbank.GitVersioning.Tasks","3.6.133.12845")>]
#endif
#if NET40_OR_GREATER || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER
[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]
#endif
type internal ThisAssembly() =
   ...

But with NBGV_EmitThisAssemblyClass = false it's

namespace xxx
[<assembly: System.Reflection.AssemblyVersionAttribute("0.7.0.0")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute("0.7.59.18254")>]
[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("0.7.59-prerelease+474e680183")>]

without the trailing do(), which seems to be the problem.

Just from a quick look at the GitVersioning code, it looks like the do() gets added by the StartThisAssemblyClass at https://github.com/dotnet/Nerdbank.GitVersioning/blob/2b5ba90c74dc5d3e9300e8079d6ed511536000a9/src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs#L741C21-L741C21 and then that isn't called when ThisAssembly is diabled?

This is with version 3.6.133, though the 3.7.48-alpha seems the same.

Numpsy commented 8 months ago

Would it be reasonable to have an EndAssemblyAttributes function or similar in the code generator to add the trailing do() ?

AArnott commented 8 months ago

Sure, that sounds good. I don't use F# myself. Could you send a PR to fix this?

AArnott commented 8 months ago

You may want to target the v3.6 branch instead of main so that we can get it out faster.

Numpsy commented 8 months ago

I'll try to have a look at it later

Numpsy commented 8 months ago

You may want to target the v3.6 branch instead of main so that we can get it out faster.

Do you want a PR against main as well, or will it get merged later?

AArnott commented 8 months ago

It will get merged later.