Nuget Visual Studio 2022 control dependency version - visual-studio

Whenever I try to install any package from Nuget through Visual Studio 2022 - be it the GUI or package manager console, I can't seem to find a way to get the highest dependency version.
For example: if I add latest version 1.0.152 protobuf-net.Grpc to my project it has a dependency on Grpc.Core.Api >= 2.36.1. The current version for Grpc.Core.Api is 2.46.3...
In the GUI under options I have no option to control dependency version what so ever it seems like the Install-Package cmdlet doesn't obey -DependencyVersion Highest:
Install-Package protobuf-net.Grpc -DependencyVersion Highest
Installing NuGet package protobuf-net.Grpc 1.0.152.
Committing restore...
Successfully installed 'Grpc.Core.Api 2.36.1'
Successfully installed 'Microsoft.NETCore.Platforms 2.1.0'
Successfully installed 'protobuf-net 2.4.6'
Successfully installed 'protobuf-net.Grpc 1.0.152'
Successfully installed 'System.Memory 4.5.3'
Successfully installed 'System.Private.ServiceModel 4.5.3'
Successfully installed 'System.Reflection.DispatchProxy 4.5.0'
Successfully installed 'System.Security.Principal.Windows 4.5.0'
Successfully installed 'System.ServiceModel.Primitives 4.5.3'
How can I force Nuget to install the highest dependencies version?

According to your description here are some suggestion:
First check your project type “-DependencyVersion Highest” only used in packages.config format.
You can see the project type support about two package management formats: Projects.config and PackageReference.
Someone posted a similar issue on github, see the issue here. Hope this help you.
If you want to use “Grpc.Core.Api 2.46.3 “, you can try to delete the bin and obj folder and then go to Tools>Options>Nuget Package Manager>General>Clear All Nuget Caches.
Then you can install Grpc.Core.Api 2.46.3 package before install protobuf-net.Grpc 1.0.152

Related

Is there a setting in proget nuget server to make it consider version 1.0.1.0 = 1.0.1

Is there any setting in proget nuget server which can make it treat version 1.0.1.0 = 1.0.1
So basically when any of the version's package is tried to restore then it will return 1.0.1.0 version's package.
Because I have a package with version 1.0.1.0 in my project but whenever I try to restore it, it always try to look for 1.0.1, skipping the last zero and so it throws error that the package does not exist. Because proget server has 1.0.1.0 version.
It works when I use my local folder as nuget source in visual studio. Because from local folder it restores the version 1.0.1.0 because it seems for local folder somehow it treats 1.0.1.0 = 1.0.1
Any idea?
Is there a setting in proget nuget server to make it consider version
1.0.1.0 = 1.0.1
ProGet nuget server does not have an option to make it consider version 1.0.1.0 = 1.0.1.
I think the package is packed by on old nuget cli <=v 3.3.0. And since nuget v3.4.4, nuget will remove the fourth node if it is zero automatically.
And the latest VS and nuget will ignore the fourth zero node of the package version if you install your package version 1.0.1.0. See this official Microsoft document.
So if you install it from local source or nuget.org, on these sources, it will remove the last zero from the source path.
However, on ProGet server(third party nuget server and not Microsoft), it still retain the fourth zero node of the package version. So when you install this package on VS, it shows the version 1.0.1.0 in packages.config file and when you restore it, it will find version 1.0.1 since the new rule of nuget.
And actually, when you enable the ProGet package source, it can still find version 1.0.1.0. In my side, although it still shows version 1.0.1.0 and vs have to catches 1.0.1 during restore process, the project will still works well.
So I suspect there is some deviation between you and my environment.
This is my test process:
For an example
This is my package:
In VS, it shows version 1.0.1.
But, on ProGet nuget server, it shows version 1.0.1.0.
Suggestion
First, try to clean nuget caches first or delete all files under C:\Users\xxx\.nuget\packages.
Then enable the proget nuget server package source and remember to check it:
============================================
If you still face the error, you could follow these below:
As a suggestion, you could upload your package on nuget.org, and it will automatically cull your package to version 1.0.1 and then it will synchronize to the ProGet nuget server.
When I upload the version 1.0.1.0 on nuget.org, it shows version 1.0.1:

The specified task executable location ......csc.exe is invalid error

I have a project on TFS that is working on everyone else's machine, except mine. When building I get the error that can be seen in the image. "The specified task executable location csc.exe is invalid." currently trying to repair VS 2017 now.
Based on the message, seems the csc.exe is damaged.
Just try below things to narrow down the issue:
Navigate to the Microsoft.Net.Compilers package location, delete
the package folder, then rebuild. Generally the package will be
restored automatically during the build.
YOUR_PROJECT_DIR\packages\Microsoft.Net.Compilers.2.6.1
Uninstall and Re-install the Microsoft.Net.Compilers package:
Open Visual Studio
Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution
Go to Installed tab and find Microsoft.Net.Compilers package
Uninstall the package from your project
Try to build your project now. (Thus it will use the default compiler which lives in the .NET framework folder:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe)
If you really need the Microsoft.Net.Compilers package then go ahead and find it in the Browse tab and install the latest stable
version.
Build the project and if everything works, make sure you commit changes to your code repository.
You can also try to run below command to uninstall and reinstall the
Nuget packages from the Package Manager Console: See Microsoft.Net.Compilers
Uninstall-Package Microsoft.Net.Compilers -Version 2.6.1
Install-Package Microsoft.Net.Compilers -Version 2.6.1
Remove Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers Nuget Packages.
Installing MSBuild 2015 will resolve the issue.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=48159
I hit this question even though my error was "The specified task executable csc.exe could not be run" when pulling down existing web project with unit tests and trying to run it locally for the first time.
I was able to resolve this by building each project individually in my solution.

Can't Install NuGet packages that require Newtonsoft.Json.10.0.1 in Visual Studio 2015

I've been having problem installing NuGet packages that require Newtonsoft.Json.10.0.1
I just recently installed it and when ever I try installing packages that need it, I get this error:
Severity Code Description Project File Line
Error An error occurred while retrieving package metadata for 'Newtonsoft.Json.10.0.1' from source 'C:\Users\Sharon Umute\documents\visual studio 2015\Projects\sermon\packages'. 0
I tried upgrading to Newtonsoft.Json.10.0.2 and adding the path to Environment Variables but I keep getting the same error.
I've checked the path, the Newtonsoft.Json.10.0.2 folder contains lib, tools, and Newtonsoft.Json.10.0.1.nupkg.
I'd really appreciate some help with this.
I had a similar problem when installing System.Net.Http. Simply remove the line that references Newtonsoft.Json in packages.config. It solved my problem
I had this issue when trying to upgrade my packages and resolved it by upgrading to Newtonsoft.Json version 10.0.1.
In package manager run:
Install-Package Newtonsoft.Json -Version 10.0.1
After that, all my other packages were able to update.
open packages.config, delete <package id="Newtonsoft.Json"..>, then refresh it

TFS Build 2015 failing because of incorrect NuGet version even when the required one is present in the build machine

I'm configuring a TFS 2015 build using the new scriptable system. During the build, when NuGet is retoring some packages, it fails with the following error:
The 'System.Collections 4.0.10' package requires NuGet client version
'3.0' or above, but the current NuGet version is '2.8.60318.667'.
The 'System.Diagnostics.Debug 4.0.10' package requires NuGet client
version '3.0' or above, but the current NuGet version is
'2.8.60318.667'.
The 'System.Globalization 4.0.10' package requires NuGet client
version '3.0' or above, but the current NuGet version is
'2.8.60318.667'.
The 'System.Linq 4.0.0' package requires NuGet client version '3.0' or
above, but the current NuGet version is '2.8.60318.667'.
The 'System.Resources.ResourceManager 4.0.0' package requires NuGet
client version '3.0' or above, but the current NuGet version is
'2.8.60318.667'.
The 'System.Runtime 4.0.20' package requires NuGet client version
'3.0' or above, but the current NuGet version is '2.8.60318.667'.
The 'System.Runtime.Extensions 4.0.10' package requires NuGet client
version '3.0' or above, but the current NuGet version is
'2.8.60318.667'.
The 'System.Threading 4.0.10' package requires NuGet client version
'3.0' or above, but the current NuGet version is '2.8.60318.667'.
BTW, I've installed Visual Studio 2015 in the whole build machine and I've checked that NuGet 3.1 is present in the extensions manager menu.
I guess TFS Build is using a different NuGet installation location, but I can't figure out where's looking for it and how do I update it from 2.8.x to 3.x.
There's a workaround to this problem.
By default, if you use VSBuild/MSBuild tasks, you can only choose whether to run nuget restore or not via the appropriate checkbox. But there is a separate task called NuGet Installer (it lives in the Package section). It exposes an optional field for the custom path to the NuGet.exe:
So, here is the idea:
Schedule NuGet Installer step before the appropriate VSBuild/MSBuild step
Specify correct custom path to NuGet.exe
Make sure Restore NuGet packages flag is off for the VSBuild/MSBuild step
NOTE: Your solution with replacing the physical executable directly in the build agent internals might work well up until the agent is updated (either on purpose, or somehow automatically) and overwrites NuGet.exe with newer, but still outdated version.
It was easier than I thought...
After checking the TFS build log I found the following string:
X:\TfsBuild\Agents\project\agent\worker\tools\NuGet.exe
restore
"X:\TfsBuild\Agents\project\c57207ab\path\to\solution\whatever.sln"
-NonInteractive
That is, when TFS build agent ZIP is downloaded from the TFS Web Access, it includes an outdated NuGet executable.
The worst part that there's no publicly available NuGet Command-Line 3.x executable, and I needed to use Google once I've found a post in the official NuGet blog pointing to a NuGet Command-Line 3.1 beta version executable I've replaced the one in the build agent tools location with the beta one, and the error got fixed.
The issue also affects XAML builds
If you want to work with XAML builds, you'll need to download the same NuGet Command-Line executable and copy it to C:\Program Files\Microsoft Team Foundation Server 14.0\Tools\nuget.exe and replace existing one...
I had the same problem. You need to use more recent version of nuget.exe. Version 3.5.0 soved my problem.
You can download Nuget distributions here: https://dist.nuget.org/index.html
There should be a .NuGet folder at the top of your solution. TFS will use the nuget.exe in this folder for package restore operations.
Visit this URL: https://dist.nuget.org/index.html
Download the latest nuget.exe
Delete the existing nuget.exe from the .nuget folder.
Use add/existing item to add the new nuget.exe to this folder.
Check in the change.
You should now be able to queue a build and have it restore packages successfully.

Nuget versioning issue with package restore

I am unable to install a package (using package restore) due to some kind of versioning issue with Nuget. Here are the steps I took:
build project:
error : The schema version of 'MagicalUnicorn.MvcErrorToolkit' is incompatible with version 1.6.21205.9031 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
Extension manager says version is: 2.0.30619.9119.
Ok, restart VS as administrator, extension manager uninstall nuget.
restart VS as administrator again, search for nuget and install.
Extension manager again says version is: 2.0.30619.9119.
rebuild project:
error : The schema version of 'MagicalUnicorn.MvcErrorToolkit' is incompatible with version 1.6.21205.9031 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
Ok, so restart VS as administrator, extension manager uninstall nuget again.
This time download from http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c
Run the installer, all seems ok.
Extension manager again says version is: 2.0.30619.9119.
rebuild project:
error : The schema version of 'MagicalUnicorn.MvcErrorToolkit' is incompatible with version 1.6.21205.9031 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942.
Grr! Any ideas?
It looks like problem in nuget command line tool. When you enable 'Nuget package restore' feature it adds .nuget folder to you solution with nuget.exe. And when you compile project this tool is using to download missing packages, not VS extension is used here. So try update this tool from command line:
cd .nuget
nuget.exe update -Self
Procedure screenshot:
The following worked for me in Visual Studio 2012:
Run VS 2012 as Administrator
Click Tools -- Extensions and Updates
In the left nav, Updates -- Visual Studio Gallery
Click Update on NuGet Package Manager
Install the update
Restart Visual Studio
None of the offered solutions worked for me (Visual Studio 2013, Nuget Package Manager Version 2.8.5).
I had same error but it was saying I had version 2.5.4.
I fixed it by going to Tools > Nuget Manager Console > Nuget Package Console. This open's up a command line window. At the top of the window was a prompt to download missing packages for my project.
Pressed the download button and errors went away upon build.
I was facing the same issue. I resolved it by selecting Tools on VS 2010 Menu --> Library Package Manager --> Package Manager Settings --> Check "Automatically check for updates". After that I restarted VS and was prompted for Nuget Update Installation. Once the update was installed, the Nuget package, HTTP Client in my case, got installed smoothly.
I faced to this problem and I checked all answers that were this page and at the end my problem did not solved. After lot of search on web I could update my nuget from original site
http://docs.nuget.org/docs/start-here/installing-nuget
and for example for vs2010 :
http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c
At this site select your version of VS and then update it .
Note : before installing nuget,close all Visual Studios and after install,Open your project.
Thanks
This above did not work for me, completely. There is one last step that is IMPORTANT to note. After downloading the latest nuget version, you may notice that the same error prints in the output window. The reason is due to the .nuget folder containing a NuGet.exe which specifies a version number.
The solution (for me and perhaps to those of your that did not resolve your issue with the above directions), is to
Delete the .nuget folder from you solution.
Right click your web project and click Enable Nuget Restore.
The directions above should cause a NEW .nuget folder to be added, this time the NuGet.exe should be the newest version of nuget that you downloaded.

Resources