Skip to content

[Bug] GitVersion.MSBuild broken for WiX setup projects #2595

Closed
@NameOfTheDragon

Description

@NameOfTheDragon

Describe the bug
I have previously used GitVersion.Task nuget package in my Wix Toolset setup builds.
After migrating to GitVersion.MSBuild, this no longer works.
The problems seem to be centred around the handling of the Language parameter to the GetVersion task.
Build fails with the following error message:

------ Rebuild All started: Project: TA.NexDome.Bootstrapper, Configuration: Release x86 ------
		"D:\VS-Projects\TA.NexDome.AscomServer\packages\GitVersion.MsBuild.5.6.6\tools\net48/gitversion.exe" "D:\VS-Projects\TA.NexDome.AscomServer\TA.NexDome.Bootstrapper" -output file -outputfile gitversion.json
		D:\VS-Projects\TA.NexDome.AscomServer\packages\WiX.3.11.2\build\..\tools\candle.exe -wx -dGitVersion_UncommittedChanges=0 -dGitVersion_CommitsSinceVersionSourcePadded=0055 -dGitVersion_CommitsSinceVersionSource=55 -dGitVersion_VersionSourceSha=c8e057a899e84b13c4374fa53c87d351b33e7608 -dGitVersion_CommitDate=2021-01-08 -dGitVersion_NuGetPreReleaseTag=beta0105 -dGitVersion_NuGetPreReleaseTagV2=beta0105 -dGitVersion_NuGetVersion=4.0.0-beta0105 -dGitVersion_NuGetVersionV2=4.0.0-beta0105 -dGitVersion_ShortSha=730ef67 -dGitVersion_Sha=730ef678c48a1a00ee8be97122c1d7be2f5268e5 -dGitVersion_EscapedBranchName=release-4-0-0 -dGitVersion_BranchName=release/4.0.0 -dGitVersion_InformationalVersion=4.0.0-beta.105+Branch.release-4.0.0.Sha.730ef678c48a1a00ee8be97122c1d7be2f5268e5 -dGitVersion_FullSemVer=4.0.0-beta.105 -dGitVersion_AssemblySemFileVer=4.0.0.0 -dGitVersion_AssemblySemVer=4.0.0.105 -dGitVersion_LegacySemVerPadded=4.0.0-beta0105 -dGitVersion_LegacySemVer=4.0.0-beta105 -dGitVersion_SemVer=4.0.0-beta.105 -dGitVersion_MajorMinorPatch=4.0.0 -dGitVersion_FullBuildMetaData=Branch.release-4.0.0.Sha.730ef678c48a1a00ee8be97122c1d7be2f5268e5 -dGitVersion_WeightedPreReleaseNumber=30105 -dGitVersion_PreReleaseNumber=105 -dGitVersion_PreReleaseLabelWithDash= -dGitVersion_PreReleaseLabel=beta -dGitVersion_PreReleaseTagWithDash=-beta.105 -dGitVersion_PreReleaseTag=beta.105 -dGitVersion_Patch=0 -dGitVersion_Minor=0 -dGitVersion_Major=4 -dDevEnvDir=F:\VS2019-Preview\Common7\IDE\ -dSolutionDir=D:\VS-Projects\TA.NexDome.AscomServer\ -dSolutionExt=.sln -dSolutionFileName=TA.NexDome.AscomServer.sln -dSolutionName=TA.NexDome.AscomServer -dSolutionPath=D:\VS-Projects\TA.NexDome.AscomServer\TA.NexDome.AscomServer.sln -dConfiguration=Release -dOutDir=..\BuildOutput\ -dPlatform=x86 -dProjectDir=D:\VS-Projects\TA.NexDome.AscomServer\TA.NexDome.Bootstrapper\ -dProjectExt=.wixproj -dProjectFileName=TA.NexDome.Bootstrapper.wixproj -dProjectName=TA.NexDome.Bootstrapper -dProjectPath=D:\VS-Projects\TA.NexDome.AscomServer\TA.NexDome.Bootstrapper\TA.NexDome.Bootstrapper.wixproj -dTargetDir=D:\VS-Projects\TA.NexDome.AscomServer\BuildOutput\ -dTargetExt=.exe -dTargetFileName=NexDomeControlSystem.exe -dTargetName=NexDomeControlSystem -dTargetPath=D:\VS-Projects\TA.NexDome.AscomServer\BuildOutput\NexDomeControlSystem.exe -out obj\Release\ -arch x86 -ext D:\VS-Projects\TA.NexDome.AscomServer\packages\WiX.3.11.2\build\..\tools\\WixNetFxExtension.dll -ext D:\VS-Projects\TA.NexDome.AscomServer\packages\WiX.3.11.2\build\..\tools\\WixUtilExtension.dll -ext D:\VS-Projects\TA.NexDome.AscomServer\packages\WiX.3.11.2\build\..\tools\\WixBalExtension.dll ArduinoDriverInstallerPayload.wxs AscomPlatformBootstrapper.wxs Bundle.wxs NetFx48Bootstrapper.wxs NexDomeAscomServer.wxs NetFx472Bootstrapper.wxs obj\Release\GitVersionInformation.g.cs
candle.exe(0,0): error CNDL0103: The system cannot find the file 'obj\Release\GitVersionInformation.g.cs' with type 'Source'.
Done building project "TA.NexDome.Bootstrapper.wixproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

The error is in the line that invokes candle.exe. All of the version properties are being correctly supplied (example: -dGitVersion_InformationalVersion=4.0.0-beta.105+Branch.release-4.0.0.Sha.730ef678c48a1a00ee8be97122c1d7be2f5268e5 but then right at the end of the line, the file obj\Release\GitVersionInformation.g.cs is being 'injected' into the build. This file does not exist and is not part of the project.. This is clearly not correct for a wix setup project.

I believe this is happening because Language defaults to "C#" and GitVersion is therefore attempting to inject version metadata into the assembly being built. This clearly will not work for a Wix project, since no assembly is being built and there is no compile step being executed.

I have tried:

  • Setting Language to something other than C#, such as "wix". This results in an "Invalid language detected" build error.
  • Setting Language to empty string, results in error: "GenerateGitVersionInformation" task was not given a value for the required parameter "Language".
  • Setting property <UpdateAssemblyInfo>False</UpdateAssemblyInfo> in the .wixproj (no effect)

Expected Behavior

This build should succeed and GitVersion should not try to inject any files into the build process.

Actual Behavior

GitVersion is incorrectly assuming that this is a C# project and is attempting to inject C# code into the build.

Possible Fix

It seems like a very C#-oriented mindset has led to some bad assumptions around how language-specific processing is handled.

This causes problems under Linux because Language is a commonly defined environment variable which gets picked up by the build (issue #2591).

It causes problems in projects that don't have a normal "compile" step, such as Wix setup projects.
It will likely cause problems in other less common project types such as NDoc documentation projects.

It seems to me that what is missing is the recognition that GitVersion may be used from languages that it knows nothing about,
such as Wix, or NDoc, or from completely hand-crafted MSBuild project files that don't use the standard .NET build pipeline.

Consider this code in FileHelper.cs:

        public static string GetFileExtension(string language)
        {
            return language switch
            {
                "C#" => "cs",
                "F#" => "fs",
                "VB" => "vb",
                _ => throw new ArgumentException($"Unknown language detected: '{language}'")
            };
        }

What should I set Language to in a wix project? There is no valid value!!

My suggestion would be to introduce a value of "none" or "other" which explicitly disables language specific processing, and make that the default. In fact, rather than throwing an error and failing the build for an unrecognized language, just disable language-specific processing and perhaps print a warning explaining to the user how to modify their project file to explicitly set Language to an appropriate value.

  • If Language is set to a supported language, then do the appropriate language-specific processing.
  • If Language is set to None then disable any language-specific processing.
  • If Language is set to an unrecognized value, print a warning advising the user to set it to None and continue as if it had been set to None
  • If Language has no value, default to None and continue.
  • Never fail the build because the value of Language is not recognized.

There is no sense in defaulting to "C#" unless you know for sure you are in a C# project. That clearly doesn't work.

Steps to Reproduce

Assumption: Wix Toolset is installed and working in Visual Studio.

  1. File -> New Project. Select "Wix Setup Project for Wix 3.5".
  2. Fill in required parameters in Product.wxs and build. Verify build successful.
  3. Install GitVersion.MSBuild via nuget package manager
  4. Rebuild. Observe build failure.

Here is a ready-made failing minimal project: https://github.com/NameOfTheDragon/GitVersion.Issue

Context

So far, GitVersion.MSBuild has caused problems at every stage of my solution.
I'm still unable to release my build while I rely on GitVersion.
It's a complete showstopper.

Your Environment

https://github.com/NameOfTheDragon/GitVersion.Issue

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions