简体   繁体   中英

Let ParseAndCheckFileInProject recognize symbols from Nuget dependecies

When using FSharp.Compiler.SourceCodeServices.FSharpChecker.ParseAndCheckFileInProject from FSharp Compiler Service for whole-project analysis, how can NuGet dependencies be included for symbolic resolution?

In the project under analysis, some project file ( *.fsproj ) contains some <PackageReference> element, eg <PackageReference Include="NodaTime" Version="3.0.3" /> , and some source file contains an open statement open NodaTime and somewhere some symbol DateInterval refering to NodaTime.DateInterval . For me, the FSharp Compiler Service seems to fail to resolve DateInterval to NodaTime.DateInterval in that source file.

What I am currently doing is, summarized:

let checker = FSharpChecker.Create()
let options: FSharpProjectOptions = { ... }
checker.ParseAndCheckFileInProject (...)

Given that I use ParseAndCheckFileInProject , what is necessary for checker and/or options to consider symbols coming from NuGet dependencies?

I think you have to extract the FSharpProjectOptions from the .fsproj project file. For old-style .NET Framework projects, there used to be a method called ProjectCracker.GetProjectOptionsFromProjectFile that would do this, but it has been replaced with Dotnet.ProjInfo , which also supports .NET Core. See this SO question for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM