What are the benefits of enabling Nuget Package Restore? - version-control

What are the benefits for enabling the Nuget Package Restore feature in my Visual Studio solution?
The "Using NuGet without committing packages to source control" page in the Nuget Docs site suggests one reason:
When using a DVCS like Mercurial or Git, committing binaries can grow
the repository size like crazy over time, making cloning more and more
painful
Do you find this reason compelling enough to enable the feature? Are there other reasons?

There are more benefits of not having your NuGet package binaries in source control which are explained on another page, which I have reproduced here:
Distributed version control systems (DCVS) include every version of every file within the repository, and binary files that are updated frequently can lead to significant repository bloat and more time required to clone the repository.
With the packages included in the repository, team members may add references directly to package contents on disk rather than referencing packages through NuGet.
It becomes harder to "clean" your solution of any unused package folders, as you need to ensure you don't delete any package folders still in use.
These benefits are still related to not having the NuGet packages in version control. So the reason you highlighted is still valid.
Also note that the "Enable package restore feature" which uses MSBuild based package restore has been deprecated by the NuGet Team in later versions of NuGet because it has problems with NuGet packages that include custom MSBuild targets. Instead the NuGet team recommend to not use it but instead use the Visual Studio based package restore which will restore NuGet packages just before you build the project inside Visual Studio.
Also when NuGet was first released the NuGet team at the time expected you to put the binaries in source control so you did not have to rely on NuGet when you wanted to build your project. So a developer could clone the repository and build the project straight away without having to use NuGet. However you now have a choice.
When you are working with a large version control repository, such as MonoDevelop, then including binaries can make the repository very large. For smaller repositories including the NuGet packages is not really a problem.

Related

Github Visual Studio Pull : Will it include the Project's references?

Github Visual Studio 2022 Git Pull : Will it include the Project's references?
Using Visual Studio 2022 with Git. When pulling from a hosted repository into my local machine, will that also automatically set the same project references in my local machine as it is in the hosted repositories?
What should be the expected behaviour?
Thank you
I tried but I see other references than other users on other machines.
The project references should be defined in the .csproj file (or .vbproj, etc). This file should be included in ones source control repository.
You may need to perform a nuget restore if the references are fetched from a package manager (i.e. https://nuget.org), especially if someone else modified the references and pushed them to your remote in GitHub
For example, someone else on your project updates a reference to a newer version and pushes it up to GitHub. You then perform a git pull on the branch that these changes were made on, and suddenly you have new references or possibly see errors all over your code. When this happens, you almost certainly need to perform a nuget restore to get the new package references.

Odd NuGet cache issue; does NuGet keep track of package updates made?

I happened to get into a bit of a mess yesterday with our NuGet repository, and I've resolved it - but wanted to confirm my suspicions as to why it happened.
I did the following:
Amended some files
Packed the nuspec which includes these files
Pushed to our NuGet repository and confirmed
Confirmed that the NuGet repo had the latest version by downloading them on a dev environment
The changes I'd made were not included in the update in this dev environment (realised I hadn't updated the correct files). So I packed and pushed again without incrementing the version
Downloaded the nupkg on a different dev environment, still the changes were not there.
Took the exact same NuGet package and placed it in a local dir, and noticed when I updated from there it did include the changes.
Question
You'll notice as part of step 4 the old (incorrect) NuGet package was downloaded onto dev environment 1. Would NuGet have known this and, due to a lack of sound versioning, cached or kept hold of this copy somehow (despite my new push) and only allowed other dev environments this version and not the newest?
NOTE: I cleared the local cache on both dev environments prior to any updates made. My question was whether this was a server-side thing or not.
In addition to the copy of the package that is added to the packages folder in your solution NuGet will also cache packages already used in the following directory: C:\Users\YOUR_USER\.nuget\packages. Therefore if you do not change the version after making change you will have to remove the cached version from the directory I listed above for it to get the new changes since you did not change the package version.
I have the similar same problem. It's seem like a old issue.
So I will clear the http cache after I update the package version.
nuget locals http-cache -clear
It will work when you update your project package version.

Automatic NuGet Copy or Mirror upon package install (push to private repo)

Probelm
I want to set-up the no commit workflow for NuGet. But in order to do so, I need to make sure I have copies of any 3rd party packages and there dependencies installed from nuget.org copied to our private repo.
NuGet Mirror
I've looked into the NuGet mirror command, but this looks to be a manual process.
https://docs.nuget.org/docs/reference/command-line-reference#Mirror_Command
NuGet Copy
I also looked into NuGet copy, but could A) not get it to work and B) it still looks like a manual process.
https://www.nuget.org/packages/nuget.copy.extension/1.2.0
Is there any solutions to do this automatically upon package install? I can't force the developers to remember to manually copy the packages after they install them. When the developer installs a package, I want it to be copied over to our private NuGet repo. Please lead me in the right direction.
I'm not aware of any built-in NuGet feature to do this, but here's a simple way to make sure all packages are synced to a shared repository.
NuGet saves all downloaded packages to C:\Users\username\AppData\Local\NuGet\Cache
Just install sync software like BitTorrent Sync on each developer PC and the shared repo server. BTSync will automatically synchronize any new packages to the shared repo as well as all other devs.

Should self-created NuGet Packages be placed in version control?

I have started creating NuGet packages for some frequent dependency projects we used to use svn:externals for in our ASP.NET solutions. I'm hosting the .nupkg files in a network folder, and using that folder location as a NuGet feed.
I'm unsure what files to place in version control and where. Do you put both the .nuspec AND the .nupkg files in your repository? Do both the .nuspec and .nupkg file go in the project's version control? I thought since the .nuspec file generates the .nupkg file, you'd only need that file in version control. But, I was also thinking it might be a good idea to make the network folder, that I'm using as a NuGet feed, a repo in itself. Then I can version control the .nupkg files.
What are some good practices for version controlling created NuGet packages?
I'm in the same place you are. In keeping with the idea that you don't commit any file that you can build, my .nuspec files go in version control, but the .nupkg files don't.
Since the version number is incorporated into the .nupkg file name, you can have distinct versions of the package in the repository at the same time. You either need to either use the <version>$version$</version> form in the .nuspec file, and set the assembly version to auto-increment, or just manually change the version number each time. You could then make a Subversion tag on that version number, so you could get back to the source for a particular package version if you need to.
In order to let client projects automatically incorporate minor bug fixes in our packages, we're going to enable NuGet Package Restore in the client projects, and publish packages with short, fixed version numbers, like "1.2". When there's a simple bug fix for the package, we'll re-publish with that same version number. That will overwrite the prior version in the repository; client projects will then get the update when they restore packages during the build step.

How to Properly Use NuGet with Team Development?

So I would like to use NuGet to manage the various projects I use for a specific project my team and I are working on. Up to this point, I have placed my .js library files in the /Scripts directory of my web solution (ASP.NET MVC 2) and referenced those. Of course, this was manual and was annoying to manage during upgrades, etc.
Now that I am using NuGet, I realize that the entire goal of NuGet is to make this fairly painless. In addition, it appears that I shouldn't have to check my packages into my repository (AKA I don't need to manage my external libraries anymore). However, when I grab jQuery (for example) from NuGet, it places its specific files in the /Scripts directory of my project.
Where I get confused - what, if anything, should I check into source control at this point? Do I still check in the /Scripts directory?
In addition, if someone else is working on this project and checks out the solution from source control, are the packages automatically downloaded (assuming the solution comes with a valid packages.config)?
I'm just trying to clarify a couple points before we start using NuGet full-time.
There are two scenarios for NuGet vs VCS: to check-in or not to check-in, that's the question.
Both are valid in my opinion, but when using TFS as VCS, I'd definitely go for a no-checkin policy for NuGet packages.
That being said, even when using a no-checkin policy for NuGet packages, I'd still checkin the content changes that those NuGet packages have done to my projects. The \Scripts folder would be checked-in in its entirety (not selective, not ignored).
The no-checkin policy for packages to me means: not checking in the \Packages folder (cloak it, ignore it), except for the \Packages\repositories.config file.
As such, you are effectively not committing any NuGet packages, and when using Enable-PackageRestore from the NuGetPowerTools (this will be built-in in NuGet v1.6 just around the corner), any machine that checks out the code and builds, will fetch all required NuGet dependencies in a pre-build step.
This is true for both local development machines as for build servers, as long as Enable-PackageRestore is enabled in your solution and points to the correct NuGet repositories (local, internal, external).
If you think about it, when installing a NuGet package that only adds references to some binaries, you'd already be doing the samething in a no-checkin scenario: you would not commit the \Packages folder's subfolders, but still, you'd commit the project changes (the added reference).
I'd say, be consistent (for any type of package), whether it contains binaries only, content only, or a mix. Do not commit the packages themselves, do commit the changes to your sources. (if only to avoid the hassle of looking up what changed content-wise)
NuGet, like Nexus, are artifact repository (artifact being any type of deliverable, including potentially large binary).
The side-effect is for you to not store in an VCS (Version Control System) elements that:
wouldn't benefit from VCS features (branching, merging)
would increase significantly the size of the VCS repository (no delta or weak delta storage)
would be quite hard to remove from a VCS repository (designed primarily to keep the history)
But the goal is for you to declare what you need (and let NuGet fetch it for you) instead of storing it yourself.
So you can version /Scripts as a placeholder, but you don't need anymore to versioned any of its content now fetched automatically.