MsBuild 在 Visual Studio Online 上找不到恢复的 NuGet 包

Ole*_*ers 5 c# msbuild nuget azure-devops

我尝试构建一个存储在 Visual Studio Online 上的外部 GIT 存储库中的解决方案。

它有以下步骤:

1:Git 恢复 - 有效

2:NuGet 恢复 - 有效

3:构建 - 不起作用

查看日志时我的第一个猜测是 MsBuild 没有查找 NuGet 存储它们的包。NuGet Restore 中的一些行:

2018-03-14T21:10:11.0352862Z Completed installation of AngleSharp 0.9.9
2018-03-14T21:10:11.0353230Z Adding package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages'
2018-03-14T21:10:11.0353563Z Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages'
2018-03-14T21:10:11.0354972Z Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages' from source 'https://api.nuget.org/v3/index.json' 'Microsoft.SharePointOnline.CSOM.16.1.7317.1200' to folder 'D:\a\1\s\packages' 
Run Code Online (Sandbox Code Playgroud)

MsBuild 中的一些行:

018-03-14T21:10:21.2105399Z PrepareForBuild:
2018-03-14T21:10:21.2105793Z   Creating directory "bin\Release\".
2018-03-14T21:10:21.2424947Z   Creating directory "obj\Release\".
2018-03-14T21:10:30.3569560Z ResolveAssemblyReferences:
2018-03-14T21:10:30.3570425Z   Primary reference "AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL".
2018-03-14T21:10:30.3670272Z ##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Run Code Online (Sandbox Code Playgroud)

我的解决方案/包结构是:

....\mysolution\myproject\myproject.csproj
....\mysolution\myproject\packages.config
Run Code Online (Sandbox Code Playgroud)

当前配置: 努吉特 在此输入图像描述 那么我该如何更改 Nuget 和/或 msbuild-behavior 才能使其正常工作呢?

(更新) :为了解决这个问题:我的每个包都有这个问题。它们都在packages.config中,每一个都是从Nuget下载的,但每一个也没有从MsBuild中找到

(更新2)当前生成的命令如下:NUGET:

D:\a\_tool\NuGet\4.4.1\x64\nuget.exe restore D:\a\1\s\AweCsomeO365\packages.config -PackagesDirectory D:\a\1\a\packages -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_22.config
Run Code Online (Sandbox Code Playgroud)

微软构建:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "D:\a\1\s\AweCsomeO365\AweCsomeO365.csproj" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_(GUID)\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=(GUID)|SolutionDir=D:\a\1\s\AweCsomeO365"*ForwardingLogger,"D:\a\_tasks\VSBuild_(GUID)\1.126.0\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\a\packages /p:platform="anyCPU" /p:configuration="Release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="VSTS_(GUID)_build_4_22
Run Code Online (Sandbox Code Playgroud)

我更换了 GUID;tempNuGetConfig 似乎是由 VSTS 动态生成的

仍然。即使日志表明 nuget 存储了包

Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\a\packages'
Run Code Online (Sandbox Code Playgroud)

MsBuild 似乎没有在那里找到它们:

 For SearchPath "D:\a\1\a\packages".
2018-03-16T13:57:42.4625155Z           Considered "D:\a\1\a\packages\AngleSharp.winmd", but it didn't exist.
2018-03-16T13:57:42.4625456Z           Considered "D:\a\1\a\packages\AngleSharp.dll", but it didn't exist.
2018-03-16T13:57:42.4625730Z           Considered "D:\a\1\a\packages\AngleSharp.exe", but it didn't exist.
Run Code Online (Sandbox Code Playgroud)

VSTS 配置值:

构建女士:/p:ReferencePath=$(Build.StagingDirectory)\packages

Nuget-Destiantion目录:$(Build.StagingDirectory)\packages

(update3):我没有解决方案文件,但该存储库中只有一个 csproj 文件

Ole*_*ers 6

问题是,项目内部有一个包的提示路径,指向不在 GIT 存储库内(也不应该)的位置:

  <Reference Include="AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
      <HintPath>..\..\AweCsome365Test\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
    </Reference>
Run Code Online (Sandbox Code Playgroud)

我最初的方法是为 NuGet 定义一个目标目录,为 MSBuild 定义一个源目录,以使用两者都能理解的包的另一个位置。

但问题(据我所知)是,NuGet 总是创建子文件夹结构"./packages/{PackagesName}/lib/net45/{file}",而 MSBuild 在设置为源路径时不会递归地查找"./packages"

以上只是对未来遇到同样问题的人的解释

所以我的解决方案是模仿 nuget 的本地行为并更改输出目录以匹配存储库中的 HintPath (即使没有“AweCsome365Test”)目录: Nuget目标目录设置

(我将保留这个问题,因为这个解决方案闻起来很可疑。如果有人有更好的解决方案,允许在不使用 HintPath 的情况下链接 nuget 和 msbuild,我很乐意在上面花费我的赏金)