belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.43k stars 99 forks source link

VisualStudio extension can't parse the version `0.26.1+3d5768a543259cd498064d1ff364f4c741905ab6` #1000

Closed bartoszluka closed 1 year ago

bartoszluka commented 1 year ago

When initializing csharpier in the VisualStudio extension, there is a FormatException thrown and logged. I traced it back to the this line. Since 0.26.0 versions also contain something after the numbers, which breaks the extension.

I confirmed it by running

new System.Version("0.26.1+3d5768a543259cd498064d1ff364f4c741905ab6"); 
// FormatException: The input string '1+3d5768a543259cd498064d1ff364f4c741905ab6' was not in a correct format.
bartoszluka commented 1 year ago

Quick solution would be to discard everything after the plus when parsing the version. I can open a PR with the fix if this satisfies you

var installedVersion = new Version(version.Split('+').First());
belav commented 1 year ago

It seems at some point (probably 0.26.0) the action I use to publish to nuget started including the commit hash on the version number. There are 3 extensions that would need to be updated so I'll just republish a version 0.26.2 without the commit hash.

It is probably worth still updating the 3 extensions just in case this happens again, and to help anyone that doesn't update to 0.26.2.

belav commented 1 year ago

I take that back, it isn't the action adding it. dotnet pack is now including the commit hash in the nuspec, and dotnet csharpier --version is now including the commit hash after the version number. It isn't clear how to prevent that.

If you open a PR for VS I can get that published. And I'll take care of VSCode and Rider later today. Thanks!

belav commented 1 year ago

It turns out the rider and vscode are okay for now with the +hash version, so I went ahead and updated VS. I'll be on vacation in a few hours and wanted to get this out before then. Version 1.4.8 should be out shortly. I'm gonna leave this open so I can get rider and vscode to also trim off everything after the + when dealing with csharpier versions.

bartoszluka commented 1 year ago

I can confirm that it solved the issue, thank you!