bilal-fazlani / commanddotnet

A modern framework for building modern CLI apps
https://commanddotnet.bilal-fazlani.com
MIT License
560 stars 32 forks source link

Version command fails when no build info is present #494

Closed diredev closed 2 months ago

diredev commented 2 months ago

I get the following error when using the Version command on my application:

Unhandled exception. System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length')
Actual value was -1.
   at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
   at System.ArgumentOutOfRangeException.ThrowIfNegative[T](T value, String paramName)
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
   at CommandDotNet.Builders.AppInfo.GetVersion(Assembly hostAssembly) in CommandDotNet/Builders/AppInfo.cs:line 145
   at CommandDotNet.Builders.AppInfo.get_Version() in CommandDotNet/Builders/AppInfo.cs:line 61
   at CommandDotNet.Diagnostics.VersionMiddleware.Print(IConsole console) in CommandDotNet/Diagnostics/VersionMiddleware.cs:line 60
   ....

Looking at the code it seems that AppInfo.GetVersion() requires the AssemblyInformationalVersionAttribute to include the "+" character. Lack thereof will always cause this issue.

Note that MSBuild will always add the AssemblyInformationalVersionAttribute when bulding SDK-style projects, even if a plain version without pre-release or build information is used.

drewburlingame commented 2 months ago

Thanks for posting this. I'll be back in the office next week and will look into it then. I'm also happy to accept PRs if you need it resolved sooner.

drewburlingame commented 2 months ago

fixed in https://www.nuget.org/packages/CommandDotNet/7.0.4. Thanks again for posting.