Home > Net >  In C#, how to `Paket Add` dependencies to all projects in a folder even when they are in separate so
In C#, how to `Paket Add` dependencies to all projects in a folder even when they are in separate so

Time:12-27

Say I have a packet.dependencies file in a root folder full of different solutions adding up to hundreds of projects, each with a paket.references file.

Is there an easy way to go about adding the same package/same version in all the projects with a single command (or close) with paket?

In my use case, I'm trying to add an analyzer to every C# project we have. It would be tedious to add the same package and version to hundreds of different C# projects...

CodePudding user response:

You can use the --project-filter option and specify a glob pattern that matches all the projects in your solution. E.g. adding "Pack" to all your projects:

paket add --project-filter "**/*.csproj" Pack.

This will search for all the .csproj files in your solution and add the "Pack package" to each of them.

Or you use paket update to update the version of an existing package in all the projects in your solution:

paket update --project-filter "**/*.csproj" Pack --version 1.2.3

CodePudding user response:

It was actually just paket add <package ID>, if ran in the root folder with the paket.dependencies file, it will actually find all the .csproj files and add the dependency.

It was the following line in the docs that threw me off:

By default packages are only added to the solution directory, but not on any of its projects. It's possible to add the package to a specific project:

But it will actually add the dependency to all solutions and projects.

  • Related