How to force NuGet updates on other machines? - visual-studio

I installed a new NuGet package on my machine to get a library installed. This means I have other versions of the .NET compiler and so on. When I then push the project to my branch and others checkout and pull it, I assume their NuGet packages are different versions than mine. How do I get those to update on their machines, without doing Install NUGET_PACKAGE again, overriding everything I've done (like removing unnecessary folders)? Example:
Before:
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
After:
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.2\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.2\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
1.0.0 to 1.0.2.

This is handled by NuGet restore.
The other developers do not need to reinstall the NuGet packages into the project. All the other developers need to do is restore the packages for the projects you have modified after they have checked it out.
If they are using Visual Studio 2015 the restore will generally be done when you build the project. There is also a Restore NuGet Packages menu if you right click the solution in the Solution Explorer if you want to manually trigger the restore.

Related

Updating Nuget Package in Visual Studio

I have a problem updating the Nuget packages. I had to install my Visual Studio in a new environment and new is also Azure DevOps. Previously we had the TFS.
Meanwhile I have some packages on the Azure DevOps that I need for my Solution. In addition, packages from Nuget.org are still needed.
In my solution older versions of the Nuget packages are included. Some packages I can't update for some reasons.
Now I have a Nuget package that needs to be updated and here comes my problem. When I go to Tools --> Manage Nuget Package for Solutions... and click on Install, it brings me in the Preview Changes overview all packages that have an older version and wants to update all of them.
Where can I set it or what do I have to do, so that only the one package is updated, which I have selected? In my old environment it works normally.
Thanks.
Cheers
If you want to update one package for all the projects under the solution, you should right-click on the solution-->Manage Nuget Packages for Solution
This will update the package of all selected projects to one same version.
You could also right-click on the project-->Manage nuget packages to update the package one by one. It is definitely not as flexible as the above one .

Why doesn't Visual Studio notice changes to packages.config on build?

I'm not very familiar with Nuget, especially against VC++. I realised I needed to add Curl to my executable simply because it links a library using Curl.
So I edited the .exe's package.config:
<package id="Curl" version="7.59.0.0" targetFramework="native" />
<package id="Curl.redist" version="7.59.0.0" targetFramework="native" />
But again I am having to jump into the Nuget console in VS to update/restore things first. Why isn't this happening automatically? Is it possible to make it work that way?
Worse still, running update-package tells me there are no updates required. I have to reinstall them every time.
Why isn't this happening automatically? Is it possible to make it work
that way?
As zivkan said, it's not a valid workflow to manually edit packages.config so it's not happening automatically. And if you have to consume nuget packages in this way by manually adding and editing packages.config file, you can right-click the solution in solution explorer and click Restore Nuget Packages to restore packages first.
running update-package tells me there are no updates required
For Curl, in Nuget Gallery there's only 7.30.0.2(latest) version which depends on Curl.redist-7.30.0.2 version. I'm not sure where you can find the 7.59.0 version (It seems it has been released,see here), but it's obviously not published to nuget.org. So when you try to restore nuget packages from available nuget source in nuget console or Solution's Restore Nuget packages option mentioned above, you'll get no updates required or error like unable to find version 7.59.0 of package curl.
To resolve this issue, you can go Tools menu=>Nuget Package Manager=>Package Manager Settings=>Package Sources to configure the source where to find the 7.59.0 version of Curl. Then you can use the Restore nuget packages option to restore them easily for all projects in the solution. Or you can just trying changing the version 7.59.0.0 to the 7.30.0.2 which is exactly available in nuget.org.

How to fix all Nuget references in a .net core solution quickly?

I am finding it a common issue where when I download a .NET repo from Github, the solution has missing references. See an example below. When using Nuget Package Manager, it says the packages are installed already. The packages folder is missing.
I tried using 'Update-Package -reinstall' and got a bunch of lines with 'No package updates are available from the current package source for project 'project name'.... That's probably due to the missing package files.
I can fix each reference manually but it's a time consuming process. Is there a way to force fix all these references in all the projects in one swoop using a command or a tool that 'cleverly' knows what to do? I am using Visual Studio 2019 16.3 preview 1
In VS2019, those .net core projects or .net standard projects use PackageReference instead of packages.config format to manage nuget packages. And in this way, the content in xx.csproj looks similar to this:
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.1.3" />
<PackageReference Include="MediatR" Version="6.0.0" />
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
</ItemGroup>
Every time you download a project which uses packageReference format, you only get the xx.csproj and related source files but without nuget packages. So when you open and load the solution or project in VS IDE, it will display the nuget packages name in solution explorer but with yellow warning triangle since now VS can't find those packages locally.
Is there a way to force fix all these references in all the projects
in one swoop using a command or a tool that 'cleverly' knows what to
do?
Just like what zivkan said in his answer, NuGet is normally configured to restore packages automatically if you've enabled those two options. Every time when we load the soultion in IDE, it will automatically restore the packages for us. Not sure the reason why it seems not to work in your machine, but you can check and try:
1.Go Nuget Package Manager=>Package Sources, make sure you've set https://api.nuget.org/v3/index.json as one the Available Package sources.
2.Right-click the solution in Solution Explorer, choose the Restore Nuget Packages to restore packages for whole solution.
3.Or you can Unload and reload the project to check if it helps.
4.By default, the packages are stored at C:\Users\xxx\.nuget\packages folder, you can check if those folders exists there.
(I delate all packages in that folder, so it's clear when I open the git solution in VS, the nuget is installing those necessary packages automatically, I'm not sure if there's any possibility that cause too many packages are being installed,so it will take some time? I check and find, to restore necessary packages for NorthWind solution, it require packages for over 370 MB)
I tried using 'Update-Package -reinstall' and got a bunch of lines
with 'No package updates are available from the current package source
for project 'project name'.... That's probably due to the missing
package files.
And for the reason why Update-Package -reinstall not work well in the project, maybe it's a similar issue like nuget issue #4103, for the packagereference in xx.csproj, several commands for now are not supported.
And after my check in my machine, the command obviously do not work for a PackageReference-format .net standard project. When I've installed related packages successfully, I run this command but only get No package updates are available from the current package source for project xxx, then I delete the installed packages, clean the cache and run the command again, I still get same message!
So I think this command can't recognize PackageRefernece format in .csproj, no matter whether I install related packages or not, it will always throw message No package updates are available ...
NuGet is normally configured to restore packages automatically. See the options page. The second Package Restore option, "Automatically check for missing packages during build in Visual Studio" is enabled by default on clean installs.
Here's a little video I recorded of what happens on my machine when I open the solution. Keep an eye out on the status bar at the bottom left of the window.
If your installation of Visual Studio does not behave in the same way with the automatic restore option enabled, then there is some other issue on your machine, but we don't have enough information from your question, as of the time I wrote this.

TFS solution is downloaded along with the Nuget Packages but the references are missing?

I'm training 5 people on using Visual Studio. They've mapped their drives and have "downloaded" the solution from TFS which contains 10 projects. All located at the same depth in TFS folder structure. When the new folks download the solution there's one project that doesn't get the NUGET references even though the Package folder (created by NUGET) is at the same depth of the other 10 projects when viewed in TFS.
We know how to add these manually but is there a way to automatically have VS do it? Why would only one project lose it's reference with the Package Folder right there?
It seems you are still using MSBuild-Integrated package restore approach. If NuGet recognizes that the MSBuild-Integrated package restore approach is enabled for the solution, Automatic Package Restore is skipped.
You need to migrating MSBuild-Integrated solutions to use Automatic Package Restore, then the packages will be restored automatically.
In addition, you need to update you NuGet manager to the latest version in VS Tools--Extensions and Updates. And make sure Visual Studio is configured to 'Allow NuGet to download missing packages' and 'Automatically check for missing packages during build in Visual Studio' in VS Tools--Options--NuGet Package Mnager--General.
To Fix:
Unload all projects first, then right click and select edit project.
Find this line:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Comment it out.
Reload all the projects and compile.
This applies to Nuget api version 2.
Note you may configure all projects for Nuget at the solution level.
The package manager for the solution presents a set of check boxes for every project along with the buttons (Install or Uninstall).

Commiting libraries added via NuGet

I have a Visual Studio project which I have committed to VisualSVN (via the VisualSVN => Commit menu in Visual Studio). I have added a number of libraries to this project via NuGet.
My colleague has downloaded the project I have uploaded to SVN (via VisualSVN => Get solution from Subversion...) and has found that these libraries are missing, and he is having to re-download them.
A few questions:
Is this by design? Or have I not committed my Solution properly? Or has my colleague not download the solution to his machine properly?
If this is by design, what is the correct way to re-add references to a solution downloaded from an SVN server? I am worried that I may have added a reference and worked with it, and that it may have been updated since so whenever my colleague re-adds the same reference via NuGet he will get a more up to date version that will be different, and this will break my program. Is this a valid concern?
Yes, this is by design. The whole concept of using Nuget is that you will not have to keep libraries in your version control system.
You need to Right Click on your solution in Visual Studio and select Enable NuGet Package Restore.
This will configure the solution to restore the NuGet packages (if any missing, or in case of none) whenever you'll do a build. Also, all the libraries that you've added for a particular project will have an entry in the packages.config created in the project's source drectory; for eg:
<packages>
<package id="jQuery" version="1.8.3" />
</packages>
This way NuGet makes sure everybody gets the same version.
Just enable "Nuget package restore" in your solution and packages will be automatically downloaded during the build:
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

Resources