Visual Studio auto restores dll packages

1.1k Views Asked by At

In the company I work, inside every solution we have one folder packages, which contains all dll dependencies. This folder is not in repository with the rest of the solution.

Every time I build one project, all files inside folder packages are restored and any missing dlls appear again. This happens in the beginning of the build, no matter if the build succeeds of fails. Even if the project has no dll dependencies, any missing dlls in packages are restored.

I suspect it is a setting in msbuild but I cannot find it. Does anyone know where it might be or if there is a place with msbuild *.targets files?

thanks for any help

2

There are 2 best solutions below

2
On

From the MS Docs regarding regarding Nuget:

MSBuild: use the msbuild -t:restore command, which restores packages packages listed in the project file (PackageReference only). Available only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual Studio 2017. nuget restore and dotnet restore both use this command for applicable projects.

Further down, there's quite a bit about enabling/disabling and modifying this behavior in a variety of ways.

Allow NuGet to download missing packages: controls all forms of package restore by changing the packageRestore/enabled setting in the NuGet.Config file as shown below (%AppData%\NuGet\NuGet.Config on Windows, ~/.nuget/NuGet/NuGet.Config on Mac/Linux). In Visual Studio, this setting allows the Restore NuGet Packages command on the solution's context menu to work.

Appearing to be more to your issue:

Automatically check for missing packages during build in Visual Studio: controls automatic restore by changing the packageRestore/automatic setting in the NuGet.Config file as shown below (%AppData%\NuGet\NuGet.Config on Windows, ~/.nuget/NuGet/NuGet.Config on Mac/Linux). When this option is set, running a build from Visual Studio automatically restores any missing packages. The option does not affect builds run from the command line using MSBuild.

1
On

This is because Visual Studio restores packages defined in the packages.config files.

You can control this behaviour in Visual Studio in options: VS NuGet options