Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REGRESSION] FAKE 6.1.0 fails with dotnet preview versions #2803

Closed
SteveGilham opened this issue Aug 11, 2024 · 5 comments
Closed

[REGRESSION] FAKE 6.1.0 fails with dotnet preview versions #2803

SteveGilham opened this issue Aug 11, 2024 · 5 comments

Comments

@SteveGilham
Copy link
Contributor

SteveGilham commented Aug 11, 2024

Description

Upgrading the AltCover build from v6.0.0 to v6.1.0, the first use of Fake.DotNet.DotNet.exec fails when parsing the version string in global.json. The same is true for other APIs, like DotNet.restore

Repro steps

  1. Install SDK 9.0.100-preview.6.24328.19
  2. Invoke it with a global.json like
{
  "sdk": {
    "version": "9.0.100-preview.6.24328.19",
    "rollForward": "latestMinor"
  }
}
  1. Run a command with DotNet.exec

Expected behavior

It just works, i.e. unchanged since v 6.0.0

Actual behavior

Exception thrown

Unhandled exception. System.TypeInitializationException: The type initializer for 'AltCover.Targets' threw an exception.
 ---> System.TypeInitializationException: The type initializer for '<StartupCode$build>.$Targets' threw an exception.
 ---> System.Exception: Could not parse `sdk.version` from global.json at 'C:\Users\email\Documents\Github\altcover\global.json': Version string portion was too short or too long. (Parameter 'input')
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
   at Fake.DotNet.DotNet.tryGetSDKVersionFromGlobalJsonDir(String startDir) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Cli\DotNet.fs:line 77
   at Fake.DotNet.DotNet.Options.Create() in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Cli\DotNet.fs:line 546
   at Fake.DotNet.DotNet.exec(FSharpFunc`2 buildOptions, String command, String args) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Cli\DotNet.fs:line 772
   at <StartupCode$build>.$Targets..cctor() in C:\Users\email\Documents\Github\altcover\Build\targets.fs:line 174

Known workarounds

Revert to 6.0.0

Related information

  • Operating system - Windows 11
  • Branch - using the 6.1.0 release from NuGet
  • .NET Runtime, CoreCLR or Mono Version - dotnet SDK 9.0.100-preview.6.24328.19
  • Indications of severity - complete stopper for pre-release development
  • Version of FAKE (4.X, 5.X, 6.x) - 6.1.0
@SteveGilham
Copy link
Contributor Author

SteveGilham commented Aug 11, 2024

Parsing out the underlying version would be something like in Fake.DotNet.Cli/DotNet.fs, line 73 to put

let versionValue = (version.Value.ToString().Split("-preview"))[0]

but when used to determine an SDK file path, then the correct action is to use the global.json value as it stands, and only throw when files are not found.

Screenshot 2024-08-11 092526

@SteveGilham SteveGilham changed the title FAKE 6.1.0 fails with dotnet preview versions [REGRESSION] FAKE 6.1.0 fails with dotnet preview versions Aug 11, 2024
@SteveGilham
Copy link
Contributor Author

SteveGilham commented Aug 11, 2024

Having had time to reflect on this at leisure -

Firstly, I was forgetting earlier that we also have release candidate builds, like last year's 8.0.100-rc.1.23463.5, so the correct general major/minor/build/revision-style version extraction would be

let versionValue = (version.Value.ToString().Split('-'))[0]

Secondly, chasing up the call chain to the definition of Options.Create, this is then trying to compose a file path containing the version, so shouldn't be extracting the version from the global.json as other than a literal string.

The correct fix, therefore is to simply delete line 74, thus simplifying the match expression to

                match sdk.Property("version") with
                | null -> None
                | version ->
                    Some (version.Value.ToString())

or, more directly expressing intent, like

               sdk.Property("version")
               |> Option.ofObj
               |> Option.map _.Value.ToString()

@Numpsy
Copy link
Contributor

Numpsy commented Aug 12, 2024

refs #2757 I think? (I don't know why the Version.Parse was added as well as the null check)

xperiandri pushed a commit that referenced this issue Aug 31, 2024
refs #2803 - The check seems to break if the version is a pre-release version such as 9.0.100-preview.6.24328.19

The Parse call was added as part of the null change in #2757 but I'm not sure if there was any reason for it other than an attempt at a sanity check.
@xperiandri
Copy link
Collaborator

Try 6.1.1

@SteveGilham
Copy link
Contributor Author

That resolves the issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants