How to build a subfolder in Bitbucket Pipelines

Viewed 4662

I am struggling to configure the build in Bitbucket Pipelines.

It's a C# solution and the code is located in a subfolder, rather than in the root folder of the repository. This is why when I build it, I get the error:

+ dotnet restore

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

I've read the docs but there seems to be no option to try to specify a subfolder. How do you configure it then?

Here's my .yml file:

image: microsoft/dotnet:latest

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - export PROJECT_NAME=MyProjectNameHere
          - export TEST_NAME=MyProjectNameHere
          - dotnet restore
          - dotnet build $PROJECT_NAME
          - dotnet test $TEST_NAME
4 Answers

Maybe you could cd into the subfolder before calling the build commands.

image: microsoft/dotnet:latest

pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script:
          - cd MyProject # Set current working directory to subfolder
          - export ...
          - dotnet restore

You could also add checks to print the current folder at any time, with a step that runs pwd ("print working directory").

Now you can also use the project folders and do not need to use the .sln file in the PROJECT_NAME and TEST_NAME variables.

- step:
    caches:
      - dotnetcore
    script: # Modify the commands below to build your repository.
      - export PROJECT_NAME=YourSolutionFolder/YourProjectFolder
      - export TEST_NAME=YourSolutionFolder/YourTestProjectFolder
      - dotnet restore YourSolutionFolder
      - dotnet build $PROJECT_NAME
      - dotnet test $TEST_NAME

I found it by experiment.

image: mcr.microsoft.com/dotnet/core/sdk:3.1
pipelines:
  default:
    - step:
        caches:
          - dotnetcore
        script: # Modify the commands below to build your repository.
          - cd MainDir
          - cd SubDir
          - export PROJECT_NAME=MyProject
          - export TEST_NAME=MyProject.Test
          - dotnet restore 
          - dotnet build $PROJECT_NAME
          - dotnet test $TEST_NAME
Related