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 -
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 (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 (26): The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)
I am using EntityFramework 6.1.1. NuGet package for the project and Package Restore is enabled (in NuGet.targets file) -
<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.
I am using 2 packages for this project -
<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.
Finally I made it work. It took a while. At this point, 2 different options available :
Keep the NuGet.targets file and refer that NuGet.targets file from all the project (Didnâ€™t work for me)
Explicitly call the NuGet.Exe package restore before the build
The option 1 didnâ€™t work for me, thatâ€™s why to go ahead with the 2nd option, I had to do:
Delete the NuGet.targets file from the .nuget folder (do not checkin that file)
Delete and do not check in the packages file
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
Go to VS 2013 â€“ Tools > Extensions and Update > VS Gallery â€“ make sure that you have the latest NuGet
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.
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.
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
Check in the build.proj, NuGet.exe all in the root folder along with the solution file
Now, things are going smooth for me with the TFS online 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.