首页 文章

如何在Bitbucket管道中构建子文件夹

提问于
浏览
3

我正在努力配置Bitbucket管道中的构建 .

它是一个C#解决方案,代码位于子文件夹中,而不是存储库的根文件夹中 . 这就是为什么当我构建它时,我得到错误:

dotnet restore MSBUILD:错误MSB1003:指定项目或解决方案文件 . 当前工作目录不包含项目或解决方案文件 .

我已经阅读了文档,但似乎没有选择尝试指定子文件夹 . 那你怎么配置它?

这是我的.yml文件:

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

2 回答

  • 0

    通过实验找到它,文档根本没有提到它 .

    您需要在两行上使用完整路径和解决方案文件名,并且只需在 restore 行上使用文件夹名称:

    image: microsoft/dotnet:latest
    
    pipelines:
      default:
        - step:
            caches:
              - dotnetcore
            script: # Modify the commands below to build your repository.
              - export PROJECT_NAME=FolderNameHere/MySolution.sln # use the full path and solution file name
              - export TEST_NAME=FolderNameHere/MySolution.sln # use the full path and solution file name
              - dotnet restore FolderNameHere # use only folder name here
              - dotnet build $PROJECT_NAME
              - dotnet test $TEST_NAME
    
  • 4

    现在,您还可以使用项目文件夹,而无需使用PROJECT_NAME和TEST_NAME变量中的.sln文件 .

    - 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
    

相关问题