diff --git a/src/app/Fake.Runtime/SdkAssemblyResolver.fs b/src/app/Fake.Runtime/SdkAssemblyResolver.fs index 22983bfac57..1f2bf27c7b9 100644 --- a/src/app/Fake.Runtime/SdkAssemblyResolver.fs +++ b/src/app/Fake.Runtime/SdkAssemblyResolver.fs @@ -33,20 +33,30 @@ type SdkAssemblyResolver(logLevel: Trace.VerboseLevel) = let RuntimeResolverResolveMethod = Environment.environVarOrDefault "FAKE_SDK_RESOLVER_RUNTIME_VERSION_RESOLVE_METHOD" "" + // Defaults still .NET 6.0 but could be overriden with .NET 8.0 or even comma-separated "6.0,8.0" + let RuntimeAssemblyVersions = + let versions = Environment.environVarOrDefault "FAKE_SDK_RESOLVER_CUSTOM_DOTNET_VERSION" "6.0" + versions.Split([|',';';'|]) |> Array.toList + member this.LogLevel = logLevel - member this.SdkVersionRaw = "6.0" + member this.SdkVersionRaws = RuntimeAssemblyVersions + + member this.SdkVersions = RuntimeAssemblyVersions |> List.map(fun v -> ReleaseVersion(v + ".0")) - member this.SdkVersion = ReleaseVersion("6.0.0") + member this.PaketFrameworkIdentifiers = + this.SdkVersions |> List.map(fun thisSdk -> + FrameworkIdentifier.DotNetFramework(FrameworkVersion.TryParse(thisSdk.Major.ToString()).Value)) - member this.PaketFrameworkIdentifier = - FrameworkIdentifier.DotNetFramework(FrameworkVersion.TryParse(this.SdkVersion.Major.ToString()).Value) + member this.SdkVersionRaw = RuntimeAssemblyVersions |> Seq.head + member this.SdkVersion = this.SdkVersions |> Seq.head + member this.PaketFrameworkIdentifier = this.PaketFrameworkIdentifiers |> Seq.head member this.SdkVersionFromGlobalJson = DotNet.tryGetSDKVersionFromGlobalJson () member this.IsSdkVersionFromGlobalJsonSameAsSdkVersion() = match this.SdkVersionFromGlobalJson with - | Some version -> ReleaseVersion(version).Major.Equals(this.SdkVersion.Major) + | Some version -> this.SdkVersions |> List.exists(fun thisSdk -> ReleaseVersion(version).Major .Equals thisSdk.Major) | None -> false member this.DotNetBinaryName = if Environment.isUnix then "dotnet" else "dotnet.exe" @@ -133,7 +143,7 @@ type SdkAssemblyResolver(logLevel: Trace.VerboseLevel) = |> Async.AwaitTask |> Async.RunSynchronously |> List.ofSeq - |> List.find (fun product -> product.ProductVersion.Equals(this.SdkVersionRaw)) + |> List.find (fun product -> this.SdkVersionRaws |> List.exists(fun raws -> product.ProductVersion.Equals raws)) sdkVersionReleases.GetReleasesAsync() |> Async.AwaitTask @@ -204,28 +214,34 @@ type SdkAssemblyResolver(logLevel: Trace.VerboseLevel) = member this.SdkReferenceAssemblies() = - let referenceAssembliesPath = - this.ResolveDotNetRoot() - |> Option.map (fun dotnetRoot -> - dotnetRoot - "packs" - "Microsoft.NETCore.App.Ref" - this.ResolveSdkRuntimeVersion() - "ref" - "net" + this.SdkVersionRaw) - - match referenceAssembliesPath with - | None -> failwithf "Could not find referenced assemblies, please check installed SDK and runtime versions" - | Some referenceAssembliesPath -> + let referenceAssembliesPaths = + this.SdkVersionRaws |> List.choose(fun rawVersion -> + this.ResolveDotNetRoot() + |> Option.map (fun dotnetRoot -> + dotnetRoot + "packs" + "Microsoft.NETCore.App.Ref" + this.ResolveSdkRuntimeVersion() + "ref" + "net" + rawVersion)) + + if Seq.isEmpty referenceAssembliesPaths then + failwithf "Could not find referenced assemblies, please check installed SDK and runtime versions" + else if this.LogLevel.PrintVerbose then - Trace.tracefn $"Resolved referenced SDK path: {referenceAssembliesPath}" - - if Directory.Exists referenceAssembliesPath then - Directory.GetFiles(referenceAssembliesPath, "*.dll") |> Seq.toList - else + let paths = String.Join(",", referenceAssembliesPaths) + Trace.tracefn $"Resolved referenced SDK paths: {paths}" + + let referenceAssembliesPath = + referenceAssembliesPaths |> List.tryFind(fun referenceAssembliesPath -> Directory.Exists referenceAssembliesPath) + match referenceAssembliesPath with + | Some pathFound -> + Directory.GetFiles(pathFound, "*.dll") |> Seq.toList + | None -> + let paths = String.Join(",", referenceAssembliesPaths) failwithf "Could not find referenced assemblies in path: '%s', please check installed SDK and runtime versions" - referenceAssembliesPath + paths member this.NetStandard20ReferenceAssemblies ( @@ -308,6 +324,7 @@ type SdkAssemblyResolver(logLevel: Trace.VerboseLevel) = paketDependenciesFile: Lazy ) = if this.LogLevel.PrintVerbose then - Trace.tracefn $"Using .Net {this.SdkVersion.Major} assemblies" + let versions = String.Join(", and", this.SdkVersions |> List.map(fun v -> $" .Net{v.Major}")) + Trace.tracefn $"Using{versions} assemblies" this.SdkReferenceAssemblies()