@@ -109,6 +109,7 @@ let SimplisticResolver =
109109 | _ -> () ]
110110
111111
112+ let results = ResizeArray()
112113 let searchPaths =
113114 [ yield ! targetFrameworkDirectories
114115 yield ! explicitIncludeDirs
@@ -117,33 +118,58 @@ let SimplisticResolver =
117118 if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then
118119 yield ! registrySearchPaths() ]
119120
120- [| for ( baggage, r) in references do
121+ for ( baggage, r) in references do
122+ try
121123 let mutable found = false
122124 let success path =
123125 if not found then
124126 found <- true
125- [ { itemSpec = path; prepareToolTip = snd; baggage= baggage } ]
126- else []
127- if Path.IsPathRooted( r) then
127+ results.Add { itemSpec = path; prepareToolTip = snd; baggage= baggage }
128+
129+ if not found && Path.IsPathRooted( r) then
128130 if FileSystem.SafeExists( r) then
129- yield ! success r
130- else
131- let isFileName =
132- r.EndsWith( " dll" , StringComparison.InvariantCultureIgnoreCase) ||
133- r.EndsWith( " exe" , StringComparison.InvariantCultureIgnoreCase)
134-
135- let qual = if isFileName then r else try AssemblyName( r) .Name + " .dll" with _ -> r + " .dll"
136-
137- for searchPath in searchPaths do
138- if not found then
139- let trialPath = Path.Combine( searchPath, qual)
140- if FileSystem.SafeExists( trialPath) then
141- yield ! success trialPath
131+ success r
132+
133+ // For this one we need to get the version search exactly right, without doing a load
134+ if not found && r.StartsWith( " FSharp.Core, Version=" ) && Environment.OSVersion.Platform = PlatformID.Win32NT then
135+ let n = AssemblyName( r)
136+ let fscoreDir0 =
137+ let PF =
138+ match Environment.GetEnvironmentVariable( " ProgramFiles(x86)" ) with
139+ | null -> Environment.GetEnvironmentVariable( " ProgramFiles" )
140+ | s -> s
141+ PF + @" \Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString()
142+ let trialPath = Path.Combine( fscoreDir0, n.Name + " .dll" )
143+ printfn " searching %s " trialPath
144+ if FileSystem.SafeExists( trialPath) then
145+ success trialPath
146+
147+ // Try to use Assemby.Load rather than searching paths for assemblies with explicit versions
148+ if not found && r.Contains( " ," ) then
149+ let ass = try Some ( Assembly.Load( r)) with _ -> None
150+ match ass with
151+ | None -> ()
152+ | Some ass -> success ass.Location
153+
154+ let isFileName =
155+ r.EndsWith( " dll" , StringComparison.InvariantCultureIgnoreCase) ||
156+ r.EndsWith( " exe" , StringComparison.InvariantCultureIgnoreCase)
157+
158+ let qual = if isFileName then r else try AssemblyName( r) .Name + " .dll" with _ -> r + " .dll"
159+
160+ for searchPath in searchPaths do
142161 if not found then
143- let ass = try Some ( System.Reflection.Assembly.ReflectionOnlyLoad( r)) with _ -> None
144- match ass with
145- | None -> ()
146- | Some ass -> yield ! success ass.Location |] }
162+ let trialPath = Path.Combine( searchPath, qual)
163+ if FileSystem.SafeExists( trialPath) then
164+ success trialPath
165+
166+ if not found then
167+ let ass = try Some ( Assembly.Load( r)) with _ -> None
168+ match ass with
169+ | Some ass -> success ass.Location
170+ | None -> ()
171+ with e -> logWarning " SR001" ( e.ToString())
172+ results.ToArray() }
147173
148174#if INTERACTIVE
149175SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory
@@ -168,14 +194,14 @@ resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7
168194#endif
169195
170196let GetDefaultResolver ( msbuildEnabled : bool , msbuildVersion : string option ) =
171- // let msbuildEnabled = msbuildEnabled && false
197+ let msbuildEnabled = msbuildEnabled && false
172198 let tryMSBuild v =
173199 if msbuildEnabled then
174200 // Detect if MSBuild v12 is on the machine, if so use the resolver from there
175- let mb = try System.Reflection. Assembly.Load( sprintf " Microsoft.Build.Framework, Version=%s .0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None
176- let ass = mb |> Option.bind ( fun _ -> try System.Reflection. Assembly.Load( sprintf " FSharp.Compiler.Service.MSBuild.v%s " v) |> Option.ofObj with _ -> None)
201+ let mb = try Assembly.Load( sprintf " Microsoft.Build.Framework, Version=%s .0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None
202+ let ass = mb |> Option.bind ( fun _ -> try Assembly.Load( sprintf " FSharp.Compiler.Service.MSBuild.v%s " v) |> Option.ofObj with _ -> None)
177203 let ty = ass |> Option.bind ( fun ass -> ass.GetType( " Microsoft.FSharp.Compiler.MSBuildReferenceResolver" ) |> Option.ofObj)
178- let obj = ty |> Option.bind ( fun ty -> ty.InvokeMember( " get_Resolver" , System.Reflection. BindingFlags.Static ||| System.Reflection. BindingFlags.Public ||| System.Reflection. BindingFlags.InvokeMethod ||| System.Reflection. BindingFlags.NonPublic, null , null , [| |]) |> Option.ofObj)
204+ let obj = ty |> Option.bind ( fun ty -> ty.InvokeMember( " get_Resolver" , BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null , null , [| |]) |> Option.ofObj)
179205 let resolver = obj |> Option.bind ( fun obj -> match obj with :? Resolver as r -> Some r | _ -> None)
180206 resolver
181207 else None
0 commit comments