BoolBySigma / UpdateAssemblyInfo

SORRY THIS IS NO LONGER MAINTAINED
10 stars 9 forks source link

Current value for attribute 'AssemblyVersion' is not in a correct version format #15

Closed Kujawadl closed 7 years ago

Kujawadl commented 7 years ago

Logs

##[debug]UpdateVersion
##[debug]attributeName: AssemblyVersion
##[debug]format: 4.1.17.13903
##[debug]oldValue: 2.0.0
##[error]Current value for attribute 'AssemblyVersion' is not in a correct version format.

Code

public class AssemblyInfoUpdater
{
private string UpdateVersion(string attributeName, string format)
  {
    ...
    private static readonly Regex VersionParser = new Regex("\\d+\\.\\d+\\.\\d+\\.\\d+", RegexOptions.Compiled)
    ...
    if (!AssemblyInfoUpdater.VersionParser.IsMatch(text))
    {
      throw new FormatException("Current value for attribute '" + attributeName + "' is not in a correct version format.");
    }
    ...
  }
}

Fix

The code is not taking into account version strings with less than 4 components.

You're reinventing the whell using regex here. You're already using System.Version to create the final version string. Why not just use Version.TryParse()?

if (Version.TryParse(text, out v))
{
  // Do something
} else {
  throw new FormatException("Current value for attribute '" + attributeName + "' is not in a correct version format.");
}

Request

Please open source this code. If the codebase were on GitHub, I'd be able to correct this issue and begin using the fix immediately, as well as submit a pull request to save you the trouble of fixing it yourself. I'd love to help if you'd let me :+1:

Kujawadl commented 7 years ago

I went ahead and opened the assembly in dnSpy and updated the method to include the fix, so no rush on this. Like I said, if you open source the code I'd be happy to create a pull request with the fix.

Thanks!

ghost commented 7 years ago

Hi

Thank you for your input.

Its been my intention for a while to make it open source and it is now available here.

The extension is based off an old tool we used internallay. The regex parts for parsing file and versions are one of the areas that needs attention.

Looking forward to your improvements:)

ghost commented 7 years ago

Fixed in #18