Skip to content

Commit eb1bda9

Browse files
committed
use NETStandard.Library for netstandard20 references.
1 parent 9b5b175 commit eb1bda9

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

src/app/Fake.Runtime/CompileRunner.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let runUncached (context:FakeContext) : ResultCoreCacheInfo * Exception option =
9595
// see https://github.com/fsharp/FSharp.Compiler.Service/issues/755
9696
// see https://github.com/fsharp/FSharp.Compiler.Service/issues/799
9797
let options =
98-
[co.AdditionalArguments; [ "--fullpaths"; "--simpleresolution"; "--targetprofile:netcore"; "--nowin32manifest"; "-o"; wishPath; context.Config.ScriptFilePath ] ]
98+
[co.AdditionalArguments; [ "--fullpaths"; "--simpleresolution"; "--targetprofile:netstandard"; "--nowin32manifest"; "-o"; wishPath; context.Config.ScriptFilePath ] ]
9999
|> List.concat
100100
|> FsiOptions.ofArgs
101101
|> fun f ->

src/app/Fake.Runtime/FakeRuntime.fs

+33-24
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ let paketCachingProvider printDetails cacheDir (paketDependencies:Paket.Dependen
8989
let groupStr = match group with Some g -> g | None -> "Main"
9090
let groupName = Paket.Domain.GroupName (groupStr)
9191
#if DOTNETCORE
92-
let framework = Paket.FrameworkIdentifier.DotNetCoreApp (Paket.DotNetCoreAppVersion.V2_0)
92+
//let framework = Paket.FrameworkIdentifier.DotNetCoreApp (Paket.DotNetCoreAppVersion.V2_0)
93+
let framework = Paket.FrameworkIdentifier.DotNetStandard (Paket.DotNetStandardVersion.V2_0)
9394
#else
9495
let framework = Paket.FrameworkIdentifier.DotNetFramework (Paket.FrameworkVersion.V4_6)
9596
#endif
@@ -99,8 +100,36 @@ let paketCachingProvider printDetails cacheDir (paketDependencies:Paket.Dependen
99100

100101
#if DOTNETCORE
101102
let getCurrentSDKReferenceFiles() =
102-
let netstandard = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyName(System.Reflection.AssemblyName("netstandard"))
103-
let sdkDir = Path.GetDirectoryName netstandard.Location
103+
// We need use "real" reference assemblies as using the currently running runtime assemlies doesn't work:
104+
// see https://github.com/fsharp/FAKE/pull/1695
105+
106+
// Therefore we download the reference assemblies (the NETStandard.Library package)
107+
// and add them in addition to what we have resolved,
108+
// we use the sources in the paket.dependencies to give the user a chance to overwrite.
109+
110+
// Note: This package/version needs to updated together with our "framework" variable below and needs to
111+
// be compatible with the runtime we are currently running on.
112+
let rootDir = Directory.GetCurrentDirectory()
113+
let sources = paketDependencies.GetSources().[groupName]
114+
let packageName = Domain.PackageName("NETStandard.Library")
115+
let version = SemVer.Parse("2.0.0")
116+
let versions =
117+
Paket.NuGet.GetVersions false None rootDir (PackageResolver.GetPackageVersionsParameters.ofParams sources groupName packageName)
118+
|> Async.RunSynchronously
119+
|> dict
120+
let source =
121+
match versions.TryGetValue(version) with
122+
| true, v when v.Length > 0 -> v |> Seq.head
123+
| _ -> failwithf "Could not find package '%A' with version '%A' in any package source of group '%A', but paket needs this package for compilation" packageName version groupName
124+
125+
let _, extractedFolder =
126+
Paket.NuGet.DownloadAndExtractPackage
127+
(None, rootDir, false, PackagesFolderGroupConfig.NoPackagesFolder,
128+
source, [], Paket.Constants.MainDependencyGroup,
129+
packageName, version, false, false, false, false)
130+
|> Async.RunSynchronously
131+
//let netstandard = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyName(System.Reflection.AssemblyName("netstandard"))
132+
let sdkDir = Path.Combine(extractedFolder, "build", "netstandard2.0", "ref")
104133
Directory.GetFiles(sdkDir, "*.dll")
105134
|> Seq.toList
106135
#endif
@@ -190,26 +219,6 @@ let paketCachingProvider printDetails cacheDir (paketDependencies:Paket.Dependen
190219
|> Seq.choose (fun (isSdk, isReferenceAssembly, fi) ->
191220
let fullName = fi.FullName
192221
try let assembly = Mono.Cecil.AssemblyDefinition.ReadAssembly fullName
193-
let takeAssembly =
194-
if not isSdk then true
195-
else
196-
let isFramework =
197-
assembly.CustomAttributes |> Seq.exists (fun attr ->
198-
if attr.AttributeType.Name = "AssemblyMetadataAttribute" then
199-
let arg1 = attr.ConstructorArguments.[0]
200-
let value1 = arg1.Value.ToString()
201-
let arg2 = attr.ConstructorArguments.[1]
202-
let value2 = arg2.Value.ToString()
203-
value1 = ".NETFrameworkAssembly" ||
204-
(value1 = "Serviceable" && value2 = "True")
205-
206-
else false)
207-
isFramework
208-
if not takeAssembly then
209-
if printDetails then Trace.log <| sprintf "Not taking '%s'" fullName
210-
None
211-
else
212-
213222
{ IsReferenceAssembly = isReferenceAssembly
214223
Info =
215224
{ Runners.AssemblyInfo.FullName = assembly.Name.FullName
@@ -220,7 +229,7 @@ let paketCachingProvider printDetails cacheDir (paketDependencies:Paket.Dependen
220229
|> Seq.groupBy (fun ass -> ass.IsReferenceAssembly, System.Reflection.AssemblyName(ass.Info.FullName).Name)
221230
|> Seq.map (fun (_, group) -> group |> Seq.maxBy(fun ass -> ass.Info.Version))
222231
|> Seq.toList
223-
//|> List.partition (fun c -> c.IsReferenceAssembly)
232+
224233
// Restore or update immediatly, because or everything might be OK -> cached path.
225234
let knownAssemblies = restoreOrUpdate()
226235
if printDetails then

0 commit comments

Comments
 (0)