I just downloaded the current revision from TFS. However even after restoring the nuget packages it isn't building. Something about missing Nugets.
Any assistance would be appreciated. Is this because we are using different Visual studio versions?
I'm opening the csproj file to build my sln file.
Try following below steps to fix that:
Close Visual Studio
Manually delete the local “packages” folder
Reopen the solution, and rebuild. (Nuget should restore the
packages)
Source Link: Missing Nuget Packages on TFS Build Server
Or run the update-package -reinstall command in NuGet Package Management Console to reinstall all referenced packages.
If that still not work, just try this:
Right click on .csproj and open it in notepad or any editor and delete the following
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Then build your solution and it should work.
And this thread for your reference: NuGet not restoring packages on build
Related
Visual Studio 2015 Enterprise
Nuget.exe 3.4.4.1321
Project: Windows Forms Class Library
OK I have project.json file setup in my solution and this builds fine. I have NO IDEA how msbuild finds the packages project.json asks for, but that's fine.
I check the files into TFS 2012 (ya I know, our company won't upgrade yet)
TFS fails to build. Says "type cannot be found..."
How on earth do you DEBUG these sorts of issues when you have NO IDEA where MSBuild even LOOKS for packages?
I can GUESS where MS Build may be looking, but how can I confirm this?
csproj hintpaths had their drawbacks, but at least you KNEW where msbuild would look for your package
with Project.Json I have no idea where msbuild is looking!
The package IS there on the build server, right where I expect it to be. How to tell msbuild.exe where to look for packages?
According to your error message, it seems that something wrong with the reference using. For trouble shooting your issue, please try the following.
Please use Package.config for your project to install packages in TFS build. Check if it works to make sure your assemblies and packages are fine.
If Package.config doesn't work. Please provide the detail steps for me to reproduce your issue.
If package.config works but project.json doesn't works. Look at this document: Converting a csproj from package.config to project.json
To debug a build: https://msdn.microsoft.com/en-us/library/jj635150.aspx?f=255&MSPPError=-2147217396
Note: To always use the latest version of the package available, you could add the following to Nuget.config file. So it will get the latest version when you use packages.config. The Nuget.config file is at: C:\Users\UserName\AppData\Roaming\NuGet
(nuget spec dependencies, get latest version?)
<configuration>
<config>
<add key="dependencyversion" value="Highest" />
</config>
</configuration>
project.lock.json will report the resolution path for nuget packages.
This will appear at the VERY BOTTOM of the project.lock.json file:
sample:
"packageFolders": {
"c:\\nuget_packages": {}
Adding this key in nuget.config tells nuget where to restore packages:
<config>
<add key="globalPackagesFolder" value="c:\nuget_packages" />
</config>
This ONLY works for nuget 3+ with project.json file, not with packages.config
I used the GitHub extension of Visual Studio 2015 to clone my project onto a new computer. I try to restore packages and I get an error that says:
NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'
I've looked into some other questions about similar issues, but none of those solutions have worked for me yet.
I tried deleting the packages folder, opening up up Visual Studios again and then rebuilding. That didn't resolve it.
I tried manually installing Microsoft.Net.Compilers in Package Manager Console.
PM> Install-Package Microsoft.Net.Compilers
I tried removing this bit of code from the csproj file (this seemed to work for some):
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
I tried reinstalling all packages with
Update-Package –reinstall
So far I haven't had any luck resolving the issue. Any help is appreciated.
EDIT:
I tried the response below and received this error:
Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.
At line:1 char:16
+ Install-Package <<<< -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
+ CategoryInfo : InvalidOperation: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
It also prompted me to restore packages. When I hit restore, I got the same error as usual.
Based on your error message looks like you are looking for a version that no longer exists and cannot tell which Package source you have selected. I feel like you are looking for version 2.0.0 which is not available in nuget.org repository. The latest one is 2.0.0-rc and it is pre release candidate.
Please try this command if you want to get the latest version
Install-Package -Id Microsoft.Net.Compilers -Version 2.0.0-rc -Source nuget.org
If you want the latest stable version (1.3.2), try this command
Install-Package -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
UPDATE
If the package still cannot be installed, then that package may be out of sync between packages.config, packages/ folder and .csproj file
Please follow these steps to perform manual cleanup
Close visual studio.
Open .csproj in a notepad or some text editor and manually remove all entries related to Microsoft.Net.Compilers
Open packages.config in a notepad or some text editor and and remove entry for the Microsoft.Net.Compilers package
Go to packages/ folder in windows explorer and delete the Microsoft.Net.Compilers folder
Now start the visual studio and open the solution.
Now try to install the package again.
Some of the entries that you may have to remove from .csproj as part of step 2 are these
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
<NuGetPackageImportStamp></NuGetPackageImportStamp>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props'))" />
</Target>
I had a similar error after a clean install of Visual Studio 2017 and had to do the following to get it to automatically restore missing NuGet packages successfully. In VS, go to "Tools > Options > NuGet Package Manager > Package Sources", and ensure the appropriate package sources show and are checked.
See below. The addition of the nuget.org package source at the top tells VS to go online to download the packages from NuGet if it can’t find the appropriate versions on the local machine.
I also had similar problem on VS 2019, this one worked for me, just go to Tools > Options > NuGet Package Manager > General and Clear all NuGet Cache.
See the image below
This might be a bit late but it will still help somebody. When you try to check in your code and you get this kind of an error, it means that you had the package installed and uninstalled it again, so you just need to locate the package under included changes, in my example i an using TFS, and exclude or undo. this will solve the issue.
I moved my project in relation to where the NuGet packages had originally been stored in my project, and I eventually discovered that this causes a problem with that .csproj file that might not be immediately obvious.
Following the move and after doing a NuGet Package Restore, a second entry had been added to the EnsureNuGetPackageBuildImports target of my .csproj file reflecting the relative path of the new location.
The target now looked like the following:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
Notice the two entries, with different paths to where the packages were located. This meant one of them (the first one, which was from before I moved the project) would always fail.
The fix was simple enough. I just removed the first Error node from the Target.
I also found that there was a similar problem in the initial Import nodes of the root Project node.
I had the following:
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />
Again, the fix was just to remove the erroneous Import node.
This kind of error can happen also using an old version of nuget.exe. For example, if you download the agent.zip of TFS 2015, inside it has version 3.2.1:
\Agent\Worker\Tools\nuget.exe
That version can give the error "Unable to find version '3.7.1' of package 'NUnit'." with a solution created with VS 2015. (NUnit3TestAdapter.3.9.0 doesn't give error, though)
Updating nuget.exe to 5.2 solves the problem.
I know why, it's in the C: \ Program Files (x86) \ Microsoft SDKs \ NuGetPackages folder. There are packages that you have installed before.
This was my error: "The project references NuGet packages that are missing on this computer. Use NuGet Package Restore to download them."
And this was my solution: I had to make sure that my Package Sources were checked in the Manage Nuget Packages window.
go to tools in navbar and tools and features and chek your freamworks are downloaded or not
enter image description here
I have a mvc 5 web project with a number of NuGet packages installed (like email, log, pagedlist etc).
In a new similar project I would like to install the same NuGet packages. How can I in the old project list all installed NuGet packages?
You can find a packages.config file in the old project's root directory.
You can copy it to the new project.
If you go to Tools -> NuGet Packet Manager -> Packet manager settings and check Allow NuGet to download missing packages and the other check box that states Automatically check for missing packages during build in Visual Studio it will download it for you next time you build.
If you want to list all installed nuget packages for the project take a look at this one.
http://blogs.msdn.com/b/david_kidder/archive/2014/08/19/micro-blog-how-to-list-installed-nuget-packages-from-package-manager-console-and-be-able-to-read-them.aspx
You might also want to enable nuget package restore to restore the packages when rebuilding your project/s.
Here's another link for you - http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
In the root folder of your original project find a packages.config file. Copy its contents to your new project, same file name.
Go to Visual Studio > Tools > Package Manager Settings > General
Enable "Allow Nuget to download..." and "Automatically check for missing..."
Now build your new project
Most of the answers here are partially correct.
The first part is true. The packages.config file lists all packages that are used by the project.
However, all the answers about using Package Restore are incorrect. Package Restore will download any missing packages, however it is NOT the same as installing a package into a project. It will not add references, run any install.ps1 scripts, or add files, modify .config, etc. Package Restore simply downloads missing packages. It is assumed that the packages were already installed to the project.
In order for the packages to be correctly installed in your new project, open the Package Manager console, then type:
Update-Package -ProjectName MyProjectName -Reinstall
This will force NuGet to run through the install process and correctly install the package into your project.
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.
I just went through a dll hell. Turns out that TFS has been synchronizing packages, and I ended up with two versions of Microsoft.Web.Optimization and its dependencies at once. NuGet was convinced that I have the newest versions installed, and even reinstallation changed nothing. But at the same time, my projects wouldn't build or, if they'd build, they wouldn't start, complaining that they can't find the library version given in the manifest.
I managed to solve it by uninstalling the packages from NuGet console, physically removing their folders from the hard disc, and then doing a fresh build (which re-installed the missing latest versions). But the package folders I deleted manually are still sitting around in the Source Control Explorer. And I can't delete them, the Delete button is greyed out when I select one of them. I am afraid that they will come again when I get newest version next time.
How do I prevent it? I would like to remove them from the solution completely. In the worst case, it would be OK to ignore them, but as they are on a level above the projects, I can't enter them into a project's .tfignore file, and Visual Studio didn't let me add a .tfignore file to the solution itself.
Would it be an option to not checking in the Packages folder to TFS? NuGet now supports automatic package restore, which automatically restores packages on build.
Here is doc for migrating to this new model: http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore.
And this may save you a lot of hassle with checked-in packages folder.
Arguably best answered in this post:
https://stackoverflow.com/a/40409464/1690217
The NuGet documentation provides instructions on how to accomplish this and I just followed them successfully for Visual Studio 2015 against VSTS (Azure-hosted TFS). Everything is fully updated as of Nov 2016. This also still works for Visual Studio 2017 RTM (March 2017).
I added the following files as explained above:
.tfignore
\packages
!\packages\repositories.config
.nuget\nugget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
I had to delete the packages folder and checkin the delete, then package restore will kickin and rebuild the folder but VS will no longer automatically add it to source control.