我正在尝试将现有的 ASP.NET MVC Web 应用程序从 TeamCity 转移到 Azure DevOps,但是我似乎无法让我的管道找到它从 NuGet 包还原任务恢复的包。
该解决方案有多个项目,它们使用大量的 NuGet 包。我创建了一个多步骤管道,该管道当前具有 NuGet 还原任务和 VS 构建任务。
解决方案结构如下:
\source
..\SolutionFolder
...Solution.sln
..\..\Project1
....Project1.csproj
..\..\Project2
....Project2.csproj
..\..\Packages
azure-pipelines.yaml
NuGet.config
管道 YAML 如下所示:
trigger:
- PipelineBranch
pool:
vmImage: 'windows-latest'
stages:
## NuGet Restore ##
- stage: nuget_restore
displayName: 'Restore nuget packages'
jobs:
- job: nuget_package_restore
steps:
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
command: 'restore'
restoreSolution: 'source/SolutionFolder/Solution.sln'
feedsToUse: 'config'
nugetConfigPath: 'NuGet.Config'
restoreDirectory: '$(Build.SourcesDirectory)\source\SolutionFolder\packages'
## Build ##
- stage: build_for_int
displayName: 'Build to int)'
jobs:
- job: run_build
pool:
vmImage: 'windows-latest'
steps:
- task: VSBuild@1
displayName: 'Build Solution.sln (int)'
inputs:
solution: 'source/SolutionFolder/Solution.sln'
msbuildArgs: '
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
当管道运行时,恢复任务成功,输出如下:
<example package>
Added package 'postal.1.2.2' to folder 'd:\a\1\s\source\SolutionFolder\packages'
<loads more packages>
Installed:
190 package(s) to packages.config projects
当构建任务在解决方案上运行时,它在遇到的第一个项目上失败并出现以下错误:
[warning]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5):
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "postal, Version=1.2.14706.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
...
Considered "d:\a\1\s\source\SolutionFolder\packages\postal.1.2.2\lib\postal.dll", but it didn't exist.
每个包依赖项都会发生相同的错误。看起来包恢复任务将包恢复到这里:
d:\a\1\s\source\SolutionFolder\packages\
根据构建日志,它正在分层包文件夹结构中寻找它们,例如:
d:\a\1\s\source\SolutionFolder\packages\<package>\<lib>\<dll>
我已经尝试了很多方法,包括restoreDirectory
从还原任务中删除参数、在本地运行 MSBuild 命令(它有效)和剥离一些包,但是我仍然看到相同的构建错误。
一些项目文件还包含提示路径;例如格式:
<ItemGroup>
<Reference Include="<some package>">
<HintPath>..\packages\<package>\lib\<dll></HintPath>
</Reference>
有人会有任何见解吗?谢谢。