我正在尝试将现有的ASP.NET MVC Web应用程序从TeamCity转移到Azure DevOps,但是我似乎无法让我的管道找到从NuGet包还原任务中还原的包。 / p>
该解决方案有多个项目,并且它们使用大量的NuGet软件包。我创建了一个多步骤管道,该管道目前具有一个NuGet Restore任务和一个VS Build任务。
解决方案结构如下:
\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>
有人会有见识吗?谢谢。
答案 0 :(得分:0)
您应将任务 VSBuild @ 1 和 NuGetCommand @ 2 包含在同一作业下。
我在本地托管代理上进行了测试,发现运行 vsbuild 任务的第二个作业将清除工作文件夹并重新获取源代码,从而删除第一个作业任务创建的packages文件夹> nugetcommand 。这可能是导致错误的原因。
所以管道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'
- 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)'