I want to create a template that installs the latest version of a NuGet package and all of its dependencies. Most common solution using NuGet.VisualStudio.TemplateWizard
installs only specified package version and doesn't resolve any dependencies. Basically I want to run Install-Package example
when a project using my template is created.
How to create a project template that installs latest NuGet dependencies?
Obviously, your requirement is very clear. But we do not recommend you doing that. Because update the packages will break the template.
What we know is that preinstalled packages work using template wizards. A special wizard gets invoked when the template gets instantiated. The wizard loads the list of packages that need to be installed and passes that information to the appropriate NuGet APIs.
Besides, both the id
and version
attributes are required in the wizard, which used to specify version of a package will be installed even if a newer version is available. This prevents package updates from breaking the template, leaving the choice to update the package to the developer using the template.
what's more, update the package by the developer is a very simple matter. And developers could update some packages according to their requirement, no need update all packages.