首页 > 解决方案 > dotnet 格式验证抛出 dll not found

问题描述

我想根据 .editorconfig 验证我的应用程序的代码样式。对于此任务,我在 azure (2019) ci 管道中使用本地托管代理。我只被允许使用本地提要。所以我下载了 5.1.225507 版本的 dotnet-format并将其添加到提要中。

通过 yaml 管道中的以下步骤,我尝试验证代码样式:

# working build and test here...
    - task: DotNetCoreCLI@2
      displayName: 'dotnet install dotnet-format'
      inputs:
        command: custom
        custom: tool
        arguments: 'update -g dotnet-format --configfile ./.nuget/NuGetBuildServer.Config'

    - task: DotNetCoreCLI@2
      displayName: 'Validiere Codestil'
      inputs:
        command: custom
        custom: format
        arguments: '-v diag --configfile ./.nuget/NuGetBuildServer.Config --check --verbosity diagnostic --no-restore --verify-no-changes --severity info'
# working publishing here...

安装错误的运行时失败并出现错误。如何告诉 dotnet 使用 sdk 作为运行时?它已安装:

[command]C:\dotnet\dotnet.exe --list-sdks
5.0.201 [C:\dotnet\sdk]

标签: .netazureazure-devopsdotnet-format

解决方案


要使 SDK 在本地使用最新安装的版本,您需要在 global.json 文件中指定该版本。

如果未找到global.json中指定的 SDK,.NET CLI 将使用匹配规则来选择兼容的 SDK,如果找不到,则失败。

global.json 语法:

{
  "sdk": {
    "version": "5.0.0"
  }
}

参考: 选择要使用的 .NET 版本 - .NET | 微软文档


推荐阅读