You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for batch "Add a reference to a project file" invocation #12629
Currently, it is possible to resolve the version correctly through post-action. It is a wrapper around your functionality.
As we can see, there is no support for specifying a set of project links, so users need to specify dependencies one by one in post actions (e.g. add reference).
Once you extend your API, we can utilize it for supporting batch "add reference" operations.
If it's not VS, I'm not really sure I understand what the ask is here.
I'm not really sure what Add Reference functionality on NuGet end you're referring to.
In add package we use MSBuild APIs to write references, and that's it.
Can you point to the code in the NuGet repo that you're calling that needs additional APIs?
ghost removed
WaitingForClientTeamCustomer replied, needs attention from client team. Do not apply this label manually.
@nkolev92 this is coming from the Template Engine, which has two hosts - the dotnet CLI, and the VS New Project Dialog. Specifically, we'd like to have some kind of batch/multi-package-add capability in the NuGet CLI so that we can make project templates more correct for a larger portion of our user base. Let me walk through the problem end to end.
Currently, many project templates (MS and 3rd party) hard code PackageReference items in generated project files, but they'll often have a variable for the 'version' of that PackageReference. This is bad for a few reasons (versions getting out of date, hard to maintain) but for this conversation we mostly find it bad because hard-coding <PackageReference Include="..." Version="..." /> makes it very hard for a project to participate in CPM if the rest of the repo/solution/etc is onboarded to CPM. Package Authors would need to go through a number of complex conditional statements in the Template Engine to make sure they handle all cases, which increases the authoring burden for templates.
If we look at what the actual need of the template author is, they want to ensure that a generated project gets a PackageReference to a certain package with a certain version. Turns out that we already have that capability in the CLI via dotnet add package, and better yet the NuGet team has already done the work to make this command interact well with CPM in every case! This is basically perfect for us - it means we can ask template authors to remove hard-coding their templates, and instead move to a model where, after the project file is generated, we orchestrate calling dotnet add package for any packages that they would like to add. This nicely abstracts needing to know how to add the packages for template authors.
Which brings us to this issue. If we do this, then if a template author adds let's say 5 packages to a project that project will be evaluated at least 5 times - once for each invocation of dotnet add package. This seems unnecessary to me, and means a lot of overhead for templating operations. As a back-of-napkin estimate, I created a new console app and timed how long it took to run dotnet add package Newtonsoft.Json via Measure-Command. For me, on my work laptop this operation took 4.2 seconds. Doing that 5 times would dwarf the actual time required to generate the template content and restore (which today takes 2.25s on the same laptop).
So that's the request. It would be awesome to have an ability or syntax like dotnet add package [email protected] Serilog@3 ... so that a single evaluation could be done and multiple PackageReferences could be added in one logical operation.
As an immediate minor improvement you can make use of the --no-restore feature to add references multiple times so you at least avoid multiple restores.
Activity
heng-liu commentedon Jun 6, 2023
Hi @YuliiaKovalova, may I know which API you're using right now in post-action? Do you mean adding package reference or project reference? Thanks!
YuliiaKovalova commentedon Jun 7, 2023
Hi @heng-liu ,
I mean adding package reference to project file :)
nkolev92 commentedon Jun 12, 2023
@YuliiaKovalova Is this ask related to a Visual Studio API such as
IVsPackageInstallerYuliiaKovalova commentedon Jun 14, 2023
I don't think so.
@baronfel, please correct me if I am wrong.
nkolev92 commentedon Jun 14, 2023
@YuliiaKovalova
If it's not VS, I'm not really sure I understand what the ask is here.
I'm not really sure what Add Reference functionality on NuGet end you're referring to.
In add package we use MSBuild APIs to write references, and that's it.
Can you point to the code in the NuGet repo that you're calling that needs additional APIs?
baronfel commentedon Jun 29, 2023
@nkolev92 this is coming from the Template Engine, which has two hosts - the dotnet CLI, and the VS New Project Dialog. Specifically, we'd like to have some kind of batch/multi-package-add capability in the NuGet CLI so that we can make project templates more correct for a larger portion of our user base. Let me walk through the problem end to end.
Currently, many project templates (MS and 3rd party) hard code PackageReference items in generated project files, but they'll often have a variable for the 'version' of that PackageReference. This is bad for a few reasons (versions getting out of date, hard to maintain) but for this conversation we mostly find it bad because hard-coding
<PackageReference Include="..." Version="..." />makes it very hard for a project to participate in CPM if the rest of the repo/solution/etc is onboarded to CPM. Package Authors would need to go through a number of complex conditional statements in the Template Engine to make sure they handle all cases, which increases the authoring burden for templates.If we look at what the actual need of the template author is, they want to ensure that a generated project gets a PackageReference to a certain package with a certain version. Turns out that we already have that capability in the CLI via
dotnet add package, and better yet the NuGet team has already done the work to make this command interact well with CPM in every case! This is basically perfect for us - it means we can ask template authors to remove hard-coding their templates, and instead move to a model where, after the project file is generated, we orchestrate callingdotnet add packagefor any packages that they would like to add. This nicely abstracts needing to know how to add the packages for template authors.Which brings us to this issue. If we do this, then if a template author adds let's say 5 packages to a project that project will be evaluated at least 5 times - once for each invocation of
dotnet add package. This seems unnecessary to me, and means a lot of overhead for templating operations. As a back-of-napkin estimate, I created a new console app and timed how long it took to rundotnet add package Newtonsoft.JsonviaMeasure-Command. For me, on my work laptop this operation took 4.2 seconds. Doing that 5 times would dwarf the actual time required to generate the template content and restore (which today takes 2.25s on the same laptop).So that's the request. It would be awesome to have an ability or syntax like
dotnet add package [email protected] Serilog@3 ...so that a single evaluation could be done and multiple PackageReferences could be added in one logical operation.nkolev92 commentedon Jun 29, 2023
Thanks for clarifying it @baronfel!
As an immediate minor improvement you can make use of the --no-restore feature to add references multiple times so you at least avoid multiple restores.