Reputation: 18034
I'm trying to use nuget.exe outside of Visual Studio as part of our build infrastructure. The idea is that the various build tools are fetched by a bootstrapper script that initializes a working copy. The bootstrapper does this by using a file that specifies the required tools and their version.
packages.config
At first, it seemed like a good idea to keep a manually edited packages.config
file and use nuget restore
to install them during bootstrapping. However, this does not work for tools that have dependencies, unless I list every single dependency in the packages.config
as well, a much to arduous approach to be feasible, because I found no easy way to recursively find all dependencies of a package.
See also using nuget.exe commandline to install dependency .
nuget install
to update packages.config
The second idea was then to use nuget install
to install the packages, and let that command update the packages.config
, very similar to the Install-Package cmdlet in the package manager console. But, surprisingly, nuget install
does not support this! It either takes a packages.config
or a package ID as parameter, but I found no way to update the packages.config
with the new package and its dependencies.
This problem can also be found in another (two year old) SO question, see nuget.exe install not updating packages.config (or .csproj)?.
This must be a problem that many people face when using nuget outside of VS, so what is the best approach in that case?
Of course, I could just parse the packages.config
and emit a nuget install
for each package, but I really don't want to re-invent the dependency management part of nuget, this is what I'm using nuget for in the first place. So I'm left with the feeling that either an -WithDependencies
switch on nuget restore
or an -UpdatePackagesConfig
switch on nuget install
is missing...
Note that there are other SO questions regarding the broken approaches described above. What I'd like to know it what the best approach is to solve the root problem, i.e. manage packages with dependencies outside of VS.
Upvotes: 2
Views: 1674
Reputation: 17356
I believe that how nuget 3 works with project.json files may do what you are looking for. Essentially my understanding is that the unit of dependency becomes the package and not necessarily individual assemblies. From what I recall, the idea is the have only one place to manage these types of package references which the project (IDE/Editor), package manager, and other command line tools can use.
What I don't understand and feel somewhat frustrated about is that it appears that the project.json concept is being canceled. I don't know if plans are to reintroduce it at anytime in the future. In the mean time I keep on hearing updated info on tooling that takes advantage of project.json such as nuget so where you can actually rely on this is something that is unclear to me at this point.
Upvotes: 0
Reputation: 47917
nuget install
does not currently make changes to the project file.
nuget install
can be used to either restore the NuGet packages listed in a packages.config file or download and extract them.
If you do not need the project being modified then your solution of reading the packages in the packages.config file and calling nuget install
seems like a reasonable approach.
If you need the project to be modified then you could look at one of the following:
ripple install
command line which is similar to nuget install
but it also updates the project file. It has a lot of other features for supporting build servers so this might be a good fit.nuget update
, for example, does modify the project file, at least for file references, but will not run PowerShell scripts. So you could take the NuGet.exe source code and extend it.Of the above only 3) would give you exactly what you need. The other two would require a bit of work to read the packages from the packages.config file or some other list and then install them.
Upvotes: 2
Reputation: 20312
See my answer to Why does the nuget command line tool not follow dependencies?
nuget install My.Package.Id
will follow dependencies. However, if you want to install multiple packages, you will need to create a batch file with a separate nuget install
command for each package. These are top-level packages. You don't need to "install" the dependencies, as they will get downloaded automatically.
If you ultimately want a packages.config
file, I imagine you can generate one by enumerating all the packages that were downloaded. However, you would have to take care not to include multiple versions of the same package.
Upvotes: 0