我试图弄清楚如何(或者是否)可以创建一个自定义 Visual Studio 项目模板,该模板挂钩到 Visual Studio 2019 中可用的现有 ASP.NET Core Web 应用程序模板?
我想做的是类似于 madskristenses 的事情ASP.NET Core 模板包 https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ASPNETCoreTemplatePack (GitHub 源代码 https://github.com/madskristensen/AspNetCoreTemplatePack)。然而,我想为 VS 2019 改进的“新项目对话框”窗口执行此操作,而不是 VS 2017。因此,想象一下在下面突出显示的位置添加一个额外的 ASP.NET Core Web 应用程序模板。
我能够创建新的项目模板(适用于 Visual Studio 和dotnet new
)但到目前为止没有任何效果。有没有人能够以这种方式扩展 VS 2019,还是在 VS 2017 之后就被取消了?
在 VS 2017 和 2019(社区)之间进行更多调查后,我成功地解决了这个问题!天哪,我们需要一些这方面的文档吗,因为这感觉太棒了!
我能够使用 ASP.NET Core 模板包作为构建块来组合某些内容。对于那些不知道的人,这些扩展旨在使用以下命令将模板添加到 Visual Studio.nupkg
扩展名中嵌入的文件。使用.nupkg
文件类似于dotnet new使用自定义模板 https://learn.microsoft.com/en-us/dotnet/core/tools/custom-templates。我有一个GitHub 上的工作原型 https://github.com/willwolfram18/SampleTemplates支持bothVisual Studio 2017 和 2019。
现在,如果您像我一样,您可能会查看 madskristenses 或我的项目并问“这到底是如何工作的!?”好问题!以下是我现在有时间填写的详细信息:
- Build out a custom template (or templates) and place them into
*.nupkg
file(s)
- 在我的样本中,我的
SampleTemplates
项目包含三个不同的项目模板。我生成.nupkg
with dotnet pack
- A
vs-2017.3.host.json
file is required in the .template.config/
folder so that the ASP.NET Web Application wizard can display the template.
- 至少需要满足 1 个或多个其他要求才能在 ASP.NET Web 应用程序向导中显示,但我尚未弄清楚这些要求,因为将文件添加到控制台应用程序模板不会导致它出现。我想尝试解决这个问题,尽管如果有人已经知道,我很乐意提供帮助!
- The
template.json
needs a Framework symbol https://github.com/willwolfram18/SampleTemplates/blob/master/SampleTemplates/templates/dotnet-new-custom-api/.template.config/template.json#L28-L47 to define the list of .NET Core framework targets that are supported by the template.
- 在进行一些测试时,它看起来并不像
Framework
符号没有替换成.csproj
,这就是为什么我的示例还包括TargetFrameworkOverride
符号表示Framework
符号替换。
- 放置
.nupkg
文件到rootVSIX 扩展项目的并确保将“包含在 VSIX 中”标志设置为True
。我强调 root 是因为最初我将 NuGet 包登陆到build\
我的扩展中的文件夹和我的模板没有被选取。
我将尝试在我的示例项目中整理一个自述文件,以更好地概述完成此任务所需的所有细节。祈祷这可以帮助别人(或者至少在将来当我不可避免地忘记我是如何完成这件事时帮助我)!
Update
截至 2020 年 9 月 2 日,Visual Studio 团队发布了一项实验性功能,其中包括dotnet new
Visual Studio 中的模板。我用它做了一些极其简单的测试,它看起来确实有效,但并不完美。例如,我创建了一个dotnet new
支架多个的模板.csproj
文件和.sln
文件,输出与我的解决方案不太匹配。
这是描述该公告的 Visual Studio 博客文章:https://devblogs.microsoft.com/dotnet/net-cli-templates-in-visual-studio/ https://devblogs.microsoft.com/dotnet/net-cli-templates-in-visual-studio/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)