【发布时间】:2020-01-09 22:44:09
【问题描述】:
到目前为止,我有一个非常基本的构建管道
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- testing-build-yml-1
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
# packagesDirectory: '..\packages'
restoreDirectory: '..\new_packages'
- task: VSBuild@1
inputs:
solution: '$(solution)'
#msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:ReferencePath="d:\a\1\new_packages"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
我正在尝试使用 Nuget 还原任务将包恢复到 ..\new_packages 目录,随后希望 VSBuild 任务能够从那里获取它们并构建解决方案。
Nuget 还原执行以下命令(全部在一行中)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe
"C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\jgtjjpe0.nac.nugetinputs.targets"
/t:GenerateRestoreGraphFile
/nologo
/nr:false
/v:q
/p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\whba0xm4.c0f.nugetrestore.targets"
/p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe"
/p:RestoreSolutionDirectory="D:\a\1\s\\"
/p:RestoreConfigFile="D:\a\1\Nuget\tempNuGet_105.config"
/p:RestorePackagesPath="..\new_packages"
/p:SolutionDir="D:\a\1\s\\"
/p:SolutionName="XYZ"
然后 VSBuild Task 运行 msbuild(都在一行中)
##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe"
"D:\a\1\s\XYZ.sln"
/nologo
/nr:false
/dl:CentralLogger,
"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.161.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";
"RootDetailId=e5869970-8e7b-4a06-a8fd-f0662f639a6d|SolutionDir=D:\a\1\s"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.161.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="D:\a\1\a"
/p:ReferencePath="d:\a\1\new_packages"
/p:platform="Any CPU"
/p:configuration="Release"
/p:VisualStudioVersion="16.0"
/p:_MSDeployUserAgent="VSTS_607486bc-2d64-463d-9a7f-0cf06fe82263_build_16_0"
解决方案查看/p:ReferencePath="d:\a\1\new_packages 中指定的相应目录。
但它仍然找不到 Nuget 包的任何 dll,最终构建失败。
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 1/9/2020 10:11:18 PM.
Project "D:\a\1\s\XYZ.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Release|Any CPU".
Project "D:\a\1\s\XYZ.sln" (1) is building "D:\a\1\s\ServiceLayer\InputOutputServiceLayer.csproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Release\".
Creating directory "obj\Release\".
ResolveAssemblyReferences:
Primary reference "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL".
##[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 "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
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 "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\1\s\ServiceLayer\InputOutputServiceLayer.csproj]
For SearchPath "d:\a\1\new_packages".
Considered "d:\a\1\new_packages\EPPlus.winmd", but it didn't exist.
Considered "d:\a\1\new_packages\EPPlus.dll", but it didn't exist.
Considered "d:\a\1\new_packages\EPPlus.exe", but it didn't exist.
For SearchPath "{HintPathFromItem}".
Considered "D:\a\1\s\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll", but it didn't exist.
从技术上讲,我知道我们不应该硬编码 /p:ReferencePath=.. 这样做,但我只是想让它工作。
没有那个 VSBuild Task 似乎不知道去哪里找。
它看着
ResolveAssemblyReferences:
Primary reference "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL".
##[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 "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
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 "EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [d:\a\1\s\ServiceLayer\InputOutputServiceLayer.csproj]
For SearchPath "..\d:\a\1\a".
Considered "..\d:\a\1\a\EPPlus.winmd", but it didn't exist.
Considered "..\d:\a\1\a\EPPlus.dll", but it didn't exist.
Considered "..\d:\a\1\a\EPPlus.exe", but it didn't exist.
For SearchPath "{HintPathFromItem}".
Considered "d:\a\1\s\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll", but it didn't exist.
For SearchPath "{TargetFrameworkDirectory}".
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\EPPlus.winmd", but it didn't exist.
使用管道的旧方式也有类似的问题
MsBuild does not find restored NuGet-Packages on Visual Studio Online
他们的解决方案(虽然很老套)对我也不起作用。
如果我删除 EPPlus 包,下一个包 Entity Framework 将产生相同的错误。
如果我删除 Entity Framework 下一个包将产生相同的错误。
我只是想为此找到一个真正的解决方案,它不涉及这些硬编码黑客(..并且很明显)
编辑:
感谢Leo Liu-MSFT。
我的答案在那个下面。
【问题讨论】:
标签: c# msbuild azure-devops nuget nuget-package-restore