How to handle relative paths with Github Actions?

Hi, we have this sample repository

and want to make this PR pass

Currently this is the workflow we are using

The pull request doesn’t pass because the “Build” step fails with the error message

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

So it seems the workflow can’t find the project files. Although I tried to cd into the project with this

run: | 
cd ./RestMongo
dotnet restore

What is the workflow starting point? How can I fix the workflow?

The sample tests pass locally. Thanks in advance!

You can use the working-directory keyword to specify the working directory for a run step:

run: |
  dotnet restore
working-directory: ./RestMongo

I’m not familiar with .NET, but I assume you’ll have to do that for each of the steps that call dotnet.

Thank you very much! :slight_smile:
A working solution for me is

name: Test PR

on:
  pull_request:
    branches: [main]

jobs:
  test_pull_request:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: 5.0.x

      - name: Restore dependencies
        run: dotnet restore
        working-directory: ./RestMongo

      - name: Build	
        run: dotnet build --no-restore
        working-directory: ./RestMongo

      - name: Test
        run: dotnet test --no-build --verbosity normal
        working-directory: ./RestMongo
2 Likes