Gitversion: [Bug] /updatewixversionfile does not cleanly recreate the file

Created on 5 May 2020  路  4Comments  路  Source: GitTools/GitVersion

The content of the file GitVersion_WixVersion.wxi is not fully overwritten/recreated when the file already exists and GitVersion /updatewixversionfile is invoked. Instead it just overwrites the first x bytes.

Expected Behavior

The entire content of GitVersion_WixVersion.wxi is overwritten and the file has a valid content afterwards.

Actual Behavior

If the existing file is larger than the newly generated file, parts of the previously existing content remain in the file.

Possible Fix

Delete the file prior writing/correctly write the content.

Steps to Reproduce

  1. Create a large dummy file called GitVersion_WixVersion.wxiin the root of a repo.
  2. Run GitVersion /updatewixversionfile
  3. After that, the file looks like this (shortend the wix related content):
<?xml version="1.0" encoding="utf-8"?>
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define AssemblySemFileVer="2.0.0.0"?>
  <?define AssemblySemVer="2.0.0.0"?>
  ...
  <?define WeightedPreReleaseNumber="30001"?>
</Include>ignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 

Your Environment

  • Version Used: 5.3.2+Branch.master.Sha.438d45004092e2f6b9aa4d12b07c64becfff4031 (also in 5.2.4)
  • Operating System and version (Windows 10, Ubuntu 18.04): Windows
bug

Most helpful comment

@asbjornu: Using wix itself is not required. It can easily be reproduced without wix. Just create a file GitVersion_WixVersion.wxi in the root of a repo which is larger than the file that will be created by calling GitVersion /updatewixversionfile. You will see that afterwards the content of the file GitVersion_WixVersion.wxi starts with the generated content followed by parts of the previous content.

The issue is, that WixVersionFileUpdater uses OpenWrite(...)
https://github.com/GitTools/GitVersion/blob/438d45004092e2f6b9aa4d12b07c64becfff4031/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs#L38
see the behavior as documented e.g. in
https://docs.microsoft.com/en-us/dotnet/api/system.io.file.openwrite?view=netcore-3.1

I added some changes in #2259

All 4 comments

I don't use Wix myself, so I don't know where to start looking to fix this. Would you be up for having a look yourself and possibly submitting a PR, @tcs-devel?

@tcs-devel at the time we added wix support via #1599 it was not specified how exaclty it should work, but the idea was to update, as we have with assemblyinfo, not to re-create.

You can check the implementation here https://github.com/GitTools/GitVersion/blob/master/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs#L27-L40. In case the current implementation is not the way you think it should we can discuss

@asbjornu: Using wix itself is not required. It can easily be reproduced without wix. Just create a file GitVersion_WixVersion.wxi in the root of a repo which is larger than the file that will be created by calling GitVersion /updatewixversionfile. You will see that afterwards the content of the file GitVersion_WixVersion.wxi starts with the generated content followed by parts of the previous content.

The issue is, that WixVersionFileUpdater uses OpenWrite(...)
https://github.com/GitTools/GitVersion/blob/438d45004092e2f6b9aa4d12b07c64becfff4031/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs#L38
see the behavior as documented e.g. in
https://docs.microsoft.com/en-us/dotnet/api/system.io.file.openwrite?view=netcore-3.1

I added some changes in #2259


:tada: This issue has been resolved in version 5.3.3 :tada:
The release is available on:

Your GitReleaseManager bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings