c# - MsBuild 在 Visual Studio Online 上找不到还原的 NuGet 包

标签 c# msbuild nuget azure-devops

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

它有以下步骤:

1: Git Restore - Works

2: NuGet Restore - Works

3: Build - Does NOT work



在查看日志时,我的第一个猜测是 MsBuild 不是在寻找 NuGet 存储它们的包。
NuGet 还原中的一些行:
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 的一些行:
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.

我的解决方案/包结构是:
....\mysolution\myproject\myproject.csproj
....\mysolution\myproject\packages.config

当前配置:
NUGET
enter image description here
那么如何更改 Nuget 和/或 msbuild-behavior 以使其工作?

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

(Update2) 目前生成的命令如下:
纽 git :
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 动态生成的

仍然。即使日志指出 nuget 存储包
Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\a\packages'

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.

VSTS-配置值:

MsBuild:/p:ReferencePath=$(Build.StagingDirectory)\packages
Nuget-DestiantionDirectory:$(Build.StagingDirectory)\packages
(更新 3):我有 没有 解决方案文件,但该存储库中只有一个 csproj 文件

最佳答案

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

  <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 定义一个源目录,以将另一个位置用于两个都理解的包。

但问题(据我所知)是,NuGet 总是创建一个子文件夹结构 "./packages/{PackagesName}/lib/net45/{file}"并且 MSBuild 在设置 "./packages" 时看起来不是递归的作为源路径。

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

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

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

关于c# - MsBuild 在 Visual Studio Online 上找不到还原的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49287852/

相关文章:

c# - C# 中的频率分析器

c# - 如何将 "bin"和 "obj"目录重定向到不同的位置?

visual-studio - 每个从事同一VS项目的开发人员都需要添加Nuget软件包吗?

c# - 为 Nuget 包在 teamcity 中构建失败

c# - Linq FindWhere 子句和 bool 过滤器?

c# - ASP.NET Identity 检查自定义 UserValidator 实现中是否存在电子邮件

visual-studio - 动态设置Web应用项目的IISUrl

TFS 和 msbuild 版本号与最后一个变更集

package - 如何发布nuget预发布版本包

c# - 使用静态类作为另一个类的输入参数