tfs - 在 TFS (VS Online VS2015) 下在 CI 队列上构建时未恢复包

标签 tfs msbuild continuous-integration azure-devops

我问过 question about build errors并继续由我绝望的自己进一步调查这个问题。

我猜测问题在于获取但未正确放置的包。翻阅枯燥乏味的日志给了我这个。

2016-01-15T21:50:40.8680146Z
The target "BeforeGenerateProjectPriFile" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets (186,61)" does not exist in the project, and will be ignored.



此后不久,我可以看到某些东西横向移动的第一个迹象。

2016-01-15T21:50:43.9631666Z ##[warning]
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2016-01-15T21:50:43.9631666Z 2>
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, 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:\a\1\s\MyStuff\MyStuff.csproj]



然后它继续大量考虑不存在的东西。

2016-01-15T21:50:43.9661661Z
Considered "..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll", but it didn't exist.
2016-01-15T21:50:43.9671655Z
For SearchPath "{TargetFrameworkDirectory}". 2016-01-15T21:50:43.9681655Z
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.winmd", but it didn't exist.
...



我不熟悉 TFS 上的 CI 或 VS Online,所以它几乎没有告诉我在哪里解决问题。我在谷歌上搜索了半死,并在整个门户网站上测试了无数不同的设置。没运气。我可能会导致其他错误(当我知道我输入了错误的内容时等),但无论如何,我都会转向这个错误。

任何提示将不胜感激。

最佳答案

从 VS2015 版本开始,不需要 NuGet 文件夹,这与我看到的指南相反。事实上,唯一需要的文件是包的配置文件。有一种常见但非常具有欺骗性的解决方法来检查包及其可执行文件,但这可能会在 future 产生很多问题。我不建议这样做,因为它隐藏了问题,而不是解决问题。

首先,验证您的构建是否确实恢复了包。我注意到在错误日志中,看起来好像是这样,但这是一个陷阱。这是一种恢复的尝试,而不是真正的成功。如果您遇到这样的警告(对于 nUnit、WebGrease、NewtonSoft 或 NuGet 控制下的任何其他包也是如此):

Warning MSB3245: Could not resolve this reference. Could not locate the assembly "EntityFramework". Check to make sure the assembly exists on disk.



首先验证日志是否包含以下段落:

PrepareForBuild:
Creating directory "obj\Debug\".
...
RestorePackages:
"C:\a\src\src.nuget\nuget.exe" install "C:\a\src\src\xxxx.Entities\packages.config"
-source -RequireConsent -o "C:\a\src\src\packages"
...
Successfully installed "EntityFramework 6.3.1". ResolveAssemblyReferences:
Primary reference "EntityFramework".



请记住,当您查看日志文件时,请搜索部分字符串,因为目录、版本、包名称等可能略有不同。如果您找不到它,则很有可能在构建服务器上没有恢复这些包。本地编译证明环境之间存在差异,很可能是packages.config文件不可用。这是一个棘手的错误,因为失败的日志不会告诉您它丢失了。事实上,我的日志中根本没有提到它。
  • 首先,我创建了一个全新的项目 Auto 并 checkin 。构建成功。
  • 然后,我添加了 Entity Framework,构建失败,并出现与您相同的警告。
  • 最后,我检查了packages.config 文件。构建成功。

  • enter image description here

    出现此问题的原因是初始 checkin 选择了许多要忽略的文件。主要是 bin、obj 等,但也包括 packages.config。它需要特别选择为不被忽略。如果有人 checkin 所有文件(在我看来不是很明智),他也会获得所需的文件,因此看起来他们做得对。请注意,您应该先将文件添加到版本控制中。这样,它在每次更改时都会被检入。否则,如果您在本地添加新软件包或更新现有软件包,问题将再次出现。

    如果您收到警告但软件包已恢复(日志中列出了这些行),请尝试在本地更新软件包或重新安装它。最后,您可以通过运行 Update-Package -Reinstall 从包管理器控制台刷新安装。 .
  • 与旧版本的包管理器类似的问题 here .
  • 关于需要 checkin 的文件的错误建议(自 VS 2015 起)here .
  • 过时的文件布局描述(对 VS 2013 及更早版本有效)here .
  • 有关如何构建 NuGet 文件结构的更多信息 here .
  • 关于这个问题的非常好的博客(奇怪的是它没有出现在谷歌的顶部)here .
  • 关于tfs - 在 TFS (VS Online VS2015) 下在 CI 队列上构建时未恢复包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34820770/

    相关文章:

    TFS Visual Studio 测试任务未填充 TRX 文件

    .net - 'GenerateBindingRedirectsOutputType' 选项有什么作用?

    Github 工作流操作和 EC2 : Error Loading Key Invalid Format

    linux - 学习 CI/CD - 需要演示应用程序

    automation - nuget 是否适合日常开发工作流程?

    visual-studio-2013 - 如何获得代码审查任务的所有权?

    tfs - 使用 VSIX 和 PKGDEF 在 TFS2010 上部署自定义策略

    TFS 管理控制台缺少构建配置节点

    sql-server - VS 2015 MSBuild 部署数据库项目错误

    MSBuild:为子构建指定平台时出现问题