【问题标题】:dotnet format validation throws dll not founddotnet 格式验证抛出 dll not found
【发布时间】:2021-09-07 09:07:23
【问题描述】:

我想根据 .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]

【问题讨论】:

  • 该错误确切地告诉您问题是什么:您的代理没有安装所需的 .NET 运行时版本。
  • 是的,但我为 .net 5.0.x 构建,这工作正常。为什么会出现这个错误? AFAIK .net 核心包含在 .net 5.0 中。我需要告诉他使用其他版本吗?
  • 恭喜,您的代码在 .NET 5.0 上运行。 dotnet-format 没有,因此出现错误消息。 您应该阅读的内容。
  • 解决了我的问题。我如何使用我安装的 sdk 作为运行时?还是 sdk 不包含 rutime?

标签: .net azure azure-devops dotnet-format


【解决方案1】:

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

如果未找到 global.json 中指定的 SDK,.NET CLI 使用 matching rules 选择兼容的 SDK,如果找不到,则失败。

global.json 语法:

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

参考: Select which .NET version to use - .NET | Microsoft Docs

【讨论】:

    【解决方案2】:

    解决了我的问题。问题是 dotnet format 在默认位置查找 SDK 的位置。运行时环境改为安装在自定义目录中。要指向正确的版本,必须设置变量“DOTNET_ROOT”。添加到变量中:

    - name: dotnet_root
      value: C:\path\to\.net5.0\
    

    这在运行器中添加了变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2011-11-01
      • 2018-12-29
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多