如何在Azure DevOps Pipeline中指定解决方案文件

23

我在配置Azure DevOps Dotnet core构建过程时遇到了麻烦。

我有一个简单的dotnet core项目,我正在尝试在Azure DevOps环境中构建它。

该项目位于我的存储库中的子文件夹中,但我无法弄清楚如何指定管道应如何找到我的csproj文件。MSDN文档表明您可以指定它,但没有示例,并且我的所有尝试都会遇到错误。

使用标准dotnet CLI模板构建管道时,YAML创建为:

# ASP.NET Core
# Build and test ASP.NET Core web applications targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/languages/dotnet-core

pool:
  vmImage: 'Ubuntu 16.04'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

然而,这遇到了错误:

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

以上链接的文档建议使用“任务”基础语法而不是脚本,并且我认为在文档中输入的顺序与列在下面的示例相同。

1个回答

24
如果您使用 script,则需在 build 之后指定 csproj 文件:
- script: dotnet build myrepo/test/test.csproj --configuration $(buildConfiguration)

使用 Azure DevOps Pipeline 的最佳方法是为构建流水线使用任务,在 Dotnet Core YAML 构建任务中,您可以在 inputs 部分指定文件:

- task: DotNetCoreCLI@2
  inputs:
    command: 'build' 
    projects: 'myrepo/test/test.csproj'

4
谢谢!我原本认为使用任务(Tasks)是更好的选择,然而 Azure Devops 自带的管道(pipelines)设计器却因某些原因创建了一个使用 dotnet build 脚本的 YAML 文件。有了你的示例,我成功地创建了一个使用 DotnetCoreCLI 任务的构建任务。 - JLo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接