I created a brand new C# Web Application from the templates and immediately updated all its NuGet packages.
During the update process it required a restart, and afterwards, it keeps on showing this message:
One or more packages could not be completely uninstalled:
Newtonsoft.Json.6.0.4. Restart Visual Studio to finish uninstall.
But the same message persists after restarting Visual Studio.
The packages.config file contains the following line: <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" />.
After trying to update the package manually in the Package Manager Console, I've got an error saying that an existing file is blocking the install. After deleting the appropriate folder from the solution packages and error is gone, and I could update the package right from the Package Manager UI.
Here's my console print:
PM> update-package -reinstall Newtonsoft.Json
Removing 'Newtonsoft.Json 6.0.4' from MyProject.
Successfully removed 'Newtonsoft.Json 6.0.4' from MyProject.
Uninstalling 'Newtonsoft.Json 6.0.4'.
update-package : TF400024: The change on D:\Users\Shimmy\Documents\Visual Studio
2012\Projects\MyProject\MyProject\packages\Newtonsoft.Json.6.0.4\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll cannot be undone because a file already
exists at D:\Users\Shimmy\Documents\Visual Studio
2012\Projects\MyProject\MyProject\packages\Newtonsoft.Json.6.0.4\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll. The file must be deleted from disk for
the undo to succeed.
At line:1 char:1
+ update-package -reinstall Newtonsoft.Json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Update-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.UpdatePackageCommand
'Newtonsoft.Json 6.0.4' already installed.
Adding 'Newtonsoft.Json 6.0.4' to MyProject.
Successfully added 'Newtonsoft.Json 6.0.4' to MyProject.
One or more packages could not be completely uninstalled: Newtonsoft.Json.6.0.4. Restart Visual Studio to finish uninstall.
Related
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 am trying to install serilog and I'm getting error
PM> Install-Package Serilog
Install-Package : 'Serilog' already has a
dependency defined for 'Microsoft.CSharp'. At line:1 char:1
+ Install-Package Serilog
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
Microsoft.CSharp is already referenced in my project
As #Tieson T. said, Update "Nuget Package Manager for Visual Studio" from Visual Studio Window > Tools > Extensions and Updates > Click Updates tab. Select Nuget plugin and update. Then restart the visual studio after installation complete. I tried (Windows 8.1 64bit & Visual Studio 2013 Ultimate) and it works.
To add to this. I had a similar issue but the problem was due to our build server being based on TFS 2012 and using an old version of MSBuild (which we can't update in the near term). Everything built and ran fine locally, but when the build server tried to run we got the same error.
The workaround I found was to go into the packages folder of the solution, find the package having the issue (in my case Serilog.2.3.0 and the associated Sink packages I had installed). Open the "lib" folder and you should see some folders associated to the various .Net frameworks. Delete the netstandard folders which correspond to the .Net Core versions.
The downside to this is you have to check in the folders you modify like this so MSBuild doesn't try to restore them.
Please do the 2 steps below, it works for me or teamcity/jenkins
If you still using the Nuget CommandLine 2.8, please try to upgrade to 3.5.
If you using the private Nuget Server, Please update the Serilog.2.3.0.nupkg with the steps below:
2.1 Update Nuget Spec File:
Remove
...
...
2.2 Remove the folder lib/netstandard1.0 and lib/netstandard1.0
2.3 Then redeploy the Serilog.2.3.0.nupkg to your private Nuget Server
I just upgrade my project from Visual Studio from 2010 to 2013 to support Cross-Origin Resource Sharing (CORS) in my WebApi.
Now when I am installing Microsoft.AspNet.WebApi.Cors package from NuGet then I am getting following error.
I am using Visual Studio 2013, Asp.Net MVC 5
PM> Install-Package Microsoft.AspNet.WebApi.Cors
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.2.3 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.3)'.
Install-Package : An item with the same key has already been added.
At line:1 char:1
+ Install-Package Microsoft.AspNet.WebApi.Cors
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], ArgumentException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I had exact the same problem with another NuGet library.
Please try this steps:
1. Updates
Proof if your installed NuGet version is on the newest version
2. Clear cache
Use the NuGet command prompt and clear the cache:
You can list the local caches with this command:
nuget locals all -list
You can clear all caches with this command:
nuget locals all -clear
3. Check cache
The NuGet Cache is simply a folder on your computer, you can proof delete the remaining files manually under %LOCALAPPDATA%\NuGet\Cache.
Or just run this in administrator CMD:
del %LOCALAPPDATA%\NuGet\Cache\*.nupkg /q
The message says the package is already installed.
try uninstall before to re-install:
Uninstall-Package Microsoft.AspNet.WebApi.Cors
If that can help someone else, I tried to follow the steps from Steffen Mangold but that's wasn't working completely.
If you have an assembly error like:
System.Web.Http, Version=5.0.0.0
after doing this command Install-Package Microsoft.AspNet.WebApi.Cors
Try that :
1 - Run this in administrator CMD
del %LOCALAPPDATA%\NuGet\Cache\*.nupkg /q
2 - Run this in the Package manager console
Install-Package Microsoft.AspNet.WebApi
That will install missing assemblies and fix the error.
Check the package source.
Go to tools, click on Nuget Package Manager and click on Package Manager settings.
Then go to Package Sources subsection under the Nuget Package Manager section.
In my case the source was initially pointing to a folder on my local machine.
So just add another package source with the following details.
Name : nuget.org
Source : https://api.nuget.org/v3/index.json
I want to install the WebOptimizaton-Package to a recently new added project of my solution using the packet-manager command
Install-Package Microsoft.AspNet.Web.Optimization -Project MyNewProject
In the console he is telling me that all dependencies were downloaded and added. After the main package is installed, it will throw an installation error:
"Microsoft.AspNet.Web.Optimization 1.1.3" was successfully installed on "MyNewProject"
Installation error. We will do a rollback now...
Then he removes the package with all dependencies and throw the following error:
Install-Package: An element with the same key was already added.
At Line 1 Char 1: + Install-Package Microsoft.AspNet.Web.Optimization -Project MyNewProject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
I already tried deleting the subfolder in the packages-folder but it's not working. It seems that NuGet will download the package and then he's wondering that it is there and will remove it. But the package isn't existing in the NuGet GUI, packages.config or the references.
I also tried to uninstall the package with and without -Force parameter. But this is not working too because then NuGet tell me that the package isn't existing.
I'm using Visual Studio 2015 on Windows 8.1.
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.