Skip to content

Commit

Permalink
Fix net sdk references discovery (dotnet#10569)
Browse files Browse the repository at this point in the history
* Fix net sdk references discovery

* Do numbers properly

* version filter
  • Loading branch information
KevinRansom authored and nosami committed Feb 22, 2021
1 parent dab3e8a commit 0f373f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/fsharp/CompilerConfig.fs
Expand Up @@ -877,8 +877,6 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
#endif
None, data.legacyReferenceResolver.HighestInstalledNetFrameworkVersion()

let systemAssemblies = systemAssemblies

member x.primaryAssembly = data.primaryAssembly
member x.noFeedback = data.noFeedback
member x.stackReserveSize = data.stackReserveSize
Expand Down
22 changes: 17 additions & 5 deletions src/fsharp/DotNetFrameworkDependencies.fs
Expand Up @@ -29,7 +29,7 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
location

let inline ifEmptyUse alternative filename = if String.IsNullOrWhiteSpace filename then alternative else filename

let getFSharpCoreLibraryName = "FSharp.Core"
let getFsiLibraryName = "FSharp.Compiler.Interactive.Settings"
let getDefaultFSharpCoreLocation = Path.Combine(fSharpCompilerLocation, getFSharpCoreLibraryName + ".dll")
Expand Down Expand Up @@ -62,15 +62,27 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
// packs\Microsoft.NETCore.App.Ref\sdk-version\netcoreappn.n
// we will rely on the sdk-version match on the two paths to ensure that we get the product that ships with the
// version of the runtime we are executing on
// Use the reference assemblies for the highest netcoreapp tfm that we find in that location.
// Use the reference assemblies for the highest netcoreapp tfm that we find in that location that is
// lower than or equal to the implementation version.
let zeroVersion = Version("0.0.0.0")
let version, frameworkRefsPackDirectoryRoot =
try
let version = DirectoryInfo(implementationAssemblyDir).Name
let computeVersion version =
match Version.TryParse(version) with
| true, v -> v
| false, _ -> zeroVersion

let version = computeVersion (DirectoryInfo(implementationAssemblyDir).Name)
let microsoftNETCoreAppRef = Path.Combine(implementationAssemblyDir, "../../../packs/Microsoft.NETCore.App.Ref")
if Directory.Exists(microsoftNETCoreAppRef) then
Some version, Some microsoftNETCoreAppRef
let directory = DirectoryInfo(microsoftNETCoreAppRef).GetDirectories()
|> Array.map (fun di -> computeVersion di.Name)
|> Array.sort
|> Array.filter(fun v -> v <= version)
|> Array.last
Some (directory.ToString()), Some microsoftNETCoreAppRef
else
Some version, None
None, None
with | _ -> None, None

// Tries to figure out the tfm for the compiler instance.
Expand Down

0 comments on commit 0f373f0

Please sign in to comment.