简体   繁体   中英

Creating a Visual Studio Project Template that already includes a Nuget Package Reference?

I want to create a Visual Studio 2010 Project Template, which is essentially a ASP.net 3.5 Webforms Application.

However, I would like to automatically add a NuGet Package Reference. I can bundle the actual nupkg with the template if needed, but I wonder if it's possible to instead run the Install-Package command to always retrieve the latest version when creating a new Project? (I can guarantee that future versions never break the template)

Is that possible? I only made small changes to Project Templates so far, so I don't know exactly where I would start. I found some stuff for MVC 3, but as said, I'm on Webforms (and .net 3.5).

Given the answers here are now quite old, the advice at on the official NuGet site seems more likely to be useful for newcomers to this question:

https://docs.nuget.org/create/packages-in-visual-studio-templates

You can create a custom template for it, however it won't be fetched from the web, it'll only copy from your local disk (though maybe this will change in the future). Phil Haack wrote an article about this on his blog recently:

There are two major limitations:

  • The package must exist in the %ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC 3\Packages folder. MVC 3 doesn't go searching online for them.
  • The version attribute of the package in the element is required and is an exact match.

Check out the following blog post: http://blogs.msdn.com/b/marcinon/archive/2011/07/08/project-templates-and-preinstalled-nuget-packages.aspx which descrbies an upcoming feature of NuGet 1.5 (not yet released) that will enable preinstalled NuGet packages in all project types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM