我正在努力配置Bitbucket管道中的构建。
它是一个C#解决方案,代码位于子文件夹中,而不是存储库的根文件夹中。这就是为什么当我构建它时,我得到错误:
+ dotnet还原
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
通过实验找到它,文档根本没有提到它。
您需要在两行上使用完整路径和解决方案文件名,并且只需要在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
现在,您还可以使用项目文件夹,而无需使用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
也许你可以在调用构建命令之前将cd
放入子文件夹中。
image: microsoft/dotnet:latest pipelines: default: - step: caches: - dotnetcore script: - cd MyProject # Set current working directory to subfolder - export ... - dotnet restore
您还可以随时添加检查以打印当前文件夹,并执行运行pwd
(“打印工作目录”)的步骤。