1

I add github action to my repo to test my branch and then merge it to the master but it gives me this error :

MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.

there are 4 projects in solution

so how can I solve this problem ?

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

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


1 Answers1

10

This usually happens when you are starting with a single project, and your .sln-file ends up inside a project folder. Easiest way out of this, is to move .sln-file one folder level up.

Additional resource for moving the .sln-file (credit to @Charles): https://stackoverflow.com/a/626646/14072498

Just click on the solution in the Solution Explorer and then click on "Save myProject.sln as..." in the File Menu. This will save your .sln in the folder that you choose without breaking the references.

To fix this without moving .sln-file, follow the list below.

Replace WebApplication.sln and WebApplication/WebApplication.csproj with corresponding names from your app below.

run: dotnet restore ./WebApplication.sln

run: dotnet build WebApplication/WebApplication.csproj --configuration Release --no-restore

For the tests, point to .sln-file

run: dotnet test ./WebApplication.sln --configuration Release --no-restore
Roar S.
  • 8,103
  • 1
  • 15
  • 37
  • This happened to me last night, was able to fix by selecting the Solution node within Solution Explorer, then File->Save [solution name] As... and choosing one folder up from project file. Additionally, after the save, it's okay to delete the previous sln file. Might want to update this answer to include those additional steps given that references will break if you just "move" it. – Charles Dec 22 '22 at 17:46
  • Hi @Charles. Thanks for the suggestion. Just to make sure I understand this correct: What caused the trouble was that you copied the .sln-file one level up and didn't remove the old one? BR – Roar S. Dec 22 '22 at 17:55
  • IIRC I did delete the solution file that was in the same folder as the project file after copying one level up. However, some references were broken and I wasn't able to load the project from new solution file, nor was I able to manually edit the solution file path in Properties window. Instead, I had to revert the change/commit, then go the "Save As..." route. Only after that was I able to remove the previous solution file + have everything work and run properly. Was working with VS2022 and an ASP net core web api, FWIW. – Charles Dec 22 '22 at 17:59
  • I had also tried finding the "Recover Solution File" option (or something like that) but it wasn't present. – Charles Dec 22 '22 at 18:00
  • 1
    https://stackoverflow.com/questions/626631/how-to-relocate-visual-studio-project-sln-file was the other post I went by to "move" the sln file after I encountered the breaking change. – Charles Dec 22 '22 at 18:05
  • Thanks @Charles. I'll add a link to that answer. BR – Roar S. Dec 22 '22 at 18:18