sno*_*dog 4 msbuild-task nuget-package-restore azure-devops azure-pipelines multistage-pipeline
我正在尝试将现有的 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
Run Code Online (Sandbox Code Playgroud)
管道 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)'
Run Code Online (Sandbox Code Playgroud)
当管道运行时,恢复任务成功并显示以下输出:
<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
Run Code Online (Sandbox Code Playgroud)
当构建任务在解决方案上运行时,它在遇到的第一个项目上失败并出现以下错误:
[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.
Run Code Online (Sandbox Code Playgroud)
每个包依赖项都会发生相同的错误。看起来包恢复任务将包恢复到这里:
d:\a\1\s\source\SolutionFolder\packages\
Run Code Online (Sandbox Code Playgroud)
根据构建日志,它在分层包文件夹结构中在这里寻找它们,例如:
d:\a\1\s\source\SolutionFolder\packages\<package>\<lib>\<dll>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多事情,包括restoreDirectory从恢复任务中删除参数、在本地运行 MSBuild 命令(它有效)和剥离一些包,但是我仍然看到相同的构建错误。
一些项目文件还包含提示路径;例如格式:
<ItemGroup>
<Reference Include="<some package>">
<HintPath>..\packages\<package>\lib\<dll></HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
有人会有任何见解吗?谢谢。
您应该在同一个作业下包含任务VSBuild@1和NuGetCommand@2。
我在本地托管代理上进行了测试,发现运行vsbuild任务的第二个作业将清除工作文件夹并重新获取源代码,这将删除由第一个作业任务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)'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3253 次 |
| 最近记录: |