I was wondering why is Nuget restoring needed? I mean nugets are just files that are downloaded to your solution. So if they are downloaded once why do they need to be restored sometimes?
When you install a NuGet package to your solution/project, it does not add the files from that package to your solution/project. Rather it makes an entry to the csproj/project.json/packages.config (depending on the project type and VS version) on the required package dependency. And downloads the packages to the NuGet cache (not the solution).
When you build the solution, these packages are restored to the solution. Restoring means the packages (.nupkg) are expanded to individual assemblies and the exact dependency to these assemblies are written down in the assets file (project.assets.json) created in the obj directory. Again, here the files are not copied to the solution but instead are referenced from the cache. The build output will contains these files as required. Remember caching plays a big role into when the packages are actually downloaded vs. referenced from the cache.
Related
I have a project (I am the package creator) that has several builds that each depend on MVC (Microsoft.AspNet.Mvc, Microsoft.AspNet.Razor, and Microsoft.AspNet.WebPages). When my package is installed into a brand new MVC project, everything works as expected.
However, when the package is uninstalled, it destroys the project because MVC is inadvertently uninstalled (because it is a dependency), along with all of the dependencies it has. When I try to reinstall those packages, it seems there is no way to get the versions right because (since there is no NuGet log) I have no idea what versions it uninstalled.
My package DOES DEPEND on these libraries being in place, that is, those libraries are referenced directly from my DLL. But I don't want my NuGet package to uninstall them.
Is there a way?
I am using NuGet to add packages to my solution. NuGet added a Packages folder to my visual studio’s solution root folder. The concerning part is that the “packages” folder is not part of source control. That means the source code comes from TFS, but the project references come from a folder that is fed by external source. People can put malicious code in the packages folder and build the application.
I like to understand how my other colleagues that get the source code from the TFS source control can build the project with packages folder not being part of the source control?
We did have a similar problem where our build server wasn't allowed to have internet connection, so couldn't download packages. We started with creating our own NuGet Source, which was simply a shared folder with all packages copied to it. The visual studio projects would of course use these packages rather than packages hosted on www.nuget.org
I must say that we scrapped this idea because of the overhead of doing it as our package usage increased.
My advise is that if you are worried about packages downloaded at build time, store the packages folder on source control.
NuGet supports automatic package restoration so your colleagues who use this feature will automatically download required packages. There is a policy at nuget.org that prevents user to delete or update exact version of package once it is published so it can support package restore without any interruptions - see this answer for more detail. If you are using other package sources than nuget.org than you should check their package deletion/update policy because it may be different.
when I create a build for the Team Foundation Service, I get all kind of reference dll's not found exceptions.
These references are added by nugget packages.
I've added the 'package restore' option on the solution which added 3 files in a .NuGet folder.
EDIT
When i got the solution from TFS on another pc, i got the same errors (missing dll's), so it's not only the TFS build service having problems.
The missing dll's are are missing files from installed nuget packages (some are part of the default VS template, Unity was a package i added later), which (the packages) are added on the first pc, but then are missing on the next pc (that's why i added the 'or' in the title of this question)
How can i get the Nuget added files on pc2 too?
I guess you've found a solution by now. I write this just to provide an answer for this question.
To have NuGet packages automatically downloaded on another PC, you need to enable NuGet package restore on build. You do this in two steps:
Right click the solution and select Enable NuGet Package Restore.
This will add a .nuget solution folder with NuGet.Config, NuGet.exe and NuGet.targets underneath it. These files should actually be checked in to source control, but the binary file is tiny. It will also modify the MSBuild scripts in all projects of the solution to import the NuGet.targets file to hook NuGet into the build process.
In Tools -> Library Package Manager -> Package Manager Settings make sure the option 'Allow NuGet to download missing packages during build' is checked.
This step must be done on all machines.
Now the BuildDependsOn property of all project build scripts should make the RestorePackages target in NuGet.targets kick in and download missing packages before you get build errors for missing references.
I created an ASP.NET MVC project in Visual Studio 2012 on my laptop, did a bit of work on it without issues, then checked it into source control. I've checked it out on my main desktop machine (a completely fresh Git clone), and it won't compile stating that various references are missing (one of which being entityframework.dll). Looking back on my laptop, those DLLs are in my project's "bin" folder (which I didn't add to source control for obvious reasons). On my laptop, if I rename my bin folder, then I get the same compile errors. Am I incorrect in not committing certain DLL files that are in my bin folder? Surely those DLLs should be copied into the bin directory at compile time?
The desktop probably can't find the folder to copy from.
You should add the references using NuGet (if you aren't already) and include the packages folder in source control. (or enable package restore)
You should look as to where the library references are stored in your project file. If the project is referencing copies in your bin directory then you have your project setup incorrectly.
You should maintain a libraries directory in your source control tree that id checked in like any other dependency.
The bin directory should be output only.
I made a checkout of my project from a different location, now I noticed that I didn't commit the dll files from /packages, can I get nuget to download them?
The only way to do this right now is to is to remove the reference from packages.config and reinstall those packages. We're planning to support this scenario in the future (more info here http://nuget.codeplex.com/workitem/165).