[英]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.我想创建一个 Visual Studio 2010 项目模板,它本质上是一个 ASP.net 3.5 Webforms 应用程序。
However, I would like to automatically add a NuGet Package Reference.但是,我想自动添加 NuGet Package 参考。 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?
如果需要,我可以将实际的 nupkg 与模板捆绑在一起,但我想知道是否可以改为运行 Install-Package 命令以在创建新项目时始终检索最新版本? (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).
我为 MVC 3 找到了一些东西,但如前所述,我在 Webforms(和 .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:鉴于这里的答案现在已经很老了,官方 NuGet 网站上的建议似乎更有可能对这个问题的新手有用:
https://docs.nuget.org/create/packages-in-visual-studio-templates 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).您可以为它创建一个自定义模板,但是它不会从 web 中获取,它只会从您的本地磁盘复制(尽管将来可能会改变)。 Phil Haack wrote an article about this on his blog recently:
Phil Haack 最近在他的博客上写了一篇关于此的文章:
There are two major limitations:
有两个主要限制:
- The package must exist in the %ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC 3\Packages folder.
package 必须存在于 %ProgramFiles%\Microsoft ASP.NET\ASP.NET MVC 3\Packages 文件夹中。 MVC 3 doesn't go searching online for them.
MVC 3 不会 go 在线搜索它们。
- The version attribute of the package in the element is required and is an exact match.
元素中 package 的版本属性是必需的,并且是完全匹配的。
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.查看以下博客文章: http://blogs.msdn.com/b/marcinon/archive/2011/07/08/project-templates-and-preinstalled-nuget-packages.aspx描述了 NuGet1 即将推出的功能。 (尚未发布)这将在所有项目类型中启用预安装的 NuGet 包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.