尝试使用 DocFX 会导致错误“无法检测到 MSBuild 实例”

问题描述 投票:0回答:1

我使用命令行向导创建了一个 docFx 项目。当我尝试使用 docfx ./docfx.json 呈现文档时,出现以下错误:

ExtractMetadataException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
     InvalidOperationException: No instances of MSBuild could be detected.
     Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
       at VisualStudioInstance RegisterDefaults()
       at void EnsureMSBuildLocator() in DotnetApiCatalog.cs:126
  at void EnsureMSBuildLocator() in DotnetApiCatalog.cs:134
  at async Task Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory) in DotnetApiCatalog.cs:60
  at void <Execute>b__0() in DefaultCommand.cs:45
  at int Run(LogOptions options, Action run) in CommandHelper.cs:48
  at int Execute(CommandContext context, Options options) in DefaultCommand.cs:31
  at Task<int> Execute(CommandContext context, CommandSettings settings) in CommandOfT.cs:40
  at async Task<int> Execute(CommandTree leaf, CommandTree tree, CommandContext context, ITypeResolver resolver, IConfiguration configuration) in CommandExecutor.cs:166

这是 dotnet --list-sdks 的输出:

7.0.403 [C:\Program Files\dotnet\sdk]

目标项目使用.NET 7.0,并编译(这是一个新创建的项目,空保存默认的“Hello world!”打印)

这是 docfx.json 文件:

{
  "metadata": [
    {
      "src": [
        {
          "src": "C:/Users/my_user/Repos/Tests/docfx_test/dotnet_project/dotnet_project",
          "files": [
            "**/*.csproj"
          ]
        }
      ],
      "dest": ""
    }
  ],
  "build": {
    "content": [
      {
        "files": [
          "**/*.{md,yml}"
        ],
        "exclude": [
          "_site/**"
        ]
      }
    ],
    "resource": [
      {
        "files": [
          "images/**"
        ]
      }
    ],
    "output": "_site",
    "template": [
      "default",
      "modern"
    ],
    "globalMetadata": {
      "_appName": "TestDocumentation",
      "_appTitle": "TestDocumentation",
      "_enableSearch": true,
      "pdf": true
    }
  }
}
c# msbuild docfx
1个回答
0
投票

现在可以了,但我不知道为什么。我尝试卸载除 6.0 之外的所有 .NET 运行时,但没有成功。然后我重新安装了7.0版本,还是不行。我安装了8.0,没用。

之后我卸载并重新安装了 docfx 本身,现在它可以工作了。我不确定哪种重新安装组合可以解决问题,但很明显,当我第一次安装 docfx 时,某些东西尚未正确初始化。

© www.soinside.com 2019 - 2024. All rights reserved.