到目前为止,我有一个非常基本的构建管道
# 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 Restore任务,以将软件包还原到..\new_packages
目录,然后希望VSBuild Task从那里获取它们并构建解决方案。
Nuget Restore执行以下命令(全部一行)
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在Visual Studio Online上找不到还原的NuGet软件包
他们的解决方案(尽管很笨拙)对我也不起作用。
如果我删除EPPlus软件包,则下一个软件包Entity Framework
将产生相同的错误。
如果删除Entity Framework
下一个包,将产生相同的错误。
我只是想为此找到一个真正的解决方案,它不涉及这些硬编码黑客(显然,..和有效)
编辑:
努力工作,非常感谢Leo Liu-MSFT
。
我的回答是在那下面。
Azure devops Cant为Nuget程序包连接Nuget Restore和VSBuild
除非您HintPath
在项目文件中进行修改,否则恐怕无法使其正常工作。
当您将还原到..\new_packages
目录的nuget软件包更改为目录时,还原后,新目录中的软件包应具有以下结构级别:
d:\a\1\new_packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll
dll文件以nuget包的形式存储在新目录中,而不是直接存储在新目录中。
因此,当您/p:ReferencePath="d:\a\1\new_packages"
在构建项目时指定时,VS将dll
直接从中找到文件ReferencePath
。收到错误消息的原因是:
被视为“ d:\ a \ 1 \ new_packages \ EPPlus.dll”
实际上,dll
路径应为d:\a\1\new_packages\EPPlus.4.5.3.2\lib\net40
。由于此路径与软件包的名称和版本有关,因此我们无法使用一个参数来指定multiple的路径dlls
。
在这种情况下,我们必须修改HintPath
项目文件中的。
正确的过程是更改nuget.config
文件中的repositoryPath以更改本地的nuget软件包目录:
然后Update-Package -reinstall
在软件包管理器控制台中使用命令行强制将软件包引用重新安装到本地的项目中,它将更新HintPath
所有软件包的,然后将更改提交给源控件。然后我们可以使用Nuget Restore任务将软件包还原到..\new_packages
目录
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句