Dot-Net-Core

Github Action DotNetCore sln 和項目在同一個文件夾中

  • May 25, 2022
name: .NET Core

上:推:分支:

$$ master $$ pull_request:分支:$$ master $$ 工作: 建造:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
 uses: actions/setup-dotnet@v1
 with:
   dotnet-version: 3.1.101
- name: Install dependencies
 run: dotnet restore
- name: Build
 run: dotnet build --configuration Release --no-restore
- name: Test
 run: dotnet test --no-restore --verbosity normal

這是我的 yml 程式碼。它顯示錯誤 MSBUILD:錯誤 MSB1003:指定項目或解決方案文件。目前工作目錄不包含項目或解決方案文件。

$$ error $$過程以退出程式碼 1 完成。

dotnet restore步驟中,因為項目文件夾中的 sln。如何解決這個問題呢

只需定義具有解決方案或項目文件的目錄的路徑。假設項目文件位置是src/MyProject/MyProject.csproj,那麼Install dependencies步驟應該是:

- name: Install dependencies
 run: dotnet restore
 working-directory: src/MyProject

指定解決方案名稱

- name: Build with dotnet
 run: dotnet build Document.Approval.sln --configuration Release

- name: dotnet publish
 run: dotnet publish Document.Approval.sln -c Release -o ${{env.DOTNET_ROOT}}/myapp

引用自:https://stackoverflow.com/questions/61188284