我正在尝试在 Azure DevOps
上恢复 .Net Core 项目,如下所示:
steps:
- task: PowerShell@2
displayName: 'Get solution path'
inputs:
targetType: 'inline'
script: |
$solutionPath = Get-ChildItem -Filter *.sln -Recurse | Select-Object -Expand Directory -First 1
Write-Host "##vso[task.setvariable variable=solutionPath]$solutionPath"
- task: PowerShell@2
displayName: 'Restore'
inputs:
targetType: 'inline'
script: |
dotnet restore
workingDirectory: "$(solutionPath)"
- task: DotNetCoreCLI@2
displayName: 'Restore'
inputs:
command: 'restore'
workingDirectory: "$(solutionPath)"
我使用 PowerShell
的第一个恢复任务工作得很好,但我使用 DotNetCoreCLI
的第二个恢复任务失败并出现以下错误:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
最佳答案
您可以用更简单的方式做到这一点
#Restore packages with the .NET Core CLI task
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: 'restore'
projects: '**/*.sln'
如果您想使用自己的方式,请确保在恢复之前通过列出文件来选择正确的路径
- script: ls '$(solutionPath)'
关于.net - 无法在 Azure Devops 上使用 DotNetCoreCLI 任务恢复 .Net Core 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65727200/