You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions配置Nuget缓存报every step must define `uses`/`run`错如何解决

错误原因

你的YAML语法配置错误:Cache Nuget步骤的name和uses被拆成了两个独立的步骤条目,单独的- name: Cache Nuget属于没有配置uses或run字段的无效步骤,因此触发every step must define a \uses` or `run` key`报错。

修正方案

将缓存步骤的name和uses合并为同一个步骤条目,删除uses前多余的破折号并调整缩进即可,也推荐将actions/cache升级到最新稳定版v3提升兼容性,修正后的缓存步骤如下:

- name: Cache Nuget
  uses: actions/cache@v3
  with:
    path: ~/.nuget/packages
    key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
    restore-keys: |
      ${{ runner.os }}-nuget-

完整修正后的Workflow配置

name: Build and Tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Cache Nuget
      uses: actions/cache@v3
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
        restore-keys: |
          ${{ runner.os }}-nuget-
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Run Tests
      run: dotnet test --configuration Release --no-build --verbosity minimal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
    - name: Publish coverage report to coveralls.io   
      uses: coverallsapp/github-action@master   
      with:
       github-token: ${{ secrets.GITHUB_TOKEN }} 
       path-to-lcov: Tests/App.Tests/TestResults/coverage.info 

调整后缓存逻辑可以正常生效,后续的构建、测试步骤无需修改,dotnet restore会优先读取命中的缓存内容,没有命中时才会远程拉取Nuget包。

内容的提问来源于stack exchange,提问作者Józef Podlecki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 09:09:10