fsprojects / FAKE

FAKE - F# Make
https://fake.build
Other
1.28k stars 581 forks source link

Fake 5.22.0 requires .NET 6 to use Async module #2659

Closed MiloszKrajewski closed 2 years ago

MiloszKrajewski commented 2 years ago

Description

Any mention related to Async module makes fake fail with:

Error FS0193: The module/namespace 'System' from compilation unit 'netstandard' did not contain the namespace, module or type 'IAsyncDisposable'

Repro steps

Just use some async code in build.fsx, for example, add anywhere:

async { () } |> ignore

I've attached zipped folder but it can be easily done with:

  1. Create fresh FAKE project

    dotnet new -i "fake-template::*"
    dotnet new fake
  2. Use async (or Async) anywhere in build.fsx (anywhere because it does not need to be ran, it fails while compiling)

async { () } |> ignore

Alternatively, use provided project:

fake-async-boom.zip

and run with ./fake build

Expected behavior

No problems expected.

Actual behavior

Fails when compiling script. I guess it is something about .net6, .netstandard2.0 and FSharp.Core compatibility, but that's it.

Known workarounds

None found. I've tried downgrading to 5.21.x but with no success.

Related information

Additional information

What happens:

image

build.fsx.lock

build.fsx.lock.zip

yazeedobaid commented 2 years ago

@MiloszKrajewski Can you please add a global.json file beside your script and specify a Net6 version in it? Since it seems FAKE has defaulted to netstandard2.0 reference assemblies when compiling the script. And IAsyncDisposable is available on Netstandard2.1 and above.

MiloszKrajewski commented 2 years ago

Closed by accident ;-) I did not thought it through yet, but this worries me a little bit. If I put global.json in root then I will force same SDK for build script and my own projects, right? I was hoping fake-cli will (magically?) run using .NET 6 while I can still force SDK 5.0 to be used for my project.

I will test if this still works for me? Maybe I need to put fake-cli not in root of my project?

I need to think if it is still going to work me.

Thank you.

yazeedobaid commented 2 years ago

We have implemented it this way because the default was to use Netstabndard2.0 reference assemblies. And defaulting to Net6 would be a breaking change. Net6 should be the default for FAKE reference assemblies when the next major release is published.

MiloszKrajewski commented 2 years ago

Bad news: adding global.json did not help. Good news: deleting .fake folder AND adding global.json did help. Even better: after rebuilding .fake folder global.json file can be deleted. Although, AFAIU, .fake folder is not meant to be stored in repo so it needs to be and will be rebuilt over and over again. Juggling with global.json does not feel right.

I checked differences and the only file which is different is ".fake/build.fsx/dependencies.txt" and yes, in fact, one points to netstandard2.0 and the other to net6.

I'm not sure if I understand the argument about "enforcing .NET 6 would be a breaking change".

If async (for example, Fake.Api.GitHub uses async) started crashing after upgrading then this is already a breaking change and .NET 6 is already enforced. Actually two things are enforced: it requires .NET 6 AND global.json now.

In other words, for example, it is not possible to create new project (https://fake.build/fake-gettingstarted.html) which uses Fake.Api.GitHub without global.json pointing explicitly to .NET6.

Bootstrapping previous version (5.20.4) does not work either, as it tries to lock 5.22.0 assemblies and ends with Could not detect any platforms from 'net6.0' in 'C:\Users\xxx\.nuget\packages\system.collections.immutable\6.0.0\System.Collections.Immutable.6.0.0.nupkg\System.Collections.Immutable.nuspec', please tell the package authors

So, I guess "next major release" is now imminent ;-)

Some workaround for 5.20.4 is a lot of pinning of pre-5.22.0 assemblies (or reusing some old .lock file).

yazeedobaid commented 2 years ago

Is there anything still left in this issue?

MiloszKrajewski commented 2 years ago

Yeah, I think it can be closed. I'm actually not sure what I would be positive outcome.

So, as a summary

starting at 5.21.1 FAKE requires .NET 6 both while resolving build.fsx.lock file and running build.fsx if script mentions or uses Async module (for example: [Fake.Api.GitHub](https://www.nuget.org/packages/Fake.Api.GitHub))