From 3656cff99e42c114c5ed49cdc51985e63f7a04b8 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 16:40:22 +0100 Subject: [PATCH 01/19] preliminary dependency isolation work --- FSharp.Compiler.Service.sln | 20 +++++++++++++++++++ ...ssemblyinfo.FSharp.Compiler.Service.dll.fs | 6 ++++++ .../FSharp.Compiler.Service.fsproj | 18 ----------------- src/fsharp/MSBuildReferenceResolver.fs | 16 +++++++++++++++ src/fsharp/ReferenceResolver.fs | 11 ++++++++++ src/fsharp/fsi/fsi.fs | 2 +- src/fsharp/vs/SimpleServices.fs | 2 +- src/fsharp/vs/service.fs | 2 +- 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/FSharp.Compiler.Service.sln b/FSharp.Compiler.Service.sln index 8aed6fa713..955debaba8 100644 --- a/FSharp.Compiler.Service.sln +++ b/FSharp.Compiler.Service.sln @@ -81,6 +81,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{9020 nuget\projectcracker.template = nuget\projectcracker.template EndProjectSection EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.MSBuild.v12", "src\fsharp\FSharp.Compiler.Service.MSBuild.v12\FSharp.Compiler.Service.MSBuild.v12.fsproj", "{8157B50E-397D-4232-A4E0-1977AFC7076D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -283,6 +285,24 @@ Global {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Mixed Platforms.Build.0 = Release|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|x86.ActiveCfg = Release|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|x86.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|x86.ActiveCfg = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|x86.Build.0 = Debug|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Any CPU.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Any CPU.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Mixed Platforms.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|x86.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|x86.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Any CPU.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.ActiveCfg = Release|Any CPU + {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.fs b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.fs index a3a1114770..c4bd292e62 100755 --- a/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.fs +++ b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.fs @@ -10,6 +10,12 @@ open System.Runtime.InteropServices [] [] +[] +[] +[] +[] +[] +[] [] #if NO_STRONG_NAMES diff --git a/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj index ba9fc020f8..5bcee3dd45 100644 --- a/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj +++ b/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj @@ -604,9 +604,6 @@ Service/reshapedmsbuild.fs - - Service/MSBuildReferenceResolver.fs - Service/service.fsi @@ -633,21 +630,6 @@ - - True - - - True - - - True - - - True - - - True - False diff --git a/src/fsharp/MSBuildReferenceResolver.fs b/src/fsharp/MSBuildReferenceResolver.fs index a430cdcb5d..5046328ff4 100644 --- a/src/fsharp/MSBuildReferenceResolver.fs +++ b/src/fsharp/MSBuildReferenceResolver.fs @@ -180,15 +180,27 @@ module internal MSBuildReferenceResolver = | AssemblyFolders -> lineIfExists(resolvedPath) + lineIfExists(fusionName) +#if CROSS_PLATFORM_COMPILER + + "Found by AssemblyFolders registry key" +#else + (FSComp.SR.assemblyResolutionFoundByAssemblyFoldersKey()) +#endif | AssemblyFoldersEx -> lineIfExists(resolvedPath) + lineIfExists(fusionName) +#if CROSS_PLATFORM_COMPILER + + "Found by AssemblyFoldersEx registry key" +#else + (FSComp.SR.assemblyResolutionFoundByAssemblyFoldersExKey()) +#endif | TargetFrameworkDirectory -> lineIfExists(resolvedPath) + lineIfExists(fusionName) +#if CROSS_PLATFORM_COMPILER + + ".NET Framework" +#else + (FSComp.SR.assemblyResolutionNetFramework()) +#endif | Unknown -> // Unknown when resolved by plain directory search without help from MSBuild resolver. lineIfExists(resolvedPath) @@ -197,7 +209,11 @@ module internal MSBuildReferenceResolver = lineIfExists(fusionName) | GlobalAssemblyCache -> lineIfExists(fusionName) +#if CROSS_PLATFORM_COMPILER + + "Global Assembly Cache" +#else + (FSComp.SR.assemblyResolutionGAC())+ "\n" +#endif + lineIfExists(redist) | Path _ -> lineIfExists(resolvedPath) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index d9e48bcd69..1aa57a30cd 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -56,3 +56,14 @@ module internal ReferenceResolver = logwarning:(string->string->unit) * logerror:(string->string->unit) -> ResolvedFile[] + + let GetDefaultResolver() = + let msbuild12 = + let ass = System.Reflection.Assembly.Load("FSharp.Compiler.Service.MSBuild.v12") |> Option.ofObj + let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) + let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("Resolver",System.Reflection.BindingFlags.Static ||| System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.InvokeMethod ||| System.Reflection.BindingFlags.NonPublic, null, null, null) |> Option.ofObj) + let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) + resolver + match msbuild12 with + | None -> failwith "couldn't find FSharp.Compiler.Service.MSBuild.v12 resolver" + | Some r -> r \ No newline at end of file diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index 9a9100b3ea..e2270186ca 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -2374,7 +2374,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i if containsRequiredFiles then defaultFSharpBinariesDir else Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value - let referenceResolver = MSBuildReferenceResolver.Resolver + let referenceResolver = ReferenceResolver.GetDefaultResolver() let tcConfigB = TcConfigBuilder.CreateNew(referenceResolver, defaultFSharpBinariesDir, diff --git a/src/fsharp/vs/SimpleServices.fs b/src/fsharp/vs/SimpleServices.fs index 3a9fd3025d..dd4e4c58f3 100644 --- a/src/fsharp/vs/SimpleServices.fs +++ b/src/fsharp/vs/SimpleServices.fs @@ -113,7 +113,7 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices let checker = InteractiveChecker.Create() let fileversion = 0 let loadTime = DateTime.Now - let referenceResolver = MSBuildReferenceResolver.Resolver + let referenceResolver = ReferenceResolver.GetDefaultResolver() /// Tokenize a single line, returning token information and a tokenization state represented by an integer member x.TokenizeLine (line: string, state: int64) : FSharpTokenInfo[] * int64 = diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index 19c4401bc2..1ce458c8f9 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -2737,7 +2737,7 @@ type FSharpChecker(referenceResolver, projectCacheSize, keepAssemblyContents, ke /// Instantiate an interactive checker. static member Create(?projectCacheSize, ?keepAssemblyContents, ?keepAllBackgroundResolutions) = - let referenceResolver = MSBuildReferenceResolver.Resolver + let referenceResolver = ReferenceResolver.GetDefaultResolver() let keepAssemblyContents = defaultArg keepAssemblyContents false let keepAllBackgroundResolutions = defaultArg keepAllBackgroundResolutions true let projectCacheSizeReal = defaultArg projectCacheSize projectCacheSizeDefault From bb12ac92729d3779c416c3ca5f84b96d24421c43 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 16:46:27 +0100 Subject: [PATCH 02/19] fix build --- build.fsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index 52ca3cfdff..1bbf4a9736 100644 --- a/build.fsx +++ b/build.fsx @@ -322,7 +322,11 @@ Target "All.NetFx" DoNothing =?> ("All.NetCore", isDotnetSDKInstalled) ==> "All" -"NuGet.NetFx" +"All.NetCore" + ==> "Nuget.AddNetCore" + +"All.NetFx" + ==> "NuGet.NetFx" =?> ("Nuget.AddNetCore", isDotnetSDKInstalled) ==> "NuGet" From ee381faaac7bba8558ddc5e81c8b4299493787a6 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 20:07:32 +0100 Subject: [PATCH 03/19] fix build of nuget pkg --- build.fsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.fsx b/build.fsx index 1bbf4a9736..93542f58a9 100644 --- a/build.fsx +++ b/build.fsx @@ -282,12 +282,12 @@ Target "RunTests.NetCore" (fun _ -> Target "Nuget.AddNetCore" (fun _ -> do let nupkg = sprintf "../../../%s/FSharp.Compiler.Service.%s.nupkg" buildDir (release.AssemblyVersion) - let netcoreNupkg = sprintf "bin/Release/FSharp.Compiler.Service.%s.nupkg" (release.AssemblyVersion) + let netcoreNupkg = sprintf "bin/FSharp.Compiler.Service.%s.nupkg" (release.AssemblyVersion) runCmdIn "src/fsharp/FSharp.Compiler.Service" "dotnet" "mergenupkg --source %s --other %s --framework netstandard1.6" nupkg netcoreNupkg do let nupkg = sprintf "../../../%s/FSharp.Compiler.Service.ProjectCracker.%s.nupkg" buildDir (release.AssemblyVersion) - let netcoreNupkg = sprintf "bin/Release/FSharp.Compiler.Service.ProjectCracker.%s.nupkg" (release.AssemblyVersion) + let netcoreNupkg = sprintf "bin/FSharp.Compiler.Service.ProjectCracker.%s.nupkg" (release.AssemblyVersion) runCmdIn "src/fsharp/FSharp.Compiler.Service.ProjectCracker" "dotnet" "mergenupkg --source %s --other %s --framework netstandard1.6" nupkg netcoreNupkg ) From a37e29538d64b57f5cc6a4848ae256a064d09e2a Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 20:18:10 +0100 Subject: [PATCH 04/19] misc --- src/fsharp/ReferenceResolver.fs | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 1aa57a30cd..500aa567f5 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -57,11 +57,51 @@ module internal ReferenceResolver = logerror:(string->string->unit) -> ResolvedFile[] + open System + open System.IO + let ScriptingNaiveResolver = + { new Resolver with + member __.HighestInstalledNetFrameworkVersion() = "v4.5" + member __.DotNetFrameworkReferenceAssembliesRootDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, + outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = + + let searchPaths = + [ yield! targetFrameworkDirectories + if not (String.IsNullOrEmpty(rawFileName)) then + let rawDir = Path.GetDirectoryName(rawFileName) + if not (String.IsNullOrEmpty(Path.GetDirectoryName(rawFileName))) then + yield rawDir + yield! explicitIncludeDirs + yield fsharpCoreDir + yield implicitIncludeDir + for reg in + "Software\Microsoft\.NetFramework", "AssemblyFoldersEx" , "" +[sprintf "{Registry:%s,%s,%s%s}" frameworkRegistryBase targetFrameworkVersion assemblyFoldersSuffix assemblyFoldersConditions] @ // Like {Registry:Software\Microsoft\.NETFramework,v2.0,AssemblyFoldersEx} + ["{AssemblyFolders}"] @ + ["{GAC}"] @ + // use path to implementation assemblies as the last resort + GetPathToDotNetFrameworkImlpementationAssemblies targetFrameworkVersion + for dir in + (// These are search paths for compile-like resolution. GAC searching is not present. + ["{TargetFrameworkDirectory}"] @ + rawFileNamePath @ // Quick-resolve straight to filename first + explicitIncludeDirs @ // From -I, #I + [fsharpCoreDir] @ // Location of explicit reference to FSharp.Core, otherwise location of fsc.exe + [implicitIncludeDir] @ // Usually the project directory + [sprintf "{Registry:%s,%s,%s%s}" frameworkRegistryBase targetFrameworkVersion assemblyFoldersSuffix assemblyFoldersConditions] @ // Like {Registry:Software\Microsoft\.NETFramework,v2.0,AssemblyFoldersEx} + ["{AssemblyFolders}"] @ + [outputDirectory] @ + ["{GAC}"] @ + // use path to implementation assemblies as the last resort + GetPathToDotNetFrameworkImlpementationAssemblies targetFrameworkVersion + + let GetDefaultResolver() = let msbuild12 = let ass = System.Reflection.Assembly.Load("FSharp.Compiler.Service.MSBuild.v12") |> Option.ofObj let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) - let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("Resolver",System.Reflection.BindingFlags.Static ||| System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.InvokeMethod ||| System.Reflection.BindingFlags.NonPublic, null, null, null) |> Option.ofObj) + 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) let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) resolver match msbuild12 with From a43e31bbf97b7e492e9da7233e6b0636a8ceabf4 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 20:38:12 +0100 Subject: [PATCH 05/19] add files --- nuget/FSharp.Compiler.Service.template | 1 + ...FSharp.Compiler.Service.MSBuild.v12.fsproj | 116 ++++++++++++++++++ .../paket.references | 0 .../project.json | 56 +++++++++ 4 files changed, 173 insertions(+) create mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj create mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v12/paket.references create mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v12/project.json diff --git a/nuget/FSharp.Compiler.Service.template b/nuget/FSharp.Compiler.Service.template index 9c3b7a4eda..0dfc5c1089 100644 --- a/nuget/FSharp.Compiler.Service.template +++ b/nuget/FSharp.Compiler.Service.template @@ -19,6 +19,7 @@ files ../bin/v4.5/FSharp.Compiler.Service.xml ==> lib/net45 ../bin/v4.5/FSharp.Compiler.Service.?db ==> lib/net45 ../bin/v4.5/FSharp.Compiler.Service.dll.?db ==> lib/net45 + ../bin/v4.5/FSharp.Compiler.Service.MSBuild.v12.dll ==> lib/net45 dependencies System.Collections.Immutable >= LOCKEDVERSION System.Reflection.Metadata >= LOCKEDVERSION \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj new file mode 100644 index 0000000000..8ed6b4b3ae --- /dev/null +++ b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj @@ -0,0 +1,116 @@ + + + + + Debug + AnyCPU + Library + FSharp.Compiler.Service.MSBuild.v12 + $(NoWarn);44;62;9 + {8157b50e-397d-4232-a4e0-1977afc7076d} + true + v4.5 + 0x06800000 + $(OtherFlags) /warnon:1182 + true + true + $(OtherFlags) --times + $(NoWarn);69;65;54;61;75 + true + ..\..\..\bin\$(TargetFrameworkVersion) + $(OutputPath)$(AssemblyName).xml + $(DefineConstants);CROSS_PLATFORM_COMPILER + $(DefineConstants);FX_ATLEAST_45 + $(DefineConstants);FX_ATLEAST_40 + $(DefineConstants);FX_MSBUILDRESOLVER_RUNTIMELIKE + 4.4.0.0 + $(MSBuildProjectDirectory)\..\..\..\ + + false + true + AnyCPU + + + $(SolutionDir)lib\bootstrap\4.0 + $(SolutionDir)packages\FsSrGen\lib\net46 + $(FsLexYaccPath) + $(FsLexYaccPath) + fslex.exe + fsyacc.exe + false + + + + DEBUG; $(DefineConstants) + false + $(OtherFlags) --no-jit-optimize --jit-tracking + + + true + + + + AssemblyInfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v12.dll.fs + + + AssemblyInfo/assemblyinfo.shared.fs + + + Service/MSBuildReferenceResolver.fs + + + + + + + + + + + True + + + True + + + True + + + True + + + True + + + False + + + FSharp.Compiler.Service + {2e4d67b4-522d-4cf7-97e4-ba940f0b18f3} + True + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + + + + + + \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/paket.references b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/paket.references new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/project.json b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/project.json new file mode 100644 index 0000000000..7e75972caa --- /dev/null +++ b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/project.json @@ -0,0 +1,56 @@ +{ + "version": "8.0.0", + "buildOptions": { + "debugType": "portable", + "compilerName": "fsc", + "compile": { + "includeFiles": [ + "../../assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.MSBuild.v12.fs", + "../../assemblyinfo/assemblyinfo.shared.fs", + "../../utils/reshapedmsbuild.fs", + "../MSBuildReferenceResolver.fs" + ] + }, + "define": [ + "FX_ATLEAST_35", + "FX_ATLEAST_40", + "FX_ATLEAST_45", + "FX_ATLEAST_LINQ", + "FX_ATLEAST_PORTABLE", + "TODO_REWORK_ASSEMBLY_LOAD" + ], + "xmlDoc": true, + "delaySign": true, + "warningsAsErrors": true + }, + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.Diagnostics.TraceSource": "4.0.0", + "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", + "System.Collections.Immutable": "1.2.0", + "System.Security.Cryptography.Algorithms": "4.2.0", + "System.Security.Cryptography.Primitives": "4.0.0", + "System.Reflection.Metadata": "1.4.1-beta-24227-04", + "System.Diagnostics.Process": "4.1.0", + "FSharp.Compiler.Service": { + "version": "8.0.0", + "target": "project" + } + }, + "tools": { + "dotnet-fssrgen": "3.2.*", + "dotnet-mergenupkg": { "version": "1.0.*" }, + "dotnet-compile-fsc": { + "version": "1.0.0-preview2-*", + "imports": "dnxcore50" + } + }, + "frameworks": { + "netstandard1.6": { + "imports": [ + "portable-net45+win81", + "dnxcore50" + ] + } + } +} From 59971b3e65935f7c6322a8c7997fed64f965e418 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 21:47:43 +0100 Subject: [PATCH 06/19] missing file --- ...info.FSharp.Compiler.Service.MSBuild.v12.dll.fs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v12.dll.fs diff --git a/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v12.dll.fs b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v12.dll.fs new file mode 100644 index 0000000000..c7f68fe89a --- /dev/null +++ b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v12.dll.fs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.FSharp +open System.Reflection +open System.Runtime.InteropServices + +[] +[] +[] +[] + +[] +[] +do() From 5083343d288729514fadcb28e6b1c0340374e25a Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 22:53:30 +0100 Subject: [PATCH 07/19] default resolver --- FSharp.Compiler.Service.sln | 86 +---- ...FSharp.Compiler.Service.MSBuild.v14.dll.fs | 14 + ...FSharp.Compiler.Service.MSBuild.v12.fsproj | 13 +- ...FSharp.Compiler.Service.MSBuild.v14.fsproj | 105 +++++++ .../project.json | 56 ++++ src/fsharp/ReferenceResolver.fs | 297 +++++++++++------- src/fsharp/fsi/fsi.fs | 13 +- src/fsharp/fsi/fsi.fsi | 8 +- src/fsharp/vs/SimpleServices.fs | 6 +- src/fsharp/vs/service.fs | 6 +- src/fsharp/vs/service.fsi | 4 +- 11 files changed, 399 insertions(+), 209 deletions(-) create mode 100644 src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs create mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj create mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json diff --git a/FSharp.Compiler.Service.sln b/FSharp.Compiler.Service.sln index 955debaba8..614a721932 100644 --- a/FSharp.Compiler.Service.sln +++ b/FSharp.Compiler.Service.sln @@ -83,14 +83,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{9020 EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.MSBuild.v12", "src\fsharp\FSharp.Compiler.Service.MSBuild.v12\FSharp.Compiler.Service.MSBuild.v12.fsproj", "{8157B50E-397D-4232-A4E0-1977AFC7076D}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.MSBuild.v14", "src\fsharp\FSharp.Compiler.Service.MSBuild.v14\FSharp.Compiler.Service.MSBuild.v14.fsproj", "{43393416-DA88-4286-8D5A-3D2BB3686BBA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|Mixed Platforms = Debug|Mixed Platforms Debug|x86 = Debug|x86 - Proto|Any CPU = Proto|Any CPU - Proto|Mixed Platforms = Proto|Mixed Platforms - Proto|x86 = Proto|x86 Release|Any CPU = Release|Any CPU Release|Mixed Platforms = Release|Mixed Platforms Release|x86 = Release|x86 @@ -102,12 +101,6 @@ Global {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|x86.ActiveCfg = Debug|Any CPU {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|x86.Build.0 = Debug|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Any CPU.Build.0 = Release|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|x86.ActiveCfg = Release|Any CPU - {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|x86.Build.0 = Release|Any CPU {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.Build.0 = Release|Any CPU {2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -119,11 +112,6 @@ Global {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Debug|x86.ActiveCfg = Debug|Any CPU - {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Proto|Any CPU.Build.0 = Release|Any CPU - {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Proto|x86.ActiveCfg = Release|Any CPU {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Release|Any CPU.ActiveCfg = Release|Any CPU {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Release|Any CPU.Build.0 = Release|Any CPU {A40507D6-FA48-43D3-B18A-AE3DAACE4020}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -134,11 +122,6 @@ Global {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Debug|x86.ActiveCfg = Debug|Any CPU - {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Proto|Any CPU.Build.0 = Release|Any CPU - {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Proto|x86.ActiveCfg = Release|Any CPU {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Release|Any CPU.ActiveCfg = Release|Any CPU {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Release|Any CPU.Build.0 = Release|Any CPU {067E95E5-E3DC-4CA7-813A-4D1E277D2D52}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -149,11 +132,6 @@ Global {92793069-816F-4F69-84AC-0966F8275E65}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {92793069-816F-4F69-84AC-0966F8275E65}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {92793069-816F-4F69-84AC-0966F8275E65}.Debug|x86.ActiveCfg = Debug|Any CPU - {92793069-816F-4F69-84AC-0966F8275E65}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {92793069-816F-4F69-84AC-0966F8275E65}.Proto|Any CPU.Build.0 = Release|Any CPU - {92793069-816F-4F69-84AC-0966F8275E65}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {92793069-816F-4F69-84AC-0966F8275E65}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {92793069-816F-4F69-84AC-0966F8275E65}.Proto|x86.ActiveCfg = Release|Any CPU {92793069-816F-4F69-84AC-0966F8275E65}.Release|Any CPU.ActiveCfg = Release|Any CPU {92793069-816F-4F69-84AC-0966F8275E65}.Release|Any CPU.Build.0 = Release|Any CPU {92793069-816F-4F69-84AC-0966F8275E65}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -164,11 +142,6 @@ Global {C816728D-BBEA-472D-9F6C-E8913957A673}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {C816728D-BBEA-472D-9F6C-E8913957A673}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {C816728D-BBEA-472D-9F6C-E8913957A673}.Debug|x86.ActiveCfg = Debug|Any CPU - {C816728D-BBEA-472D-9F6C-E8913957A673}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {C816728D-BBEA-472D-9F6C-E8913957A673}.Proto|Any CPU.Build.0 = Release|Any CPU - {C816728D-BBEA-472D-9F6C-E8913957A673}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {C816728D-BBEA-472D-9F6C-E8913957A673}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {C816728D-BBEA-472D-9F6C-E8913957A673}.Proto|x86.ActiveCfg = Release|Any CPU {C816728D-BBEA-472D-9F6C-E8913957A673}.Release|Any CPU.ActiveCfg = Release|Any CPU {C816728D-BBEA-472D-9F6C-E8913957A673}.Release|Any CPU.Build.0 = Release|Any CPU {C816728D-BBEA-472D-9F6C-E8913957A673}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -179,11 +152,6 @@ Global {5EF9FF95-1C75-458A-983A-168E43945913}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {5EF9FF95-1C75-458A-983A-168E43945913}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {5EF9FF95-1C75-458A-983A-168E43945913}.Debug|x86.ActiveCfg = Debug|Any CPU - {5EF9FF95-1C75-458A-983A-168E43945913}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {5EF9FF95-1C75-458A-983A-168E43945913}.Proto|Any CPU.Build.0 = Release|Any CPU - {5EF9FF95-1C75-458A-983A-168E43945913}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {5EF9FF95-1C75-458A-983A-168E43945913}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {5EF9FF95-1C75-458A-983A-168E43945913}.Proto|x86.ActiveCfg = Release|Any CPU {5EF9FF95-1C75-458A-983A-168E43945913}.Release|Any CPU.ActiveCfg = Release|Any CPU {5EF9FF95-1C75-458A-983A-168E43945913}.Release|Any CPU.Build.0 = Release|Any CPU {5EF9FF95-1C75-458A-983A-168E43945913}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -194,11 +162,6 @@ Global {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Debug|x86.ActiveCfg = Debug|Any CPU - {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Proto|Any CPU.Build.0 = Release|Any CPU - {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Proto|x86.ActiveCfg = Release|Any CPU {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Release|Any CPU.ActiveCfg = Release|Any CPU {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Release|Any CPU.Build.0 = Release|Any CPU {C94C257C-3C0A-4858-B5D8-D746498D1F08}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -209,11 +172,6 @@ Global {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Debug|x86.ActiveCfg = Debug|Any CPU - {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Proto|Any CPU.Build.0 = Release|Any CPU - {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Proto|x86.ActiveCfg = Release|Any CPU {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Release|Any CPU.Build.0 = Release|Any CPU {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -225,12 +183,6 @@ Global {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Debug|x86.ActiveCfg = Debug|Any CPU {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Debug|x86.Build.0 = Debug|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|Any CPU.Build.0 = Release|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|x86.ActiveCfg = Release|Any CPU - {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Proto|x86.Build.0 = Release|Any CPU {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Release|Any CPU.ActiveCfg = Release|Any CPU {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Release|Any CPU.Build.0 = Release|Any CPU {F9540CA8-1CE0-4546-A23A-A461E416E95B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -242,11 +194,6 @@ Global {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Debug|x86.ActiveCfg = Debug|Any CPU - {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Proto|Any CPU.Build.0 = Release|Any CPU - {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Proto|x86.ActiveCfg = Release|Any CPU {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Release|Any CPU.Build.0 = Release|Any CPU {B1BDD96D-47E1-4E65-8107-FBAE23A06DB4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -257,11 +204,6 @@ Global {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Debug|x86.ActiveCfg = Debug|Any CPU - {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Proto|Any CPU.Build.0 = Release|Any CPU - {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Proto|x86.ActiveCfg = Release|Any CPU {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|Any CPU.ActiveCfg = Release|Any CPU {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|Any CPU.Build.0 = Release|Any CPU {893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -273,12 +215,6 @@ Global {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|x86.ActiveCfg = Debug|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|x86.Build.0 = Debug|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Any CPU.Build.0 = Release|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|x86.ActiveCfg = Release|Any CPU - {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|x86.Build.0 = Release|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Any CPU.Build.0 = Release|Any CPU {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU @@ -291,18 +227,24 @@ Global {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|x86.ActiveCfg = Debug|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Debug|x86.Build.0 = Debug|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Any CPU.ActiveCfg = Release|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Any CPU.Build.0 = Release|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|Mixed Platforms.Build.0 = Release|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|x86.ActiveCfg = Release|Any CPU - {8157B50E-397D-4232-A4E0-1977AFC7076D}.Proto|x86.Build.0 = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Any CPU.ActiveCfg = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Any CPU.Build.0 = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.ActiveCfg = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.Build.0 = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|x86.ActiveCfg = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|x86.Build.0 = Debug|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Any CPU.Build.0 = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|x86.ActiveCfg = Release|Any CPU + {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs new file mode 100644 index 0000000000..4eddab4910 --- /dev/null +++ b/src/assemblyinfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.FSharp +open System.Reflection +open System.Runtime.InteropServices + +[] +[] +[] +[] + +[] +[] +do() diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj index 8ed6b4b3ae..b5d6cf9cff 100644 --- a/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj +++ b/src/fsharp/FSharp.Compiler.Service.MSBuild.v12/FSharp.Compiler.Service.MSBuild.v12.fsproj @@ -27,7 +27,7 @@ $(NoWarn);69;65;54;61;75 true ..\..\..\bin\$(TargetFrameworkVersion) - $(OutputPath)$(AssemblyName).xml + $(OutputPath)\$(AssemblyName).xml $(DefineConstants);CROSS_PLATFORM_COMPILER $(DefineConstants);FX_ATLEAST_45 $(DefineConstants);FX_ATLEAST_40 @@ -39,15 +39,6 @@ true AnyCPU - - $(SolutionDir)lib\bootstrap\4.0 - $(SolutionDir)packages\FsSrGen\lib\net46 - $(FsLexYaccPath) - $(FsLexYaccPath) - fslex.exe - fsyacc.exe - false - DEBUG; $(DefineConstants) @@ -110,7 +101,5 @@ - - \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj new file mode 100644 index 0000000000..ac423f511d --- /dev/null +++ b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj @@ -0,0 +1,105 @@ + + + + + Debug + AnyCPU + Library + FSharp.Compiler.Service.MSBuild.v14 + $(NoWarn);44;62;9 + {43393416-da88-4286-8d5a-3d2bb3686bba} + true + v4.5 + 0x06800000 + $(OtherFlags) /warnon:1182 + true + true + $(OtherFlags) --times + $(NoWarn);69;65;54;61;75 + true + ..\..\..\bin\$(TargetFrameworkVersion) + $(OutputPath)\$(AssemblyName).xml + $(DefineConstants);CROSS_PLATFORM_COMPILER + $(DefineConstants);FX_ATLEAST_45 + $(DefineConstants);FX_ATLEAST_40 + $(DefineConstants);FX_MSBUILDRESOLVER_RUNTIMELIKE + 4.4.0.0 + $(MSBuildProjectDirectory)\..\..\..\ + + false + true + AnyCPU + + + + DEBUG; $(DefineConstants) + false + $(OtherFlags) --no-jit-optimize --jit-tracking + + + true + + + + AssemblyInfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs + + + AssemblyInfo/assemblyinfo.shared.fs + + + Service/MSBuildReferenceResolver.fs + + + + + + + + + + + True + + + True + + + True + + + True + + + True + + + False + + + FSharp.Compiler.Service + {2e4d67b4-522d-4cf7-97e4-ba940f0b18f3} + True + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + + + + \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json new file mode 100644 index 0000000000..9be378dfa5 --- /dev/null +++ b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json @@ -0,0 +1,56 @@ +{ + "version": "8.0.0", + "buildOptions": { + "debugType": "portable", + "compilerName": "fsc", + "compile": { + "includeFiles": [ + "../../assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.MSBuild.v14.fs", + "../../assemblyinfo/assemblyinfo.shared.fs", + "../../utils/reshapedmsbuild.fs", + "../MSBuildReferenceResolver.fs" + ] + }, + "define": [ + "FX_ATLEAST_35", + "FX_ATLEAST_40", + "FX_ATLEAST_45", + "FX_ATLEAST_LINQ", + "FX_ATLEAST_PORTABLE", + "TODO_REWORK_ASSEMBLY_LOAD" + ], + "xmlDoc": true, + "delaySign": true, + "warningsAsErrors": true + }, + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.Diagnostics.TraceSource": "4.0.0", + "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", + "System.Collections.Immutable": "1.2.0", + "System.Security.Cryptography.Algorithms": "4.2.0", + "System.Security.Cryptography.Primitives": "4.0.0", + "System.Reflection.Metadata": "1.4.1-beta-24227-04", + "System.Diagnostics.Process": "4.1.0", + "FSharp.Compiler.Service": { + "version": "8.0.0", + "target": "project" + } + }, + "tools": { + "dotnet-fssrgen": "3.2.*", + "dotnet-mergenupkg": { "version": "1.0.*" }, + "dotnet-compile-fsc": { + "version": "1.0.0-preview2-*", + "imports": "dnxcore50" + } + }, + "frameworks": { + "netstandard1.6": { + "imports": [ + "portable-net45+win81", + "dnxcore50" + ] + } + } +} diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 500aa567f5..19dcc945c3 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -1,109 +1,194 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.FSharp.Compiler - -module internal ReferenceResolver = - - exception ResolutionFailure - - type ResolutionEnvironment = - /// Indicates a script or source being compiled - | CompileTimeLike - /// Indicates a script or source being interpreted - | RuntimeLike - /// Indicates a script or source being edited - | DesignTimeLike - - type ResolvedFile = - { /// Item specification. - itemSpec:string - /// Prepare textual information about where the assembly was resolved from, used for tooltip output - prepareToolTip: string * string -> string - /// Round-tripped baggage - baggage:string - } - - override this.ToString() = sprintf "ResolvedFile(%s)" this.itemSpec - - type Resolver = - /// Get the "v4.5.1"-style moniker for the highest installed .NET Framework version. - /// This is the value passed back to Resolve if no explicit "mscorlib" has been given. - /// - /// Note: If an explicit "mscorlib" is given, then --noframework is being used, and the whole ReferenceResolver logic is essentially - /// unused. However in the future an option may be added to allow an expicit specification of - /// a .NET Framework version to use for scripts. - abstract HighestInstalledNetFrameworkVersion : unit -> string +#if INTERACTIVE +#load "../utils/ResizeArray.fs" +#load "../absil/illib.fs" +#else +module Microsoft.FSharp.Compiler.ReferenceResolver +#endif + +open System +open System.IO +open System.Reflection +open Microsoft.Win32 + +exception ResolutionFailure +open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library + +type ResolutionEnvironment = + /// Indicates a script or source being compiled + | CompileTimeLike + /// Indicates a script or source being interpreted + | RuntimeLike + /// Indicates a script or source being edited + | DesignTimeLike + +type ResolvedFile = + { /// Item specification. + itemSpec:string + /// Prepare textual information about where the assembly was resolved from, used for tooltip output + prepareToolTip: string * string -> string + /// Round-tripped baggage + baggage:string + } + + override this.ToString() = sprintf "ResolvedFile(%s)" this.itemSpec + +type Resolver = + /// Get the "v4.5.1"-style moniker for the highest installed .NET Framework version. + /// This is the value passed back to Resolve if no explicit "mscorlib" has been given. + /// + /// Note: If an explicit "mscorlib" is given, then --noframework is being used, and the whole ReferenceResolver logic is essentially + /// unused. However in the future an option may be added to allow an expicit specification of + /// a .NET Framework version to use for scripts. + abstract HighestInstalledNetFrameworkVersion : unit -> string - /// Get the Reference Assemblies directory for the .NET Framework (on Windows) - /// This is added to the default resolution path for - /// design-time compilations. - abstract DotNetFrameworkReferenceAssembliesRootDirectory : string - - /// Perform assembly resolution on the given references under the given conditions - abstract Resolve : - resolutionEnvironment: ResolutionEnvironment * - // The actual reference paths or assemby name text, plus baggage - references:(string (* baggage *) * string)[] * - // e.g. v4.5.1 - targetFrameworkVersion:string * - targetFrameworkDirectories:string list * - targetProcessorArchitecture:string * - outputDirectory: string * - fsharpCoreDir:string * - explicitIncludeDirs:string list * - implicitIncludeDir:string * - logmessage:(string->unit) * - logwarning:(string->string->unit) * - logerror:(string->string->unit) - -> ResolvedFile[] - - open System - open System.IO - let ScriptingNaiveResolver = - { new Resolver with - member __.HighestInstalledNetFrameworkVersion() = "v4.5" - member __.DotNetFrameworkReferenceAssembliesRootDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() - member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, - outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = - - let searchPaths = - [ yield! targetFrameworkDirectories - if not (String.IsNullOrEmpty(rawFileName)) then - let rawDir = Path.GetDirectoryName(rawFileName) - if not (String.IsNullOrEmpty(Path.GetDirectoryName(rawFileName))) then - yield rawDir - yield! explicitIncludeDirs - yield fsharpCoreDir - yield implicitIncludeDir - for reg in - "Software\Microsoft\.NetFramework", "AssemblyFoldersEx" , "" -[sprintf "{Registry:%s,%s,%s%s}" frameworkRegistryBase targetFrameworkVersion assemblyFoldersSuffix assemblyFoldersConditions] @ // Like {Registry:Software\Microsoft\.NETFramework,v2.0,AssemblyFoldersEx} - ["{AssemblyFolders}"] @ - ["{GAC}"] @ - // use path to implementation assemblies as the last resort - GetPathToDotNetFrameworkImlpementationAssemblies targetFrameworkVersion - for dir in - (// These are search paths for compile-like resolution. GAC searching is not present. - ["{TargetFrameworkDirectory}"] @ - rawFileNamePath @ // Quick-resolve straight to filename first - explicitIncludeDirs @ // From -I, #I - [fsharpCoreDir] @ // Location of explicit reference to FSharp.Core, otherwise location of fsc.exe - [implicitIncludeDir] @ // Usually the project directory - [sprintf "{Registry:%s,%s,%s%s}" frameworkRegistryBase targetFrameworkVersion assemblyFoldersSuffix assemblyFoldersConditions] @ // Like {Registry:Software\Microsoft\.NETFramework,v2.0,AssemblyFoldersEx} - ["{AssemblyFolders}"] @ - [outputDirectory] @ - ["{GAC}"] @ - // use path to implementation assemblies as the last resort - GetPathToDotNetFrameworkImlpementationAssemblies targetFrameworkVersion - - - let GetDefaultResolver() = - let msbuild12 = - let ass = System.Reflection.Assembly.Load("FSharp.Compiler.Service.MSBuild.v12") |> Option.ofObj - let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) - 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) - let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) - resolver - match msbuild12 with - | None -> failwith "couldn't find FSharp.Compiler.Service.MSBuild.v12 resolver" - | Some r -> r \ No newline at end of file + /// Get the Reference Assemblies directory for the .NET Framework (on Windows) + /// This is added to the default resolution path for + /// design-time compilations. + abstract DotNetFrameworkReferenceAssembliesRootDirectory : string + + /// Perform assembly resolution on the given references under the given conditions + abstract Resolve : + resolutionEnvironment: ResolutionEnvironment * + // The actual reference paths or assemby name text, plus baggage + references:(string (* baggage *) * string)[] * + // e.g. v4.5.1 + targetFrameworkVersion:string * + targetFrameworkDirectories:string list * + targetProcessorArchitecture:string * + outputDirectory: string * + fsharpCoreDir:string * + explicitIncludeDirs:string list * + implicitIncludeDir:string * + logmessage:(string->unit) * + logwarning:(string->string->unit) * + logerror:(string->string->unit) + -> ResolvedFile[] + +let ScriptingNaiveResolver = + { new Resolver with + member __.HighestInstalledNetFrameworkVersion() = "v4.5" + member __.DotNetFrameworkReferenceAssembliesRootDirectory = + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\Framework\.NETFramework" + else + "" + + member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, + outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = + + let registrySearchPaths() = + [ let registryKey = @"Software\Microsoft\.NetFramework"; + use key = Registry.LocalMachine.OpenSubKey(registryKey) + match key with + | null -> () + | _ -> + for subKeyName in key.GetSubKeyNames() do + use subKey = key.OpenSubKey(subKeyName) + use subSubKey = subKey.OpenSubKey("AssemblyFoldersEx") + match subSubKey with + | null -> () + | _ -> + for subSubSubKeyName in subSubKey.GetSubKeyNames() do + use subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) + match subSubSubKey.GetValue(null) with + | :? string as s -> yield s + | _ -> () + use subSubKey = key.OpenSubKey("AssemblyFolders") + match subSubKey with + | null -> () + | _ -> + for subSubSubKeyName in subSubKey.GetSubKeyNames() do + let subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) + match subSubSubKey.GetValue(null) with + | :? string as s -> yield s + | _ -> () ] + + + let searchPaths = + [ yield! targetFrameworkDirectories + yield! explicitIncludeDirs + yield fsharpCoreDir + yield implicitIncludeDir + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then + yield! registrySearchPaths() ] + + [| for (baggage,r) in references do + let mutable found = false + let success path = + if not found then + found <- true + [ { itemSpec = path; prepareToolTip = snd; baggage=baggage } ] + else [] + if Path.IsPathRooted(r) then + if FileSystem.SafeExists(r) then + yield! success r + else + let isFileName = + r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || + r.EndsWith("exe",StringComparison.InvariantCultureIgnoreCase) + + let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" + + for searchPath in searchPaths do + if not found then + let trialPath = Path.Combine(searchPath,qual) + if FileSystem.SafeExists(trialPath) then + yield! success trialPath + if not found then + let ass = try Some (System.Reflection.Assembly.ReflectionOnlyLoad(r)) with _ -> None + match ass with + | None -> () + | Some ass -> yield! success ass.Location |] } + +#if INTERACTIVE +ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory +ScriptingNaiveResolver.HighestInstalledNetFrameworkVersion() + +let fscoreDir = + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" + else + System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + +let resolve s = + ScriptingNaiveResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> ("", a) |],"v4.5.1", [ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + +resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] + +#endif + +let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = + let msbuildEnabled = msbuildEnabled && false + let tryMSBuild v = + if msbuildEnabled then + // Detect if MSBuild v12 is on the machine, if so use the resolver from there + 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 + let ass = mb |> Option.bind (fun _ -> try System.Reflection.Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) + let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) + 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) + let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) + resolver + else None + match tryMSBuild (defaultArg msbuildVersion "12") with + | Some r -> r + | None -> + //match tryMSBuild "15" with + //| Some r -> r + //| None -> + //match tryMSBuild "14" with + //| Some r -> r + //| None -> + match tryMSBuild "12" with + | Some r -> r + | None -> + ScriptingNaiveResolver diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index e2270186ca..d32cb46899 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -2317,7 +2317,7 @@ let internal DriveFsiEventLoop (fsi: FsiEvaluationSessionHostConfig, fsiConsoleO /// The primary type, representing a full F# Interactive session, reading from the given /// text input, writing to the given text output and error writers. -type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], inReader:TextReader, outWriter:TextWriter, errorWriter: TextWriter, fsiCollectible: bool) = +type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], inReader:TextReader, outWriter:TextWriter, errorWriter: TextWriter, fsiCollectible: bool, msbuildEnabled: bool, msbuildVersion: string option) = #if DYNAMIC_CODE_REWRITES_CONSOLE_WRITE do Microsoft.FSharp.Core.Printf.setWriter outWriter @@ -2374,7 +2374,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i if containsRequiredFiles then defaultFSharpBinariesDir else Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value - let referenceResolver = ReferenceResolver.GetDefaultResolver() + let referenceResolver = ReferenceResolver.GetDefaultResolver(msbuildEnabled, msbuildVersion) let tcConfigB = TcConfigBuilder.CreateNew(referenceResolver, defaultFSharpBinariesDir, @@ -2721,12 +2721,9 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i GC.KeepAlive fsiInterruptController.EventHandlers - new (fsiConfig, argv, inReader, outWriter, errorWriter) = - new FsiEvaluationSession (fsiConfig, argv, inReader, outWriter, errorWriter, fsiCollectible=false) - - static member Create(fsiConfig, argv, inReader, outWriter, errorWriter, ?collectible) = - new FsiEvaluationSession(fsiConfig, argv, inReader, outWriter, errorWriter, defaultArg collectible false) - + static member Create(fsiConfig, argv, inReader, outWriter, errorWriter, ?collectible, ?msbuildEnabled, ?msbuildVersion) = + new FsiEvaluationSession(fsiConfig, argv, inReader, outWriter, errorWriter, defaultArg collectible false, defaultArg msbuildEnabled true, msbuildVersion) + static member GetDefaultConfiguration(fsiObj:obj) = FsiEvaluationSession.GetDefaultConfiguration(fsiObj, true) static member GetDefaultConfiguration(fsiObj:obj, useFsiAuxLib) = diff --git a/src/fsharp/fsi/fsi.fsi b/src/fsharp/fsi/fsi.fsi index c76e54a987..11d73cf297 100644 --- a/src/fsharp/fsi/fsi.fsi +++ b/src/fsharp/fsi/fsi.fsi @@ -110,14 +110,11 @@ type public FsiEvaluationSessionHostConfig = /// Represents an F# Interactive evaluation session. +[] type FsiEvaluationSession = interface System.IDisposable - /// Create an FsiEvaluationSession, reading from the given text input, writing to the given text output and error writers. - [] - new : fsiConfig: FsiEvaluationSessionHostConfig * argv:string[] * inReader:TextReader * outWriter:TextWriter * errorWriter: TextWriter -> FsiEvaluationSession - /// Create an FsiEvaluationSession, reading from the given text input, writing to the given text output and error writers. /// /// Create an FsiEvaluationSession, reading from the given text input, writing to the given text output and error writers @@ -127,7 +124,7 @@ type FsiEvaluationSession = /// Read input from the given reader /// Write output to the given writer /// Optionally make the dynamic assmbly for the session collectible - static member Create : fsiConfig: FsiEvaluationSessionHostConfig * argv:string[] * inReader:TextReader * outWriter:TextWriter * errorWriter: TextWriter * ?collectible: bool -> FsiEvaluationSession + static member Create : fsiConfig: FsiEvaluationSessionHostConfig * argv:string[] * inReader:TextReader * outWriter:TextWriter * errorWriter: TextWriter * ?collectible: bool * ?msbuildEnabled: bool * ?msbuildVersion: string -> FsiEvaluationSession /// A host calls this to request an interrupt on the evaluation thread. member Interrupt : unit -> unit @@ -256,6 +253,7 @@ type FsiEvaluationSession = static member GetDefaultConfiguration: unit -> FsiEvaluationSessionHostConfig + /// A default implementation of the 'fsi' object, used by GetDefaultConfiguration() module Settings = /// An event loop used by the currently executing F# Interactive session to execute code diff --git a/src/fsharp/vs/SimpleServices.fs b/src/fsharp/vs/SimpleServices.fs index dd4e4c58f3..388ce543a9 100644 --- a/src/fsharp/vs/SimpleServices.fs +++ b/src/fsharp/vs/SimpleServices.fs @@ -108,12 +108,12 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices member x.GetDeclarations(line, col, qualifyingNames, partialName, ?xmlCommentRetriever) = x.GetDeclarationListInfo(Line.fromZ line, col, qualifyingNames, partialName, ?xmlCommentRetriever=xmlCommentRetriever) /// Provides simple services for checking and compiling F# scripts - type public SimpleSourceCodeServices() = + type public SimpleSourceCodeServices(?msbuildEnabled, ?msbuildVersion) = - let checker = InteractiveChecker.Create() + let checker = InteractiveChecker.Create(?msbuildEnabled=msbuildEnabled, ?msbuildVersion=msbuildVersion) let fileversion = 0 let loadTime = DateTime.Now - let referenceResolver = ReferenceResolver.GetDefaultResolver() + let referenceResolver = checker.ReferenceResolver /// Tokenize a single line, returning token information and a tokenization state represented by an integer member x.TokenizeLine (line: string, state: int64) : FSharpTokenInfo[] * int64 = diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index 1ce458c8f9..03f2e57b4a 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -2736,13 +2736,15 @@ type FSharpChecker(referenceResolver, projectCacheSize, keepAssemblyContents, ke let maxMemEvent = new Event() /// Instantiate an interactive checker. - static member Create(?projectCacheSize, ?keepAssemblyContents, ?keepAllBackgroundResolutions) = - let referenceResolver = ReferenceResolver.GetDefaultResolver() + static member Create(?projectCacheSize, ?keepAssemblyContents, ?keepAllBackgroundResolutions, ?msbuildEnabled, ?msbuildVersion) = + let referenceResolver = ReferenceResolver.GetDefaultResolver(defaultArg msbuildEnabled true, msbuildVersion) let keepAssemblyContents = defaultArg keepAssemblyContents false let keepAllBackgroundResolutions = defaultArg keepAllBackgroundResolutions true let projectCacheSizeReal = defaultArg projectCacheSize projectCacheSizeDefault new FSharpChecker(referenceResolver, projectCacheSizeReal,keepAssemblyContents, keepAllBackgroundResolutions) + member ic.ReferenceResolver = referenceResolver + member ic.MatchBracesAlternate(filename, source, options) = async { match braceMatchCache.TryGet (filename, source, options) with diff --git a/src/fsharp/vs/service.fsi b/src/fsharp/vs/service.fsi index c7f32cfdf5..4dd6db6bf0 100755 --- a/src/fsharp/vs/service.fsi +++ b/src/fsharp/vs/service.fsi @@ -413,7 +413,7 @@ type FSharpChecker = /// The optional size of the project checking cache. /// Keep the checked contents of projects. /// If false, do not keep full intermediate checking results from background checking suitable for returning from GetBackgroundCheckResultsForFileInProject. This reduces memory usage. - static member Create : ?projectCacheSize: int * ?keepAssemblyContents: bool * ?keepAllBackgroundResolutions: bool -> FSharpChecker + static member Create : ?projectCacheSize: int * ?keepAssemblyContents: bool * ?keepAllBackgroundResolutions: bool * ?msbuildEnabled: bool * ?msbuildVersion: string -> FSharpChecker /// /// Parse a source code file, returning information about brace matching in the file. @@ -733,6 +733,8 @@ type FSharpChecker = // One shared global singleton for use by multiple add-ins static member Instance : FSharpChecker member internal FrameworkImportsCache : FrameworkImportsCache + member internal ReferenceResolver : ReferenceResolver.Resolver + // An object to typecheck source in a given typechecking environment. From 9e4727aee57ae6fdd9ca06f6aa2c6c06fafc2ef6 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 23:32:08 +0100 Subject: [PATCH 08/19] trial changes --- src/absil/illib.fs | 1 - src/fsharp/ReferenceResolver.fs | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/absil/illib.fs b/src/absil/illib.fs index 3b2f844243..5d06388aa2 100755 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -8,7 +8,6 @@ open System open System.Collections open System.Collections.Generic open Internal.Utilities -open Internal.Utilities.Collections #if FX_RESHAPED_REFLECTION open Microsoft.FSharp.Core.ReflectionAdapters diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 19dcc945c3..e5ec487352 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if INTERACTIVE -#load "../utils/ResizeArray.fs" -#load "../absil/illib.fs" +#load "../utils/ResizeArray.fs" "../absil/illib.fs" #else module Microsoft.FSharp.Compiler.ReferenceResolver #endif @@ -118,7 +117,7 @@ let ScriptingNaiveResolver = if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then yield! registrySearchPaths() ] - [| for (baggage,r) in references do + [| for (baggage,r) in references do let mutable found = false let success path = if not found then @@ -165,10 +164,11 @@ let resolve s = resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] +resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] #endif let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = - let msbuildEnabled = msbuildEnabled && false + //let msbuildEnabled = msbuildEnabled && false let tryMSBuild v = if msbuildEnabled then // Detect if MSBuild v12 is on the machine, if so use the resolver from there From 712fdb166ae6377e21872d60811aae9cb6a3f0bd Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 23:39:28 +0100 Subject: [PATCH 09/19] default resolver --- src/fsharp/ReferenceResolver.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index e5ec487352..5a1ecd8f29 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -65,7 +65,7 @@ type Resolver = logerror:(string->string->unit) -> ResolvedFile[] -let ScriptingNaiveResolver = +let SimplisticResolver = { new Resolver with member __.HighestInstalledNetFrameworkVersion() = "v4.5" member __.DotNetFrameworkReferenceAssembliesRootDirectory = @@ -146,8 +146,8 @@ let ScriptingNaiveResolver = | Some ass -> yield! success ass.Location |] } #if INTERACTIVE -ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory -ScriptingNaiveResolver.HighestInstalledNetFrameworkVersion() +SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory +SimplisticResolver.HighestInstalledNetFrameworkVersion() let fscoreDir = if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows @@ -160,7 +160,7 @@ let fscoreDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() let resolve s = - ScriptingNaiveResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> ("", a) |],"v4.5.1", [ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + SimplisticResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> ("", a) |],"v4.5.1", [SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] @@ -191,4 +191,4 @@ let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = match tryMSBuild "12" with | Some r -> r | None -> - ScriptingNaiveResolver + SimplisticResolver From 161ad17c21dfdf2dd482f7409a5c9f495aadab35 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 23:59:35 +0100 Subject: [PATCH 10/19] default resolver --- src/fsharp/ReferenceResolver.fs | 76 ++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 5a1ecd8f29..8dd398e7a4 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -109,6 +109,7 @@ let SimplisticResolver = | _ -> () ] + let results = ResizeArray() let searchPaths = [ yield! targetFrameworkDirectories yield! explicitIncludeDirs @@ -117,33 +118,58 @@ let SimplisticResolver = if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then yield! registrySearchPaths() ] - [| for (baggage,r) in references do + for (baggage,r) in references do + try let mutable found = false let success path = if not found then found <- true - [ { itemSpec = path; prepareToolTip = snd; baggage=baggage } ] - else [] - if Path.IsPathRooted(r) then + results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } + + if not found && Path.IsPathRooted(r) then if FileSystem.SafeExists(r) then - yield! success r - else - let isFileName = - r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || - r.EndsWith("exe",StringComparison.InvariantCultureIgnoreCase) - - let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" - - for searchPath in searchPaths do - if not found then - let trialPath = Path.Combine(searchPath,qual) - if FileSystem.SafeExists(trialPath) then - yield! success trialPath + success r + + // For this one we need to get the version search exactly right, without doing a load + if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let fscoreDir0 = + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() + let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") + printfn "searching %s" trialPath + if FileSystem.SafeExists(trialPath) then + success trialPath + + // Try to use Assemby.Load rather than searching paths for assemblies with explicit versions + if not found && r.Contains(",") then + let ass = try Some (Assembly.Load(r)) with _ -> None + match ass with + | None -> () + | Some ass -> success ass.Location + + let isFileName = + r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || + r.EndsWith("exe",StringComparison.InvariantCultureIgnoreCase) + + let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" + + for searchPath in searchPaths do if not found then - let ass = try Some (System.Reflection.Assembly.ReflectionOnlyLoad(r)) with _ -> None - match ass with - | None -> () - | Some ass -> yield! success ass.Location |] } + let trialPath = Path.Combine(searchPath,qual) + if FileSystem.SafeExists(trialPath) then + success trialPath + + if not found then + let ass = try Some (Assembly.Load(r)) with _ -> None + match ass with + | Some ass -> success ass.Location + | None -> () + with e -> logWarning "SR001" (e.ToString()) + results.ToArray() } #if INTERACTIVE SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory @@ -168,14 +194,14 @@ resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7 #endif let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = - //let msbuildEnabled = msbuildEnabled && false + let msbuildEnabled = msbuildEnabled && false let tryMSBuild v = if msbuildEnabled then // Detect if MSBuild v12 is on the machine, if so use the resolver from there - 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 - let ass = mb |> Option.bind (fun _ -> try System.Reflection.Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) + let mb = try Assembly.Load(sprintf "Microsoft.Build.Framework, Version=%s.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None + let ass = mb |> Option.bind (fun _ -> try Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) - 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) + let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("get_Resolver",BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null, null, [| |]) |> Option.ofObj) let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) resolver else None From 2aa7e3f558c081f4b58db89e95d2b8c93b132553 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Wed, 12 Oct 2016 23:59:46 +0100 Subject: [PATCH 11/19] default resolver --- src/fsharp/ReferenceResolver.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 8dd398e7a4..21df834482 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -194,7 +194,7 @@ resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7 #endif let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = - let msbuildEnabled = msbuildEnabled && false + //let msbuildEnabled = msbuildEnabled && false let tryMSBuild v = if msbuildEnabled then // Detect if MSBuild v12 is on the machine, if so use the resolver from there From 53aabd75c99b63388c4d3f52f14fccccef16a5af Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 12:33:27 +0100 Subject: [PATCH 12/19] fix search --- src/fsharp/ReferenceResolver.fs | 19 ++++++++++--------- .../FSharp.Compiler.Service.Tests.fsproj | 5 ----- tests/service/ProjectAnalysisTests.fs | 9 --------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 21df834482..f298abf3bb 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -118,11 +118,13 @@ let SimplisticResolver = if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then yield! registrySearchPaths() ] - for (baggage,r) in references do + for (r, baggage) in references do try + printfn "resolving %s" r let mutable found = false let success path = if not found then + printfn "resolved %s --> %s" r path found <- true results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } @@ -140,7 +142,6 @@ let SimplisticResolver = | s -> s PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") - printfn "searching %s" trialPath if FileSystem.SafeExists(trialPath) then success trialPath @@ -163,11 +164,11 @@ let SimplisticResolver = if FileSystem.SafeExists(trialPath) then success trialPath - if not found then - let ass = try Some (Assembly.Load(r)) with _ -> None - match ass with - | Some ass -> success ass.Location - | None -> () + //if not found then + // let ass = try Some (Assembly.Load(r)) with _ -> None + // match ass with + // | Some ass -> success ass.Location + // | None -> () with e -> logWarning "SR001" (e.ToString()) results.ToArray() } @@ -186,7 +187,7 @@ let fscoreDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() let resolve s = - SimplisticResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> ("", a) |],"v4.5.1", [SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + SimplisticResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] @@ -194,7 +195,7 @@ resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7 #endif let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = - //let msbuildEnabled = msbuildEnabled && false + let msbuildEnabled = msbuildEnabled && false let tryMSBuild v = if msbuildEnabled then // Detect if MSBuild v12 is on the machine, if so use the resolver from there diff --git a/tests/service/FSharp.Compiler.Service.Tests.fsproj b/tests/service/FSharp.Compiler.Service.Tests.fsproj index 0d2ad6bb97..178fab3b46 100644 --- a/tests/service/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/service/FSharp.Compiler.Service.Tests.fsproj @@ -99,11 +99,6 @@ {887630a3-4b1d-40ea-b8b3-2d842e9c40db} True - - TestTP - {ff76bd3c-5e0a-4752-b6c3-044f6e15719b} - True - diff --git a/tests/service/ProjectAnalysisTests.fs b/tests/service/ProjectAnalysisTests.fs index 095abdbaac..2f2dd0a4f9 100644 --- a/tests/service/ProjectAnalysisTests.fs +++ b/tests/service/ProjectAnalysisTests.fs @@ -4510,15 +4510,6 @@ module Project35b = let options = checker.GetProjectOptionsFromScript(fileName1, fileSource1) |> Async.RunSynchronously #endif -[] -let ``Test project35b Dependency files for ParseFileInProject`` () = - // This is testing legacy functionality - let parseFileResults = checker.ParseFileInProject(Project35b.fileName1, Project35b.fileSource1, Project35b.options) |> Async.RunSynchronously - for d in parseFileResults.DependencyFiles do - printfn "ParseFileInProject dependency: %s" d - parseFileResults.DependencyFiles |> List.exists (fun s -> s.Contains "notexist.dll") |> shouldEqual true - parseFileResults.DependencyFiles |> List.exists (fun s -> s.Contains Project35b.fileName1) |> shouldEqual true - [] let ``Test project35b Dependency files for ParseAndCheckFileInProject`` () = let checkFileResults = From 6204900af5bcd074bc048b89630304aa88d2bb54 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 13:04:57 +0100 Subject: [PATCH 13/19] implement GAC search --- src/fsharp/ReferenceResolver.fs | 89 +++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index f298abf3bb..abff2c81f2 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -65,7 +65,7 @@ type Resolver = logerror:(string->string->unit) -> ResolvedFile[] -let SimplisticResolver = +let SimulatedMSBuildResolver = { new Resolver with member __.HighestInstalledNetFrameworkVersion() = "v4.5" member __.DotNetFrameworkReferenceAssembliesRootDirectory = @@ -119,7 +119,6 @@ let SimplisticResolver = yield! registrySearchPaths() ] for (r, baggage) in references do - try printfn "resolving %s" r let mutable found = false let success path = @@ -128,29 +127,35 @@ let SimplisticResolver = found <- true results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } - if not found && Path.IsPathRooted(r) then - if FileSystem.SafeExists(r) then - success r + try + if not found && Path.IsPathRooted(r) then + if FileSystem.SafeExists(r) then + success r + with e -> logWarning "SR001" (e.ToString()) // For this one we need to get the version search exactly right, without doing a load - if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then - let n = AssemblyName(r) - let fscoreDir0 = - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") - | s -> s - PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() - let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") - if FileSystem.SafeExists(trialPath) then - success trialPath + try + if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let fscoreDir0 = + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() + let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) // Try to use Assemby.Load rather than searching paths for assemblies with explicit versions - if not found && r.Contains(",") then - let ass = try Some (Assembly.Load(r)) with _ -> None - match ass with - | None -> () - | Some ass -> success ass.Location + try + if not found && r.Contains(",") then + let ass = try Some (Assembly.Load(r)) with _ -> None + match ass with + | None -> () + | Some ass -> success ass.Location + with e -> logWarning "SR001" (e.ToString()) let isFileName = r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || @@ -159,22 +164,43 @@ let SimplisticResolver = let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" for searchPath in searchPaths do + try if not found then let trialPath = Path.Combine(searchPath,qual) if FileSystem.SafeExists(trialPath) then success trialPath + with e -> logWarning "SR001" (e.ToString()) + + try + // Seach the GAC on Windows + if not found && not isFileName && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let netfx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + let gac = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(netfx.TrimEnd('\\'))),"assembly") + for gacdir in Directory.EnumerateDirectories(gac) do + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + let verdir = Path.Combine(assdir,"v4.0_"+n.Version.ToString()+"__"+String.concat "" [| for b in n.GetPublicKeyToken() -> sprintf "%02x" b |]) + printfn "searching GAC: %s" verdir + + if Directory.Exists(verdir) then + let trialPath = Path.Combine(verdir,qual) + printfn "searching GAC: %s" trialPath + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) + //if not found then // let ass = try Some (Assembly.Load(r)) with _ -> None // match ass with // | Some ass -> success ass.Location // | None -> () - with e -> logWarning "SR001" (e.ToString()) results.ToArray() } #if INTERACTIVE -SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory -SimplisticResolver.HighestInstalledNetFrameworkVersion() +SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory +SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() let fscoreDir = if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows @@ -187,26 +213,27 @@ let fscoreDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() let resolve s = - SimplisticResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimplisticResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] + +resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] #endif let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = let msbuildEnabled = msbuildEnabled && false + let msbuildVersion = defaultArg msbuildVersion "12" let tryMSBuild v = - if msbuildEnabled then - // Detect if MSBuild v12 is on the machine, if so use the resolver from there + // Detect if MSBuild is on the machine, if so use the resolver from there let mb = try Assembly.Load(sprintf "Microsoft.Build.Framework, Version=%s.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None let ass = mb |> Option.bind (fun _ -> try Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("get_Resolver",BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null, null, [| |]) |> Option.ofObj) let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) resolver - else None - match tryMSBuild (defaultArg msbuildVersion "12") with + match (if msbuildEnabled then tryMSBuild msbuildVersion else None) with | Some r -> r | None -> //match tryMSBuild "15" with @@ -215,7 +242,7 @@ let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = //match tryMSBuild "14" with //| Some r -> r //| None -> - match tryMSBuild "12" with + match (if msbuildEnabled && msbuildVersion <> "12" then tryMSBuild "12" else None) with | Some r -> r | None -> - SimplisticResolver + SimulatedMSBuildResolver From 345bdaebc0bf3440309980fd6d8f028efd2658d3 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 13:26:28 +0100 Subject: [PATCH 14/19] implement GAC search --- src/fsharp/ReferenceResolver.fs | 65 +++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index abff2c81f2..1927efad1f 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -198,31 +198,8 @@ let SimulatedMSBuildResolver = // | None -> () results.ToArray() } -#if INTERACTIVE -SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory -SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() - -let fscoreDir = - if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF - | s -> s - PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" - else - System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() - -let resolve s = - SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) - -resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] - -resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] - -resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] -#endif - let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = +#if !RESHAPED_MSBUILD let msbuildEnabled = msbuildEnabled && false let msbuildVersion = defaultArg msbuildVersion "12" let tryMSBuild v = @@ -245,4 +222,44 @@ let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = match (if msbuildEnabled && msbuildVersion <> "12" then tryMSBuild "12" else None) with | Some r -> r | None -> +#endif SimulatedMSBuildResolver + + +#if INTERACTIVE +// Some manual testing +SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory +SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() + +let fscoreDir = + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" + else + System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + +let resolve s = + SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + +// Resolve partial name +resolve ["FSharp.Core" ] + +// Resolve partial name +resolve ["FSharp.Core.dll" ] + +// Resolve from reference assemblies +resolve ["System"; "mscorlib"; "mscorlib.dll" ] + +// Resolve from Registry AssemblyFolders +resolve ["Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] + +// Resolve exact version of FSharp.Core +resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] + +// Resolve from GAC: +resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] +#endif + From f8b143595041ae40ad74e39fa45b8bfa1db06043 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 13:45:52 +0100 Subject: [PATCH 15/19] implement GAC search --- src/fsharp/ReferenceResolver.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 1927efad1f..3d5634dad2 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -158,8 +158,8 @@ let SimulatedMSBuildResolver = with e -> logWarning "SR001" (e.ToString()) let isFileName = - r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || - r.EndsWith("exe",StringComparison.InvariantCultureIgnoreCase) + r.EndsWith("dll",StringComparison.OrdinalIgnoreCase) || + r.EndsWith("exe",StringComparison.OrdinalIgnoreCase) let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" From 60ff0cdb0640a22d870ab4bde05cea836fda8522 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 13:47:12 +0100 Subject: [PATCH 16/19] fixes --- src/fsharp/ReferenceResolver.fs | 88 +++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 3d5634dad2..692505fd9f 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -69,6 +69,9 @@ let SimulatedMSBuildResolver = { new Resolver with member __.HighestInstalledNetFrameworkVersion() = "v4.5" member __.DotNetFrameworkReferenceAssembliesRootDirectory = +#if RESHAPED_MSBUILD + "" +#else if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then let PF = match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with @@ -77,10 +80,12 @@ let SimulatedMSBuildResolver = PF + @"\Reference Assemblies\Microsoft\Framework\.NETFramework" else "" +#endif member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = +#if !RESHAPED_MSBUILD let registrySearchPaths() = [ let registryKey = @"Software\Microsoft\.NetFramework"; use key = Registry.LocalMachine.OpenSubKey(registryKey) @@ -107,7 +112,7 @@ let SimulatedMSBuildResolver = match subSubSubKey.GetValue(null) with | :? string as s -> yield s | _ -> () ] - +#endif let results = ResizeArray() let searchPaths = @@ -115,15 +120,18 @@ let SimulatedMSBuildResolver = yield! explicitIncludeDirs yield fsharpCoreDir yield implicitIncludeDir +#if !RESHAPED_MSBUILD if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then - yield! registrySearchPaths() ] + yield! registrySearchPaths() +#endif + ] for (r, baggage) in references do - printfn "resolving %s" r + //printfn "resolving %s" r let mutable found = false let success path = if not found then - printfn "resolved %s --> %s" r path + //printfn "resolved %s --> %s" r path found <- true results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } @@ -133,6 +141,7 @@ let SimulatedMSBuildResolver = success r with e -> logWarning "SR001" (e.ToString()) +#if !RESHAPED_MSBUILD // For this one we need to get the version search exactly right, without doing a load try if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then @@ -147,15 +156,7 @@ let SimulatedMSBuildResolver = if FileSystem.SafeExists(trialPath) then success trialPath with e -> logWarning "SR001" (e.ToString()) - - // Try to use Assemby.Load rather than searching paths for assemblies with explicit versions - try - if not found && r.Contains(",") then - let ass = try Some (Assembly.Load(r)) with _ -> None - match ass with - | None -> () - | Some ass -> success ass.Location - with e -> logWarning "SR001" (e.ToString()) +#endif let isFileName = r.EndsWith("dll",StringComparison.OrdinalIgnoreCase) || @@ -171,31 +172,48 @@ let SimulatedMSBuildResolver = success trialPath with e -> logWarning "SR001" (e.ToString()) +#if !RESHAPED_MSBUILD try // Seach the GAC on Windows if not found && not isFileName && Environment.OSVersion.Platform = PlatformID.Win32NT then let n = AssemblyName(r) let netfx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() let gac = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(netfx.TrimEnd('\\'))),"assembly") - for gacdir in Directory.EnumerateDirectories(gac) do - let assdir = Path.Combine(gacdir,n.Name) - if Directory.Exists(assdir) then - let verdir = Path.Combine(assdir,"v4.0_"+n.Version.ToString()+"__"+String.concat "" [| for b in n.GetPublicKeyToken() -> sprintf "%02x" b |]) - printfn "searching GAC: %s" verdir - - if Directory.Exists(verdir) then - let trialPath = Path.Combine(verdir,qual) - printfn "searching GAC: %s" trialPath - if FileSystem.SafeExists(trialPath) then - success trialPath + match n.Version, n.GetPublicKeyToken() with + | null, _ | _,null -> + let options = + [ for gacdir in Directory.EnumerateDirectories(gac) do + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + for tdir in Directory.EnumerateDirectories(assdir) do + let trialPath = Path.Combine(tdir,qual) + if FileSystem.SafeExists(trialPath) then + yield trialPath ] + //printfn "sorting GAC paths: %A" options + options + |> List.sort // puts latest version last + |> List.tryLast + |> function None -> () | Some p -> success p + + | v,tok -> + for gacdir in Directory.EnumerateDirectories(gac) do + //printfn "searching GAC directory: %s" gacdir + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + //printfn "searching GAC directory: %s" assdir + + let tokText = String.concat "" [| for b in tok -> sprintf "%02x" b |] + let verdir = Path.Combine(assdir,"v4.0_"+v.ToString()+"__"+tokText) + //printfn "searching GAC directory: %s" verdir + + if Directory.Exists(verdir) then + let trialPath = Path.Combine(verdir,qual) + //printfn "searching GAC: %s" trialPath + if FileSystem.SafeExists(trialPath) then + success trialPath with e -> logWarning "SR001" (e.ToString()) +#endif - - //if not found then - // let ass = try Some (Assembly.Load(r)) with _ -> None - // match ass with - // | Some ass -> success ass.Location - // | None -> () results.ToArray() } let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = @@ -244,10 +262,10 @@ let fscoreDir = let resolve s = SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) -// Resolve partial name +// Resolve partial name to something on search path resolve ["FSharp.Core" ] -// Resolve partial name +// Resolve DLL name to something on search path resolve ["FSharp.Core.dll" ] // Resolve from reference assemblies @@ -261,5 +279,11 @@ resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7 // Resolve from GAC: resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] + +// Resolve from GAC: +resolve [ "EventViewer" ] + +resolve [ "Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] +resolve [ "Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] #endif From 0bf1ac4c7fadb0ddbc7dd906a7c9a524d3e10186 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 13:49:55 +0100 Subject: [PATCH 17/19] default resolver --- src/fsharp/ReferenceResolver.fs | 202 +++++++++++++----- .../FSharp.Compiler.Service.Tests.fsproj | 5 - tests/service/ProjectAnalysisTests.fs | 9 - 3 files changed, 150 insertions(+), 66 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index e5ec487352..0eef26292d 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -65,10 +65,13 @@ type Resolver = logerror:(string->string->unit) -> ResolvedFile[] -let ScriptingNaiveResolver = +let SimulatedMSBuildResolver = { new Resolver with member __.HighestInstalledNetFrameworkVersion() = "v4.5" member __.DotNetFrameworkReferenceAssembliesRootDirectory = +#if RESHAPED_MSBUILD + "" +#else if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then let PF = match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with @@ -77,10 +80,12 @@ let ScriptingNaiveResolver = PF + @"\Reference Assemblies\Microsoft\Framework\.NETFramework" else "" +#endif member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = +#if !RESHAPED_MSBUILD let registrySearchPaths() = [ let registryKey = @"Software\Microsoft\.NetFramework"; use key = Registry.LocalMachine.OpenSubKey(registryKey) @@ -107,79 +112,126 @@ let ScriptingNaiveResolver = match subSubSubKey.GetValue(null) with | :? string as s -> yield s | _ -> () ] +#endif - + let results = ResizeArray() let searchPaths = [ yield! targetFrameworkDirectories yield! explicitIncludeDirs yield fsharpCoreDir yield implicitIncludeDir +#if !RESHAPED_MSBUILD if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then - yield! registrySearchPaths() ] + yield! registrySearchPaths() +#endif + ] - [| for (baggage,r) in references do + for (r, baggage) in references do + //printfn "resolving %s" r let mutable found = false let success path = if not found then + //printfn "resolved %s --> %s" r path found <- true - [ { itemSpec = path; prepareToolTip = snd; baggage=baggage } ] - else [] - if Path.IsPathRooted(r) then - if FileSystem.SafeExists(r) then - yield! success r - else - let isFileName = - r.EndsWith("dll",StringComparison.InvariantCultureIgnoreCase) || - r.EndsWith("exe",StringComparison.InvariantCultureIgnoreCase) - - let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" - - for searchPath in searchPaths do - if not found then - let trialPath = Path.Combine(searchPath,qual) - if FileSystem.SafeExists(trialPath) then - yield! success trialPath - if not found then - let ass = try Some (System.Reflection.Assembly.ReflectionOnlyLoad(r)) with _ -> None - match ass with - | None -> () - | Some ass -> yield! success ass.Location |] } + results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } -#if INTERACTIVE -ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory -ScriptingNaiveResolver.HighestInstalledNetFrameworkVersion() + try + if not found && Path.IsPathRooted(r) then + if FileSystem.SafeExists(r) then + success r + with e -> logWarning "SR001" (e.ToString()) -let fscoreDir = - if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF - | s -> s - PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" - else - System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() +#if !RESHAPED_MSBUILD + // For this one we need to get the version search exactly right, without doing a load + try + if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let fscoreDir0 = + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() + let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) +#endif -let resolve s = - ScriptingNaiveResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> ("", a) |],"v4.5.1", [ScriptingNaiveResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + let isFileName = + r.EndsWith("dll",StringComparison.OrdinalIgnoreCase) || + r.EndsWith("exe",StringComparison.OrdinalIgnoreCase) -resolve ["System"; "mscorlib"; "mscorlib.dll"; "FSharp.Core"; "FSharp.Core.dll"; "Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] + let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" -resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] + for searchPath in searchPaths do + try + if not found then + let trialPath = Path.Combine(searchPath,qual) + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) + +#if !RESHAPED_MSBUILD + try + // Seach the GAC on Windows + if not found && not isFileName && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let netfx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + let gac = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(netfx.TrimEnd('\\'))),"assembly") + match n.Version, n.GetPublicKeyToken() with + | null, _ | _,null -> + let options = + [ for gacdir in Directory.EnumerateDirectories(gac) do + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + for tdir in Directory.EnumerateDirectories(assdir) do + let trialPath = Path.Combine(tdir,qual) + if FileSystem.SafeExists(trialPath) then + yield trialPath ] + //printfn "sorting GAC paths: %A" options + options + |> List.sort // puts latest version last + |> List.tryLast + |> function None -> () | Some p -> success p + + | v,tok -> + for gacdir in Directory.EnumerateDirectories(gac) do + //printfn "searching GAC directory: %s" gacdir + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + //printfn "searching GAC directory: %s" assdir + + let tokText = String.concat "" [| for b in tok -> sprintf "%02x" b |] + let verdir = Path.Combine(assdir,"v4.0_"+v.ToString()+"__"+tokText) + //printfn "searching GAC directory: %s" verdir + + if Directory.Exists(verdir) then + let trialPath = Path.Combine(verdir,qual) + //printfn "searching GAC: %s" trialPath + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) #endif + results.ToArray() } + let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = - //let msbuildEnabled = msbuildEnabled && false +#if RESHAPED_MSBUILD + ignore msbuildVersion + ignore msbuildEnabled +#else + let msbuildEnabled = msbuildEnabled && false + let msbuildVersion = defaultArg msbuildVersion "12" let tryMSBuild v = - if msbuildEnabled then - // Detect if MSBuild v12 is on the machine, if so use the resolver from there - 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 - let ass = mb |> Option.bind (fun _ -> try System.Reflection.Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) + // Detect if MSBuild is on the machine, if so use the resolver from there + let mb = try Assembly.Load(sprintf "Microsoft.Build.Framework, Version=%s.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None + let ass = mb |> Option.bind (fun _ -> try Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) - 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) + let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("get_Resolver",BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null, null, [| |]) |> Option.ofObj) let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) resolver - else None - match tryMSBuild (defaultArg msbuildVersion "12") with + match (if msbuildEnabled then tryMSBuild msbuildVersion else None) with | Some r -> r | None -> //match tryMSBuild "15" with @@ -188,7 +240,53 @@ let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = //match tryMSBuild "14" with //| Some r -> r //| None -> - match tryMSBuild "12" with + match (if msbuildEnabled && msbuildVersion <> "12" then tryMSBuild "12" else None) with | Some r -> r | None -> - ScriptingNaiveResolver +#endif + SimulatedMSBuildResolver + + +#if INTERACTIVE +// Some manual testing +SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory +SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() + +let fscoreDir = + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" + else + System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + +let resolve s = + SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + +// Resolve partial name to something on search path +resolve ["FSharp.Core" ] + +// Resolve DLL name to something on search path +resolve ["FSharp.Core.dll" ] + +// Resolve from reference assemblies +resolve ["System"; "mscorlib"; "mscorlib.dll" ] + +// Resolve from Registry AssemblyFolders +resolve ["Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] + +// Resolve exact version of FSharp.Core +resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] + +// Resolve from GAC: +resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] + +// Resolve from GAC: +resolve [ "EventViewer" ] + +resolve [ "Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] +resolve [ "Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] +#endif + diff --git a/tests/service/FSharp.Compiler.Service.Tests.fsproj b/tests/service/FSharp.Compiler.Service.Tests.fsproj index 0d2ad6bb97..178fab3b46 100644 --- a/tests/service/FSharp.Compiler.Service.Tests.fsproj +++ b/tests/service/FSharp.Compiler.Service.Tests.fsproj @@ -99,11 +99,6 @@ {887630a3-4b1d-40ea-b8b3-2d842e9c40db} True - - TestTP - {ff76bd3c-5e0a-4752-b6c3-044f6e15719b} - True - diff --git a/tests/service/ProjectAnalysisTests.fs b/tests/service/ProjectAnalysisTests.fs index 095abdbaac..2f2dd0a4f9 100644 --- a/tests/service/ProjectAnalysisTests.fs +++ b/tests/service/ProjectAnalysisTests.fs @@ -4510,15 +4510,6 @@ module Project35b = let options = checker.GetProjectOptionsFromScript(fileName1, fileSource1) |> Async.RunSynchronously #endif -[] -let ``Test project35b Dependency files for ParseFileInProject`` () = - // This is testing legacy functionality - let parseFileResults = checker.ParseFileInProject(Project35b.fileName1, Project35b.fileSource1, Project35b.options) |> Async.RunSynchronously - for d in parseFileResults.DependencyFiles do - printfn "ParseFileInProject dependency: %s" d - parseFileResults.DependencyFiles |> List.exists (fun s -> s.Contains "notexist.dll") |> shouldEqual true - parseFileResults.DependencyFiles |> List.exists (fun s -> s.Contains Project35b.fileName1) |> shouldEqual true - [] let ``Test project35b Dependency files for ParseAndCheckFileInProject`` () = let checkFileResults = From f777b1f8be36bfcee76f9b62efb145de9f4e3415 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 14:37:00 +0100 Subject: [PATCH 18/19] onuy MSBuildv12 --- FSharp.Compiler.Service.sln | 14 -- nuget/FSharp.Compiler.Service.template | 1 - ...FSharp.Compiler.Service.MSBuild.v14.fsproj | 105 -------- .../project.json | 56 ----- .../FSharp.Compiler.Service.fsproj | 3 + .../FSharp.Compiler.Service/project.json | 2 +- src/fsharp/ReferenceResolver.fs | 235 +----------------- .../SimulatedMSBuildReferenceResolver.fs | 229 +++++++++++++++++ src/fsharp/fsi/fsi.fs | 8 +- src/fsharp/fsi/fsi.fsi | 2 +- src/fsharp/vs/SimpleServices.fs | 4 +- src/fsharp/vs/SimpleServices.fsi | 2 +- src/fsharp/vs/service.fs | 4 +- src/fsharp/vs/service.fsi | 5 +- 14 files changed, 247 insertions(+), 423 deletions(-) delete mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj delete mode 100644 src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json create mode 100644 src/fsharp/SimulatedMSBuildReferenceResolver.fs diff --git a/FSharp.Compiler.Service.sln b/FSharp.Compiler.Service.sln index 614a721932..c5173d3703 100644 --- a/FSharp.Compiler.Service.sln +++ b/FSharp.Compiler.Service.sln @@ -83,8 +83,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{9020 EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.MSBuild.v12", "src\fsharp\FSharp.Compiler.Service.MSBuild.v12\FSharp.Compiler.Service.MSBuild.v12.fsproj", "{8157B50E-397D-4232-A4E0-1977AFC7076D}" EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.MSBuild.v14", "src\fsharp\FSharp.Compiler.Service.MSBuild.v14\FSharp.Compiler.Service.MSBuild.v14.fsproj", "{43393416-DA88-4286-8D5A-3D2BB3686BBA}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -233,18 +231,6 @@ Global {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.ActiveCfg = Release|Any CPU {8157B50E-397D-4232-A4E0-1977AFC7076D}.Release|x86.Build.0 = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|x86.ActiveCfg = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Debug|x86.Build.0 = Debug|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Any CPU.Build.0 = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|x86.ActiveCfg = Release|Any CPU - {43393416-DA88-4286-8D5A-3D2BB3686BBA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/nuget/FSharp.Compiler.Service.template b/nuget/FSharp.Compiler.Service.template index 1d1f1d9d0e..0dfc5c1089 100644 --- a/nuget/FSharp.Compiler.Service.template +++ b/nuget/FSharp.Compiler.Service.template @@ -20,7 +20,6 @@ files ../bin/v4.5/FSharp.Compiler.Service.?db ==> lib/net45 ../bin/v4.5/FSharp.Compiler.Service.dll.?db ==> lib/net45 ../bin/v4.5/FSharp.Compiler.Service.MSBuild.v12.dll ==> lib/net45 - ../bin/v4.5/FSharp.Compiler.Service.MSBuild.v14.dll ==> lib/net45 dependencies System.Collections.Immutable >= LOCKEDVERSION System.Reflection.Metadata >= LOCKEDVERSION \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj deleted file mode 100644 index ac423f511d..0000000000 --- a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/FSharp.Compiler.Service.MSBuild.v14.fsproj +++ /dev/null @@ -1,105 +0,0 @@ - - - - - Debug - AnyCPU - Library - FSharp.Compiler.Service.MSBuild.v14 - $(NoWarn);44;62;9 - {43393416-da88-4286-8d5a-3d2bb3686bba} - true - v4.5 - 0x06800000 - $(OtherFlags) /warnon:1182 - true - true - $(OtherFlags) --times - $(NoWarn);69;65;54;61;75 - true - ..\..\..\bin\$(TargetFrameworkVersion) - $(OutputPath)\$(AssemblyName).xml - $(DefineConstants);CROSS_PLATFORM_COMPILER - $(DefineConstants);FX_ATLEAST_45 - $(DefineConstants);FX_ATLEAST_40 - $(DefineConstants);FX_MSBUILDRESOLVER_RUNTIMELIKE - 4.4.0.0 - $(MSBuildProjectDirectory)\..\..\..\ - - false - true - AnyCPU - - - - DEBUG; $(DefineConstants) - false - $(OtherFlags) --no-jit-optimize --jit-tracking - - - true - - - - AssemblyInfo/assemblyinfo.FSharp.Compiler.Service.MSBuild.v14.dll.fs - - - AssemblyInfo/assemblyinfo.shared.fs - - - Service/MSBuildReferenceResolver.fs - - - - - - - - - - - True - - - True - - - True - - - True - - - True - - - False - - - FSharp.Compiler.Service - {2e4d67b4-522d-4cf7-97e4-ba940f0b18f3} - True - - - - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets - - - $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets - - - - - - - - \ No newline at end of file diff --git a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json b/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json deleted file mode 100644 index 9be378dfa5..0000000000 --- a/src/fsharp/FSharp.Compiler.Service.MSBuild.v14/project.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "version": "8.0.0", - "buildOptions": { - "debugType": "portable", - "compilerName": "fsc", - "compile": { - "includeFiles": [ - "../../assemblyinfo/assemblyinfo.FSharp.Compiler.Service.dll.MSBuild.v14.fs", - "../../assemblyinfo/assemblyinfo.shared.fs", - "../../utils/reshapedmsbuild.fs", - "../MSBuildReferenceResolver.fs" - ] - }, - "define": [ - "FX_ATLEAST_35", - "FX_ATLEAST_40", - "FX_ATLEAST_45", - "FX_ATLEAST_LINQ", - "FX_ATLEAST_PORTABLE", - "TODO_REWORK_ASSEMBLY_LOAD" - ], - "xmlDoc": true, - "delaySign": true, - "warningsAsErrors": true - }, - "dependencies": { - "NETStandard.Library": "1.6.0", - "System.Diagnostics.TraceSource": "4.0.0", - "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", - "System.Collections.Immutable": "1.2.0", - "System.Security.Cryptography.Algorithms": "4.2.0", - "System.Security.Cryptography.Primitives": "4.0.0", - "System.Reflection.Metadata": "1.4.1-beta-24227-04", - "System.Diagnostics.Process": "4.1.0", - "FSharp.Compiler.Service": { - "version": "8.0.0", - "target": "project" - } - }, - "tools": { - "dotnet-fssrgen": "3.2.*", - "dotnet-mergenupkg": { "version": "1.0.*" }, - "dotnet-compile-fsc": { - "version": "1.0.0-preview2-*", - "imports": "dnxcore50" - } - }, - "frameworks": { - "netstandard1.6": { - "imports": [ - "portable-net45+win81", - "dnxcore50" - ] - } - } -} diff --git a/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj index 5bcee3dd45..98a5787bcc 100644 --- a/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj +++ b/src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj @@ -604,6 +604,9 @@ Service/reshapedmsbuild.fs + + Service/SimulatedMSBuildReferenceResolver.fs + Service/service.fsi diff --git a/src/fsharp/FSharp.Compiler.Service/project.json b/src/fsharp/FSharp.Compiler.Service/project.json index 147e25de89..d4509181c9 100644 --- a/src/fsharp/FSharp.Compiler.Service/project.json +++ b/src/fsharp/FSharp.Compiler.Service/project.json @@ -167,7 +167,7 @@ "../vs/ServiceUntypedParse.fsi", "../vs/ServiceUntypedParse.fs", "../../utils/reshapedmsbuild.fs", - "../MSBuildReferenceResolver.fs", + "../SimulatedMSBuildReferenceResolver.fs", "../vs/service.fsi", "../vs/service.fs", "../vs/SimpleServices.fsi", diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 0eef26292d..8ad170b067 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -1,18 +1,10 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if INTERACTIVE -#load "../utils/ResizeArray.fs" "../absil/illib.fs" -#else -module Microsoft.FSharp.Compiler.ReferenceResolver -#endif +module internal Microsoft.FSharp.Compiler.ReferenceResolver open System -open System.IO -open System.Reflection -open Microsoft.Win32 exception ResolutionFailure -open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library type ResolutionEnvironment = /// Indicates a script or source being compiled @@ -65,228 +57,3 @@ type Resolver = logerror:(string->string->unit) -> ResolvedFile[] -let SimulatedMSBuildResolver = - { new Resolver with - member __.HighestInstalledNetFrameworkVersion() = "v4.5" - member __.DotNetFrameworkReferenceAssembliesRootDirectory = -#if RESHAPED_MSBUILD - "" -#else - if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF - | s -> s - PF + @"\Reference Assemblies\Microsoft\Framework\.NETFramework" - else - "" -#endif - - member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, - outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = - -#if !RESHAPED_MSBUILD - let registrySearchPaths() = - [ let registryKey = @"Software\Microsoft\.NetFramework"; - use key = Registry.LocalMachine.OpenSubKey(registryKey) - match key with - | null -> () - | _ -> - for subKeyName in key.GetSubKeyNames() do - use subKey = key.OpenSubKey(subKeyName) - use subSubKey = subKey.OpenSubKey("AssemblyFoldersEx") - match subSubKey with - | null -> () - | _ -> - for subSubSubKeyName in subSubKey.GetSubKeyNames() do - use subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) - match subSubSubKey.GetValue(null) with - | :? string as s -> yield s - | _ -> () - use subSubKey = key.OpenSubKey("AssemblyFolders") - match subSubKey with - | null -> () - | _ -> - for subSubSubKeyName in subSubKey.GetSubKeyNames() do - let subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) - match subSubSubKey.GetValue(null) with - | :? string as s -> yield s - | _ -> () ] -#endif - - let results = ResizeArray() - let searchPaths = - [ yield! targetFrameworkDirectories - yield! explicitIncludeDirs - yield fsharpCoreDir - yield implicitIncludeDir -#if !RESHAPED_MSBUILD - if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then - yield! registrySearchPaths() -#endif - ] - - for (r, baggage) in references do - //printfn "resolving %s" r - let mutable found = false - let success path = - if not found then - //printfn "resolved %s --> %s" r path - found <- true - results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } - - try - if not found && Path.IsPathRooted(r) then - if FileSystem.SafeExists(r) then - success r - with e -> logWarning "SR001" (e.ToString()) - -#if !RESHAPED_MSBUILD - // For this one we need to get the version search exactly right, without doing a load - try - if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then - let n = AssemblyName(r) - let fscoreDir0 = - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") - | s -> s - PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() - let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") - if FileSystem.SafeExists(trialPath) then - success trialPath - with e -> logWarning "SR001" (e.ToString()) -#endif - - let isFileName = - r.EndsWith("dll",StringComparison.OrdinalIgnoreCase) || - r.EndsWith("exe",StringComparison.OrdinalIgnoreCase) - - let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" - - for searchPath in searchPaths do - try - if not found then - let trialPath = Path.Combine(searchPath,qual) - if FileSystem.SafeExists(trialPath) then - success trialPath - with e -> logWarning "SR001" (e.ToString()) - -#if !RESHAPED_MSBUILD - try - // Seach the GAC on Windows - if not found && not isFileName && Environment.OSVersion.Platform = PlatformID.Win32NT then - let n = AssemblyName(r) - let netfx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() - let gac = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(netfx.TrimEnd('\\'))),"assembly") - match n.Version, n.GetPublicKeyToken() with - | null, _ | _,null -> - let options = - [ for gacdir in Directory.EnumerateDirectories(gac) do - let assdir = Path.Combine(gacdir,n.Name) - if Directory.Exists(assdir) then - for tdir in Directory.EnumerateDirectories(assdir) do - let trialPath = Path.Combine(tdir,qual) - if FileSystem.SafeExists(trialPath) then - yield trialPath ] - //printfn "sorting GAC paths: %A" options - options - |> List.sort // puts latest version last - |> List.tryLast - |> function None -> () | Some p -> success p - - | v,tok -> - for gacdir in Directory.EnumerateDirectories(gac) do - //printfn "searching GAC directory: %s" gacdir - let assdir = Path.Combine(gacdir,n.Name) - if Directory.Exists(assdir) then - //printfn "searching GAC directory: %s" assdir - - let tokText = String.concat "" [| for b in tok -> sprintf "%02x" b |] - let verdir = Path.Combine(assdir,"v4.0_"+v.ToString()+"__"+tokText) - //printfn "searching GAC directory: %s" verdir - - if Directory.Exists(verdir) then - let trialPath = Path.Combine(verdir,qual) - //printfn "searching GAC: %s" trialPath - if FileSystem.SafeExists(trialPath) then - success trialPath - with e -> logWarning "SR001" (e.ToString()) -#endif - - results.ToArray() } - -let GetDefaultResolver(msbuildEnabled: bool, msbuildVersion: string option) = -#if RESHAPED_MSBUILD - ignore msbuildVersion - ignore msbuildEnabled -#else - let msbuildEnabled = msbuildEnabled && false - let msbuildVersion = defaultArg msbuildVersion "12" - let tryMSBuild v = - // Detect if MSBuild is on the machine, if so use the resolver from there - let mb = try Assembly.Load(sprintf "Microsoft.Build.Framework, Version=%s.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None - let ass = mb |> Option.bind (fun _ -> try Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) - let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) - let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("get_Resolver",BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null, null, [| |]) |> Option.ofObj) - let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) - resolver - match (if msbuildEnabled then tryMSBuild msbuildVersion else None) with - | Some r -> r - | None -> - //match tryMSBuild "15" with - //| Some r -> r - //| None -> - //match tryMSBuild "14" with - //| Some r -> r - //| None -> - match (if msbuildEnabled && msbuildVersion <> "12" then tryMSBuild "12" else None) with - | Some r -> r - | None -> -#endif - SimulatedMSBuildResolver - - -#if INTERACTIVE -// Some manual testing -SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory -SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() - -let fscoreDir = - if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows - let PF = - match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with - | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF - | s -> s - PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" - else - System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() - -let resolve s = - SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) - -// Resolve partial name to something on search path -resolve ["FSharp.Core" ] - -// Resolve DLL name to something on search path -resolve ["FSharp.Core.dll" ] - -// Resolve from reference assemblies -resolve ["System"; "mscorlib"; "mscorlib.dll" ] - -// Resolve from Registry AssemblyFolders -resolve ["Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] - -// Resolve exact version of FSharp.Core -resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] - -// Resolve from GAC: -resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] - -// Resolve from GAC: -resolve [ "EventViewer" ] - -resolve [ "Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] -resolve [ "Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] -#endif - diff --git a/src/fsharp/SimulatedMSBuildReferenceResolver.fs b/src/fsharp/SimulatedMSBuildReferenceResolver.fs new file mode 100644 index 0000000000..eea6bee33e --- /dev/null +++ b/src/fsharp/SimulatedMSBuildReferenceResolver.fs @@ -0,0 +1,229 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#if INTERACTIVE +#load "../utils/ResizeArray.fs" "../absil/illib.fs" "../fsharp/ReferenceResolver.fs" +#else +module internal Microsoft.FSharp.Compiler.SimulatedMSBuildReferenceResolver +#endif + +open System +open System.IO +open System.Reflection +open Microsoft.Win32 +open Microsoft.FSharp.Compiler +open Microsoft.FSharp.Compiler.ReferenceResolver +open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library + +let internal SimulatedMSBuildResolver = + { new Resolver with + member __.HighestInstalledNetFrameworkVersion() = "v4.5" + member __.DotNetFrameworkReferenceAssembliesRootDirectory = +#if RESHAPED_MSBUILD + "" +#else + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\Framework\.NETFramework" + else + "" +#endif + + member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, + outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = + +#if !RESHAPED_MSBUILD + let registrySearchPaths() = + [ let registryKey = @"Software\Microsoft\.NetFramework"; + use key = Registry.LocalMachine.OpenSubKey(registryKey) + match key with + | null -> () + | _ -> + for subKeyName in key.GetSubKeyNames() do + use subKey = key.OpenSubKey(subKeyName) + use subSubKey = subKey.OpenSubKey("AssemblyFoldersEx") + match subSubKey with + | null -> () + | _ -> + for subSubSubKeyName in subSubKey.GetSubKeyNames() do + use subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) + match subSubSubKey.GetValue(null) with + | :? string as s -> yield s + | _ -> () + use subSubKey = key.OpenSubKey("AssemblyFolders") + match subSubKey with + | null -> () + | _ -> + for subSubSubKeyName in subSubKey.GetSubKeyNames() do + let subSubSubKey = subSubKey.OpenSubKey(subSubSubKeyName) + match subSubSubKey.GetValue(null) with + | :? string as s -> yield s + | _ -> () ] +#endif + + let results = ResizeArray() + let searchPaths = + [ yield! targetFrameworkDirectories + yield! explicitIncludeDirs + yield fsharpCoreDir + yield implicitIncludeDir +#if !RESHAPED_MSBUILD + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then + yield! registrySearchPaths() +#endif + ] + + for (r, baggage) in references do + //printfn "resolving %s" r + let mutable found = false + let success path = + if not found then + //printfn "resolved %s --> %s" r path + found <- true + results.Add { itemSpec = path; prepareToolTip = snd; baggage=baggage } + + try + if not found && Path.IsPathRooted(r) then + if FileSystem.SafeExists(r) then + success r + with e -> logWarning "SR001" (e.ToString()) + +#if !RESHAPED_MSBUILD + // For this one we need to get the version search exactly right, without doing a load + try + if not found && r.StartsWith("FSharp.Core, Version=") && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let fscoreDir0 = + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\" + n.Version.ToString() + let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) +#endif + + let isFileName = + r.EndsWith("dll",StringComparison.OrdinalIgnoreCase) || + r.EndsWith("exe",StringComparison.OrdinalIgnoreCase) + + let qual = if isFileName then r else try AssemblyName(r).Name + ".dll" with _ -> r + ".dll" + + for searchPath in searchPaths do + try + if not found then + let trialPath = Path.Combine(searchPath,qual) + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) + +#if !RESHAPED_MSBUILD + try + // Seach the GAC on Windows + if not found && not isFileName && Environment.OSVersion.Platform = PlatformID.Win32NT then + let n = AssemblyName(r) + let netfx = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + let gac = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(netfx.TrimEnd('\\'))),"assembly") + match n.Version, n.GetPublicKeyToken() with + | null, _ | _,null -> + let options = + [ for gacdir in Directory.EnumerateDirectories(gac) do + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + for tdir in Directory.EnumerateDirectories(assdir) do + let trialPath = Path.Combine(tdir,qual) + if FileSystem.SafeExists(trialPath) then + yield trialPath ] + //printfn "sorting GAC paths: %A" options + options + |> List.sort // puts latest version last + |> List.tryLast + |> function None -> () | Some p -> success p + + | v,tok -> + for gacdir in Directory.EnumerateDirectories(gac) do + //printfn "searching GAC directory: %s" gacdir + let assdir = Path.Combine(gacdir,n.Name) + if Directory.Exists(assdir) then + //printfn "searching GAC directory: %s" assdir + + let tokText = String.concat "" [| for b in tok -> sprintf "%02x" b |] + let verdir = Path.Combine(assdir,"v4.0_"+v.ToString()+"__"+tokText) + //printfn "searching GAC directory: %s" verdir + + if Directory.Exists(verdir) then + let trialPath = Path.Combine(verdir,qual) + //printfn "searching GAC: %s" trialPath + if FileSystem.SafeExists(trialPath) then + success trialPath + with e -> logWarning "SR001" (e.ToString()) +#endif + + results.ToArray() } + +let internal GetBestAvailableResolver(msbuildEnabled: bool) = +#if RESHAPED_MSBUILD + ignore msbuildEnabled +#else + let tryMSBuild v = + // Detect if MSBuild is on the machine, if so use the resolver from there + let mb = try Assembly.Load(sprintf "Microsoft.Build.Framework, Version=%s.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" v) |> Option.ofObj with _ -> None + let ass = mb |> Option.bind (fun _ -> try Assembly.Load(sprintf "FSharp.Compiler.Service.MSBuild.v%s" v) |> Option.ofObj with _ -> None) + let ty = ass |> Option.bind (fun ass -> ass.GetType("Microsoft.FSharp.Compiler.MSBuildReferenceResolver") |> Option.ofObj) + let obj = ty |> Option.bind (fun ty -> ty.InvokeMember("get_Resolver",BindingFlags.Static ||| BindingFlags.Public ||| BindingFlags.InvokeMethod ||| BindingFlags.NonPublic, null, null, [| |]) |> Option.ofObj) + let resolver = obj |> Option.bind (fun obj -> match obj with :? Resolver as r -> Some r | _ -> None) + resolver + match (if msbuildEnabled then tryMSBuild "12" else None) with + | Some r -> r + | None -> +#endif + SimulatedMSBuildResolver + + +#if INTERACTIVE +// Some manual testing +SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory +SimulatedMSBuildResolver.HighestInstalledNetFrameworkVersion() + +let fscoreDir = + if System.Environment.OSVersion.Platform = System.PlatformID.Win32NT then // file references only valid on Windows + let PF = + match Environment.GetEnvironmentVariable("ProgramFiles(x86)") with + | null -> Environment.GetEnvironmentVariable("ProgramFiles") // if PFx86 is null, then we are 32-bit and just get PF + | s -> s + PF + @"\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0" + else + System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + +let resolve s = + SimulatedMSBuildResolver.Resolve(ResolutionEnvironment.CompileTimeLike,[| for a in s -> (a, "") |],"v4.5.1", [SimulatedMSBuildResolver.DotNetFrameworkReferenceAssembliesRootDirectory + @"\v4.5.1" ],"", "", fscoreDir,[],__SOURCE_DIRECTORY__,ignore, (fun _ _ -> ()), (fun _ _-> ())) + +// Resolve partial name to something on search path +resolve ["FSharp.Core" ] + +// Resolve DLL name to something on search path +resolve ["FSharp.Core.dll" ] + +// Resolve from reference assemblies +resolve ["System"; "mscorlib"; "mscorlib.dll" ] + +// Resolve from Registry AssemblyFolders +resolve ["Microsoft.SqlServer.Dmf.dll"; "Microsoft.SqlServer.Dmf" ] + +// Resolve exact version of FSharp.Core +resolve [ "FSharp.Core, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ] + +// Resolve from GAC: +resolve [ "EventViewer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ] + +// Resolve from GAC: +resolve [ "EventViewer" ] + +resolve [ "Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] +resolve [ "Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ] +#endif + diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index d32cb46899..ddeae1ff2f 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -2317,7 +2317,7 @@ let internal DriveFsiEventLoop (fsi: FsiEvaluationSessionHostConfig, fsiConsoleO /// The primary type, representing a full F# Interactive session, reading from the given /// text input, writing to the given text output and error writers. -type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], inReader:TextReader, outWriter:TextWriter, errorWriter: TextWriter, fsiCollectible: bool, msbuildEnabled: bool, msbuildVersion: string option) = +type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], inReader:TextReader, outWriter:TextWriter, errorWriter: TextWriter, fsiCollectible: bool, msbuildEnabled: bool) = #if DYNAMIC_CODE_REWRITES_CONSOLE_WRITE do Microsoft.FSharp.Core.Printf.setWriter outWriter @@ -2374,7 +2374,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i if containsRequiredFiles then defaultFSharpBinariesDir else Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value - let referenceResolver = ReferenceResolver.GetDefaultResolver(msbuildEnabled, msbuildVersion) + let referenceResolver = SimulatedMSBuildReferenceResolver.GetBestAvailableResolver(msbuildEnabled) let tcConfigB = TcConfigBuilder.CreateNew(referenceResolver, defaultFSharpBinariesDir, @@ -2721,8 +2721,8 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i GC.KeepAlive fsiInterruptController.EventHandlers - static member Create(fsiConfig, argv, inReader, outWriter, errorWriter, ?collectible, ?msbuildEnabled, ?msbuildVersion) = - new FsiEvaluationSession(fsiConfig, argv, inReader, outWriter, errorWriter, defaultArg collectible false, defaultArg msbuildEnabled true, msbuildVersion) + static member Create(fsiConfig, argv, inReader, outWriter, errorWriter, ?collectible, ?msbuildEnabled) = + new FsiEvaluationSession(fsiConfig, argv, inReader, outWriter, errorWriter, defaultArg collectible false, defaultArg msbuildEnabled true) static member GetDefaultConfiguration(fsiObj:obj) = FsiEvaluationSession.GetDefaultConfiguration(fsiObj, true) diff --git a/src/fsharp/fsi/fsi.fsi b/src/fsharp/fsi/fsi.fsi index 11d73cf297..6c9c343486 100644 --- a/src/fsharp/fsi/fsi.fsi +++ b/src/fsharp/fsi/fsi.fsi @@ -124,7 +124,7 @@ type FsiEvaluationSession = /// Read input from the given reader /// Write output to the given writer /// Optionally make the dynamic assmbly for the session collectible - static member Create : fsiConfig: FsiEvaluationSessionHostConfig * argv:string[] * inReader:TextReader * outWriter:TextWriter * errorWriter: TextWriter * ?collectible: bool * ?msbuildEnabled: bool * ?msbuildVersion: string -> FsiEvaluationSession + static member Create : fsiConfig: FsiEvaluationSessionHostConfig * argv:string[] * inReader:TextReader * outWriter:TextWriter * errorWriter: TextWriter * ?collectible: bool * ?msbuildEnabled: bool -> FsiEvaluationSession /// A host calls this to request an interrupt on the evaluation thread. member Interrupt : unit -> unit diff --git a/src/fsharp/vs/SimpleServices.fs b/src/fsharp/vs/SimpleServices.fs index 388ce543a9..e9a596e327 100644 --- a/src/fsharp/vs/SimpleServices.fs +++ b/src/fsharp/vs/SimpleServices.fs @@ -108,9 +108,9 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices member x.GetDeclarations(line, col, qualifyingNames, partialName, ?xmlCommentRetriever) = x.GetDeclarationListInfo(Line.fromZ line, col, qualifyingNames, partialName, ?xmlCommentRetriever=xmlCommentRetriever) /// Provides simple services for checking and compiling F# scripts - type public SimpleSourceCodeServices(?msbuildEnabled, ?msbuildVersion) = + type public SimpleSourceCodeServices(?msbuildEnabled) = - let checker = InteractiveChecker.Create(?msbuildEnabled=msbuildEnabled, ?msbuildVersion=msbuildVersion) + let checker = InteractiveChecker.Create(?msbuildEnabled=msbuildEnabled) let fileversion = 0 let loadTime = DateTime.Now let referenceResolver = checker.ReferenceResolver diff --git a/src/fsharp/vs/SimpleServices.fsi b/src/fsharp/vs/SimpleServices.fsi index 703bbe3f19..e729057b26 100644 --- a/src/fsharp/vs/SimpleServices.fsi +++ b/src/fsharp/vs/SimpleServices.fsi @@ -81,7 +81,7 @@ type SimpleCheckFileResults = type SimpleSourceCodeServices = /// Create a singleton global isntance for checking and compiling F# scripts - new: ?msbuildEnabled: bool * ?msbuildVersion : string-> SimpleSourceCodeServices + new: ?msbuildEnabled: bool -> SimpleSourceCodeServices /// Tokenize a single line, returning token information and a tokenization state represented by an integer member TokenizeLine: line:string * state:int64 -> FSharpTokenInfo [] * int64 diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index 03f2e57b4a..f6f8c5fdff 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -2736,8 +2736,8 @@ type FSharpChecker(referenceResolver, projectCacheSize, keepAssemblyContents, ke let maxMemEvent = new Event() /// Instantiate an interactive checker. - static member Create(?projectCacheSize, ?keepAssemblyContents, ?keepAllBackgroundResolutions, ?msbuildEnabled, ?msbuildVersion) = - let referenceResolver = ReferenceResolver.GetDefaultResolver(defaultArg msbuildEnabled true, msbuildVersion) + static member Create(?projectCacheSize, ?keepAssemblyContents, ?keepAllBackgroundResolutions, ?msbuildEnabled) = + let referenceResolver = SimulatedMSBuildReferenceResolver.GetBestAvailableResolver(defaultArg msbuildEnabled true) let keepAssemblyContents = defaultArg keepAssemblyContents false let keepAllBackgroundResolutions = defaultArg keepAllBackgroundResolutions true let projectCacheSizeReal = defaultArg projectCacheSize projectCacheSizeDefault diff --git a/src/fsharp/vs/service.fsi b/src/fsharp/vs/service.fsi index 4dd6db6bf0..18b91f61e3 100755 --- a/src/fsharp/vs/service.fsi +++ b/src/fsharp/vs/service.fsi @@ -413,7 +413,8 @@ type FSharpChecker = /// The optional size of the project checking cache. /// Keep the checked contents of projects. /// If false, do not keep full intermediate checking results from background checking suitable for returning from GetBackgroundCheckResultsForFileInProject. This reduces memory usage. - static member Create : ?projectCacheSize: int * ?keepAssemblyContents: bool * ?keepAllBackgroundResolutions: bool * ?msbuildEnabled: bool * ?msbuildVersion: string -> FSharpChecker + /// If false, no dependency on MSBuild v12 is assumed. If true, at attempt is made to load MSBuild for reference resolution in scripts + static member Create : ?projectCacheSize: int * ?keepAssemblyContents: bool * ?keepAllBackgroundResolutions: bool * ?msbuildEnabled: bool -> FSharpChecker /// /// Parse a source code file, returning information about brace matching in the file. @@ -730,7 +731,7 @@ type FSharpChecker = [] member TypeCheckSource : parsed: FSharpParseFileResults * filename: string * fileversion: int * source: string * options: FSharpProjectOptions * isResultObsolete: IsResultObsolete * textSnapshotInfo: obj -> FSharpCheckFileAnswer option - // One shared global singleton for use by multiple add-ins + [] static member Instance : FSharpChecker member internal FrameworkImportsCache : FrameworkImportsCache member internal ReferenceResolver : ReferenceResolver.Resolver From 93e26199cb575050ebf473ccb763918dc5abd2a1 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 13 Oct 2016 15:13:58 +0100 Subject: [PATCH 19/19] integrate master --- src/fsharp/ReferenceResolver.fs | 7 ++++++- src/fsharp/SimulatedMSBuildReferenceResolver.fs | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/fsharp/ReferenceResolver.fs b/src/fsharp/ReferenceResolver.fs index 0b46ada3f3..5c8737e575 100644 --- a/src/fsharp/ReferenceResolver.fs +++ b/src/fsharp/ReferenceResolver.fs @@ -34,6 +34,11 @@ type Resolver = /// a .NET Framework version to use for scripts. abstract HighestInstalledNetFrameworkVersion : unit -> string + /// Get the Reference Assemblies directory for the .NET Framework (on Windows) + /// This is added to the default resolution path for + /// design-time compilations. + abstract DotNetFrameworkReferenceAssembliesRootDirectory : string + /// Perform assembly resolution on the given references under the given conditions abstract Resolve : resolutionEnvironment: ResolutionEnvironment * @@ -47,5 +52,5 @@ type Resolver = explicitIncludeDirs:string list * implicitIncludeDir:string * logMessage:(string->unit) * - logErrorOrWarning:(bool -> string -> string -> unit) + logErrorOrWarning:((*isError*)bool -> string -> string -> unit) -> ResolvedFile[] diff --git a/src/fsharp/SimulatedMSBuildReferenceResolver.fs b/src/fsharp/SimulatedMSBuildReferenceResolver.fs index eea6bee33e..3fbcf906f4 100644 --- a/src/fsharp/SimulatedMSBuildReferenceResolver.fs +++ b/src/fsharp/SimulatedMSBuildReferenceResolver.fs @@ -32,7 +32,7 @@ let internal SimulatedMSBuildResolver = #endif member __.Resolve(resolutionEnvironment, references, targetFrameworkVersion, targetFrameworkDirectories, targetProcessorArchitecture, - outputDirectory, fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarning, logError) = + fsharpCoreDir, explicitIncludeDirs, implicitIncludeDir, logMessage, logWarningOrError) = #if !RESHAPED_MSBUILD let registrySearchPaths() = @@ -88,7 +88,7 @@ let internal SimulatedMSBuildResolver = if not found && Path.IsPathRooted(r) then if FileSystem.SafeExists(r) then success r - with e -> logWarning "SR001" (e.ToString()) + with e -> logWarningOrError false "SR001" (e.ToString()) #if !RESHAPED_MSBUILD // For this one we need to get the version search exactly right, without doing a load @@ -104,7 +104,7 @@ let internal SimulatedMSBuildResolver = let trialPath = Path.Combine(fscoreDir0,n.Name + ".dll") if FileSystem.SafeExists(trialPath) then success trialPath - with e -> logWarning "SR001" (e.ToString()) + with e -> logWarningOrError false "SR001" (e.ToString()) #endif let isFileName = @@ -119,7 +119,7 @@ let internal SimulatedMSBuildResolver = let trialPath = Path.Combine(searchPath,qual) if FileSystem.SafeExists(trialPath) then success trialPath - with e -> logWarning "SR001" (e.ToString()) + with e -> logWarningOrError false "SR001" (e.ToString()) #if !RESHAPED_MSBUILD try @@ -160,7 +160,7 @@ let internal SimulatedMSBuildResolver = //printfn "searching GAC: %s" trialPath if FileSystem.SafeExists(trialPath) then success trialPath - with e -> logWarning "SR001" (e.ToString()) + with e -> logWarningOrError false "SR001" (e.ToString()) #endif results.ToArray() }