我的团队最近已从使用.net框架切换为将F#库使用.net标准2.0。我们在项目上运行一些内部脚本,以自动生成降价文档,这些脚本使用F#Compiler Services SDK分析代码并检索类型元数据,文档注释等。
我们正在使用FSharp.Compiler.Service.ProjectCracker
库读取我们的.fsproj
文件并生成FSharpProjectOptions
实例,以便在运行FSharpChecker.ParseAndCheckFileInProject
方法时使用。但是,对于.net标准项目,调用ProjectCracker.GetProjectOptionsFromProjectFile
时出现以下错误:
System.Exception: Could not load project Example.fsproj in ProjectCollection.
Available tools:
["C:\Program Files (x86)\MSBuild\12.0\bin\amd64";
"C:\Program Files (x86)\MSBuild\14.0\bin\amd64";
"C:\Windows\Microsoft.NET\Framework64\v2.0.50727";
"C:\Windows\Microsoft.NET\Framework64\v3.5";
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319"].
Message: The default XML namespace of the project must be the MSBuild XML namespace.
If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element.
If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.```
是否可以使用Project Cracker库读取.net标准项目文件,还是需要手动解析文件并手动为新库创建FSharpProjectOptions
?
答案 0 :(得分:2)
似乎标准的ProjectCracker软件包不能用于读取.netstandard项目文件。但是,已经有一个Dotnet.ProjInfo可以提供此功能的NuGet程序包。该项目使您可以读取.NET项目文件的所有变体,包括.NET Framework和.NET Core以及project.json和.csproj / .fsproj文件。
该项目没有作为API进行过充分的文档编制(该文档更适合于命令行工具),但是可以在FsAutoComplete library中看到该工具的编程用法。
对于.netstandard项目,您可以使用getProjectInfos
函数,如下所示:
let getProjectInfo additionalMSBuildProps file =
let projDir = Path.GetDirectoryName file
let additionalInfo =
[ "OutputType"
"IsTestProject"
"Configuration"
"IsPackable"
MSBuildKnownProperties.TargetFramework
"TargetFrameworkIdentifier"
"TargetFrameworkVersion"
"MSBuildAllProjects"
"ProjectAssetsFile"
"RestoreSuccess"
"Configurations"
"TargetFrameworks"
"RunArguments"
"RunCommand"
"IsPublishable"
]
let loggedMessages = System.Collections.Concurrent.ConcurrentQueue<string>()
let msBuildExec = Dotnet.ProjInfo.Inspect.msbuild (Dotnet.ProjInfo.Inspect.MSBuildExePath.DotnetMsbuild "dotnet") (fun exePath args -> Utils.runProcess loggedMessages.Enqueue projDir exePath (args |> String.concat " "))
let gp () = Dotnet.ProjInfo.Inspect.getProperties (["TargetPath"; "IsCrossTargetingBuild"; "TargetFrameworks"] @ additionalInfo)
let additionalArgs = additionalMSBuildProps |> List.map (Dotnet.ProjInfo.Inspect.MSBuild.MSbuildCli.Property)
let cliList = [Dotnet.ProjInfo.Inspect.getFscArgs; Dotnet.ProjInfo.Inspect.getResolvedP2PRefs; gp]
file |> Dotnet.ProjInfo.Inspect.getProjectInfos loggedMessages.Enqueue msBuildExec cliList additionalArgs