Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE]: Syntax error in generated GitVersionInformation class when using project namespace #4196

Closed
2 tasks done
rose-a opened this issue Sep 3, 2024 · 5 comments · Fixed by #4197
Closed
2 tasks done
Labels
Milestone

Comments

@rose-a
Copy link
Contributor

rose-a commented Sep 3, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.MsBuild

GitVersion version

v6.0.0

Operating system

Windows

What are you seeing?

When setting <UseProjectNamespaceForGitVersionInformation>true</UseProjectNamespaceForGitVersionInformation> in the project file, I get the following build error in line 28 in GitVersionInformation.g.cs:

error CS1022: Type or namespace definition, or end-of-file expected

This is because, in the generated code, the namespace declaration for the GitVersionInformation class has a semicolon appended:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     GitVersion
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6
namespace System.Diagnostics.CodeAnalysis
{
    [global::System.AttributeUsage(
        global::System.AttributeTargets.Assembly |
        global::System.AttributeTargets.Class |
        global::System.AttributeTargets.Struct |
        global::System.AttributeTargets.Constructor |
        global::System.AttributeTargets.Method |
        global::System.AttributeTargets.Property |
        global::System.AttributeTargets.Event,
        Inherited = false, AllowMultiple = false)]
    internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute { }
}
#endif

namespace My.Project.Namespace;
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    static class GitVersionInformation
    {
        public const string AssemblySemFileVer = "3.2.5.0";
        public const string AssemblySemVer = "3.2.5.0";
        public const string BranchName = "my-branch-name";
        public const string BuildMetaData = "";
        public const string CommitDate = "2024-09-03";
        public const string CommitsSinceVersionSource = "20";
        public const string EscapedBranchName = "my-branch-name";
        public const string FullBuildMetaData = "Branch.my-branch-name.Sha.ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string FullSemVer = "3.2.5-issue16.20";
        public const string InformationalVersion = "3.2.5-issue16.20+Branch.my-branch-name.Sha.ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string Major = "3";
        public const string MajorMinorPatch = "3.2.5";
        public const string Minor = "2";
        public const string Patch = "5";
        public const string PreReleaseLabel = "issue16";
        public const string PreReleaseLabelWithDash = "-issue16";
        public const string PreReleaseNumber = "20";
        public const string PreReleaseTag = "issue16.20";
        public const string PreReleaseTagWithDash = "-issue16.20";
        public const string SemVer = "3.2.5-issue16.20";
        public const string Sha = "ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string ShortSha = "ee208cb";
        public const string UncommittedChanges = "0";
        public const string VersionSourceSha = "bcd15e4babf9b0c9818e5a64bbd7b94041785602";
        public const string WeightedPreReleaseNumber = "30020";
    }
}

What is expected?

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     GitVersion
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6
namespace System.Diagnostics.CodeAnalysis
{
    [global::System.AttributeUsage(
        global::System.AttributeTargets.Assembly |
        global::System.AttributeTargets.Class |
        global::System.AttributeTargets.Struct |
        global::System.AttributeTargets.Constructor |
        global::System.AttributeTargets.Method |
        global::System.AttributeTargets.Property |
        global::System.AttributeTargets.Event,
        Inherited = false, AllowMultiple = false)]
    internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute { }
}
#endif

-namespace My.Project.Namespace;
+namespace My.Project.Namespace
{
    [global::System.Runtime.CompilerServices.CompilerGenerated]
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    static class GitVersionInformation
    {
        public const string AssemblySemFileVer = "3.2.5.0";
        public const string AssemblySemVer = "3.2.5.0";
        public const string BranchName = "my-branch-name";
        public const string BuildMetaData = "";
        public const string CommitDate = "2024-09-03";
        public const string CommitsSinceVersionSource = "20";
        public const string EscapedBranchName = "my-branch-name";
        public const string FullBuildMetaData = "Branch.my-branch-name.Sha.ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string FullSemVer = "3.2.5-issue16.20";
        public const string InformationalVersion = "3.2.5-issue16.20+Branch.my-branch-name.Sha.ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string Major = "3";
        public const string MajorMinorPatch = "3.2.5";
        public const string Minor = "2";
        public const string Patch = "5";
        public const string PreReleaseLabel = "issue16";
        public const string PreReleaseLabelWithDash = "-issue16";
        public const string PreReleaseNumber = "20";
        public const string PreReleaseTag = "issue16.20";
        public const string PreReleaseTagWithDash = "-issue16.20";
        public const string SemVer = "3.2.5-issue16.20";
        public const string Sha = "ee208cbc6d6dcc5869c29142801a3cc0ef290400";
        public const string ShortSha = "ee208cb";
        public const string UncommittedChanges = "0";
        public const string VersionSourceSha = "bcd15e4babf9b0c9818e5a64bbd7b94041785602";
        public const string WeightedPreReleaseNumber = "30020";
    }
}

Steps to Reproduce

Enable <UseProjectNamespaceForGitVersionInformation>true</UseProjectNamespaceForGitVersionInformation> in your project file.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

No response

@arturcic
Copy link
Member

arturcic commented Sep 3, 2024

Relates to #4116 (comment)

@arturcic
Copy link
Member

arturcic commented Sep 3, 2024

@rose-a a PR is welcomed, but if possible let's change the syntax to use the

namespace My.Project.Namespace;

with the semicolon

and then remove the curly braces aka file_scoped_namespace_declaration

@rose-a
Copy link
Contributor Author

rose-a commented Sep 3, 2024

@arturcic This wont work because of the optional declaration of ExcludeFromCodeCoverageAttribute, since there can only be a single file-scoped namespace declaration in a source file.

@arturcic
Copy link
Member

arturcic commented Sep 3, 2024

then let's use the old syntax, can you create a PR with the fix? Would also be nice to have a unit test that covers the issue

@gittools-bot
Copy link

🎉 This issue has been resolved in version 6.0.3 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants