简体   繁体   English

TFS在线构建失败 - NuGet包还原无法正常工作

[英]TFS Online Build Fails - NuGet package Restore Not working

I would love to get your help to resolve this issue. 我很乐意帮助解决这个问题。 The code compiles in local box but TFS build fails for a project saying - 代码在本地框中编译,但TFS构建失败,因为项目说 -

Entity\\DbModel.Context.cs (16): The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) Entity \\ DbModel.Context.cs(16):名称空间'System.Data'中不存在类型或命名空间名称'Entity'(您是否缺少程序集引用?)

Entity\\DbModel.Context.cs (19): The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) Entity \\ DbModel.Context.cs(19):找不到类型或命名空间名称'DbContext'(您是否缺少using指令或程序集引用?)

Entity\\DbModel.Context.cs (26): The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?) Entity \\ DbModel.Context.cs(26):找不到类型或命名空间名称'DbModelBuilder'(您是否缺少using指令或程序集引用?)

I am using EntityFramework 6.1.1. 我正在使用EntityFramework 6.1.1。 NuGet package for the project and Package Restore is enabled (in NuGet.targets file) - 启用项目和包恢复的NuGet包(在NuGet.targets文件中) -

<RestorePackages Condition="  '$(RestorePackages)' == '' ">true</RestorePackages>

I think that the package download for the EntityFramework is also failing in TFS even though the other NuGet packages for the same project are getting downloaded before the build the starts in TFS. 我认为EntityFramework的包下载在TFS中也失败了,即使在TFS中构建启动之前,同一个项目的其他NuGet包也已下载。

I am using 2 packages for this project - 我正在为这个项目使用2个包 -

<packages>
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net45" />
</packages>

Build Log file - 构建日志文件 -

RestorePackages:
  "C:\a\src\.nuget\NuGet.exe" install "C:\a\src\<project name>\packages.config" -source ""  -NonInteractive -RequireConsent -solutionDir "C:\a\src\ "
  Restoring NuGet packages...
  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages'.
  Installing 'Newtonsoft.Json 6.0.6'.
  Successfully installed 'Newtonsoft.Json 6.0.6'.
  All packages listed in packages.config are already installed.

But after Newtonsoft.Json, it didn't even download the EntityFramework Dlls. 但是在Newtonsoft.Json之后,它甚至没有下载EntityFramework Dlls。

Finally I made it work. 最后我做到了。 It took a while. 花了一段时间。 At this point, 2 different options available : 此时,有两种不同的选择:

  1. Keep the NuGet.targets file and refer that NuGet.targets file from all the project (Didn't work for me) 保留NuGet.targets文件并从所有项目中引用该NuGet.targets文件(对我来说不起作用)

  2. Explicitly call the NuGet.Exe package restore before the build 在构建之前显式调用NuGet.Exe包还原

The option 1 didn't work for me, that's why to go ahead with the 2nd option, I had to do: 选项1对我不起作用,这就是为什么继续第二个选项,我必须这样做:

  1. Delete the NuGet.targets file from the .nuget folder (do not checkin that file) 从.nuget文件夹中删除NuGet.targets文件(不要签入该文件)

  2. Delete and do not check in the packages file 删除并不签入包文件

  3. Open all the projects file in notepad and remove the reference of NuGet.targets file as mentioned in http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore 打开记事本中的所有项目文件并删除NuGet.targets文件的引用,如http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore中所述

  4. Go to VS 2013 – Tools > Extensions and Update > VS Gallery – make sure that you have the latest NuGet 转到VS 2013 - 工具>扩展和更新> VS库 - 确保您拥有最新的NuGet

  5. At this point, your project is ready to download Nuget packages right before any build, to test that delete the packages folder and start build, it should download all NuGet packages. 此时,您的项目已准备好在任何构建之前下载Nuget软件包,以测试删除packages文件夹并开始构建,它应该下载所有NuGet软件包。

  6. Now, for TFS Continuous build, instead of pointing the solution file directly in the build template, use a custom XML build.proj file as mentioned in the http://blogs.msdn.com/b/dotnet/archive/2013/08/27/nuget-package-restore-with-team-foundation-build.aspx . 现在,对于TFS Continuous构建,不要直接将解决方案文件指向构建模板,而是使用http://blogs.msdn.com/b/dotnet/archive/2013/08中提到的自定义XML build.proj文件。 /27/nuget-package-restore-with-team-foundation-build.aspx

  7. This XML first calls NuGet.EXE restore path\\.sln file, if the *.sln file is not mentioned it picks up any other solution file in the same directory 此XML首先调用NuGet.EXE还原路径\\ .sln文件,如果未提及* .sln文件,则会在同一目录中获取任何其他解决方案文件

  8. Check in the build.proj, NuGet.exe all in the root folder along with the solution file 检查根文件夹中的build.proj,NuGet.exe以及解决方案文件

Now, things are going smooth for me with the TFS online CI. 现在,通过TFS在线CI,事情进展顺利。 Do not right click on the Visual Studio solution to enable the NuGet package restore - it will undo all of the above since it brings back the NuGet.targets file and direct reference to the file in each proj file. 不要右键单击Visual Studio解决方案以启用NuGet包还原 - 它将撤消所有上述内容,因为它会带回NuGet.targets文件并直接引用每个proj文件中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM