VS 2019自定义ASP.NET Core项目模板 [英] VS 2019 Custom ASP.NET Core project templates

查看:447
本文介绍了VS 2019自定义ASP.NET Core项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何(甚至可以)创建一个自定义Visual Studio项目模板,该模板可以与Visual Studio 2019中可用的现有ASP.NET Core Web应用程序模板挂钩?

I'm trying to figure out how (or even if) I can create a custom Visual Studio project template that hooks into the existing ASP.NET Core Web Application template available in Visual Studio 2019?

我想做的事情类似于madskristensens ASP.NET核心模板包( GitHub源代码).但是,我想代替VS 2017,而不是VS 2019的经过修改的新建项目对话框"窗口执行此操作.因此,请想象在下面突出显示的位置添加一个额外的ASP.NET Core Web应用程序模板.

What I want to do is something similar to madskristensens ASP.NET Core Template Pack (GitHub source code). However instead of VS 2017 I want to do this for VS 2019's revamped "New Project Dialog" window. So imagine adding an additional ASP.NET Core web application template in the place highlighted below.

我能够创建新的项目模板(适用于Visual Studio和dotnet new),但到目前为止没有任何效果.有没有人能够以这种方式扩展VS 2019,或者在VS 2017之后被带走了?

I am able to create new project templates (both for Visual Studio and for dotnet new) but nothing has worked thus far. Has anyone been able to extend VS 2019 in this way, or was this taken away after VS 2017?

推荐答案

在VS 2017和2019(社区)之间进行了一些进一步的研究之后,我能够成功地弄清楚这一点!哦,哦,我们需要对此做些文档,因为这感觉像个傻瓜!

After doing some more investigation between both VS 2017 and 2019 (Community) I was able to successfully figure this out! Man oh man do we need some docs on this because this felt like a doozy!

我能够将ASP.NET Core模板包用作将某些东西放在一起的构造块.对于那些不知道的人,这些扩展程序旨在使用嵌入在扩展程序中的.nupkg文件将模板添加到Visual Studio. .nupkg文件的使用类似于 dotnet new与自定义模板一起使用.我有一个在GitHub上工作的原型,该原型同时支持 Visual Studio 2017和2019.

I was able to use the ASP.NET Core Template pack as a building block for putting something together. For those who don't know, the extensions are designed to add templates to Visual Studio using .nupkg file(s) embedded in the extension. The use of the .nupkg files is similar to how dotnet new works with custom templates. I've got a working prototype on GitHub that supports both Visual Studio 2017 and 2019.

现在,如果您像我一样,可以看看madskristensens或我的项目,然后问:这到底是怎么工作的?!"好问题!以下是我现在有时间填写的详细信息:

Now if you're like me, you may look at either madskristensens or my project and ask "How in the heck does this work!?" Great question! Here are the details I have the time to fill out right now:

  1. 构建一个或多个自定义模板,并将其放入*.nupkg文件
    • 在我的示例中,我的SampleTemplates项目包含三个不同的项目模板.我用dotnet pack
    • 生成.nupkg
  1. Build out a custom template (or templates) and place them into *.nupkg file(s)
    • In my sample, my SampleTemplates project contains three different project templates. I generate the .nupkg with dotnet pack
  • 至少需要满足一项或多项其他要求才能在ASP.NET Web应用程序向导中显示,但我还没有弄清楚,因为将文件添加到控制台应用程序模板并不会导致这种情况出现.我想尝试解决这个问题,尽管如果有人知道我会很乐意的!
  • 在进行一些测试时,看起来好像Framework符号没有替换为.csproj,这就是为什么我的示例中还包含一个TargetFrameworkOverride符号,而Framework符号替代了它.
  • In doing some testing, it didn't look like the Framework symbol didn't substitute into the .csproj, so that is why my example also includes a TargetFrameworkOverride symbol that the Framework symbol replaces.

我将在示例项目中尝试编写自述文件,以更好地概述完成此操作所需的所有细节.用手指交叉可以帮助某人(或者至少在将来不可避免地忘记我是如何做到这一点的时候帮助我)!

I'll try to put together a README in my example project to provide a better outline of all of the details required to accomplish this. Fingers crossed this helps someone out (or at least help me out in the future when I inevitably forget how I accomplished this)!

这篇关于VS 2019自定义ASP.NET Core项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆