MsBuild在Visual Studio Online上找不到还原的NuGet软件包 [英] MsBuild does not find restored NuGet-Packages on Visual Studio Online

查看:105
本文介绍了MsBuild在Visual Studio Online上找不到还原的NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to build a solution stored in an external GIT-Repository on Visual Studio Online.

它具有以下步骤:

1:Git Restore-正常运行

1: Git Restore - Works

2:NuGet Restore-有效

2: NuGet Restore - Works

3:构建-不起作用

查看日志时,我的第一个猜测是MsBuild不在寻找NuGet存储它们的软件包. NuGet Restore的几行内容:

My first guess when looking at the logs is that MsBuild is not looking for the Packages where NuGet had stored them. Some Lines from 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' 

来自MsBuild的一些行:

Some lines from 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.

我的解决方案/软件包结构为:

My solution/packages structure is:

....\mysolution\myproject\myproject.csproj
....\mysolution\myproject\packages.config

当前配置: 那么,如何更改Nuget和/或msbuild-behavior才能使其正常工作?

Current Config: So how can I change the Nuget and/or msbuild-behavior to make this work?

(更新):要清除此问题:每个软件包都存在此问题.它们全都在packages.config中,每个都从Nuget下载,但也没有从MsBuild中找到

(Update): To clear this up: I have this problem with every package. They all are in the packages.config, each one is downloaded from Nuget, but each one also isn't found from MsBuild

(Update2)当前生成的命令如下: NUGET:

(Update2) The Commands generated are currently the following: 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

MSBUILD:

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

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

I replaced the GUIDs; tempNuGetConfig is something that seems to be generated by VSTS dynamically

仍然.即使日志指出nuget存储了程序包

Still. even if the log states that nuget stores the packages

Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\a\packages'

MsBuild似乎找不到它们:

MsBuild does not seem to find them there:

 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.

VSTS配置值:

MsBuild:/p:ReferencePath=$(Build.StagingDirectory)\packages

Nuget-DestiantionDirectory:$(Build.StagingDirectory)\packages

Nuget-DestiantionDirectory: $(Build.StagingDirectory)\packages

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

(update3): I have no solution file, but only a csproj-file in that repository

推荐答案

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

The issue was that inside the project there was a hintpath for the packages directing to a location that was not within the GIT-Repository (and shouldn't):

  <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>

我最初的方法是为NuGet定义一个目标目录,为MSBuild定义一个源目录,以便在两个都可以理解的程序包中使用另一个位置.

My original approach was to define a target directory to NuGet and a Source Directory for MSBuild to use another location to the packages that both understand.

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

The issue though (as far as I understand) is, that NuGet always creates a subfolder-structure "./packages/{PackagesName}/lib/net45/{file}" and MSBuild does not look recursivly when setting "./packages" as source path.

以上只是对将来遇到同样问题的家伙的解释

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

So my solution was to mimic the local behavior for nuget and changing the output directory to match the HintPath (even if there is no "AweCsome365Test")-directory in the repository:

(我将打开这个问题,因为此解决方案听起来有点腥.如果有人有更好的解决方案,可以在不使用HintPath的情况下链接nuget和msbuild,我很乐意花我的钱在上面)

这篇关于MsBuild在Visual Studio Online上找不到还原的NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆