Visual Studio模板-自定义参数 [英] Visual Studio Templates - custom parameters

查看:180
本文介绍了Visual Studio模板-自定义参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2015模板为我创建一个项目,在我的C#类中,我有类似$projectname$之类的替换项,如果我这样命名我的项目-MyTemplatedProject,它们将非常有用.我使用$projectname$作为类名和名称空间的一部分.

I am using VS 2015 templates to create a project for me, within my C# classes I have substitutions like $projectname$ and they work great if I name my project like this - MyTemplatedProject. I use $projectname$ for the part of class names and namespaces.

如果我创建生成类似$projectname$Context的类,它将变为MyTemplatedProjectContext并且一切都很好.

If I create generate a class like $projectname$Context, it becomes MyTemplatedProjectContext and all is well.

但是但是,如果我将项目命名为MyTemplatedProject.FrontEnd,则生成的类会遇到问题,因为它们的名称中带有..

But if I name my project MyTemplatedProject.FrontEnd I have problems with the classes that are generated because they have the . in their name.

替换$projectname$Context变为MyTemplatedProject.FrontEndContext,不适用于类名.

The substitution $projectname$Context becomes MyTemplatedProject.FrontEndContext and that does not work for a class name.

如何创建基于$projectname$的自定义参数,理想情况下,我将有一个类似$projectnameUpToFirstDot$的参数,当项目名称为MyTemplatedProject.FrontEndContext时该参数仅返回MyTemplatedProject?

How do I create custom parameters based $projectname$, ideally I would have a parameter like $projectnameUpToFirstDot$ which only returns MyTemplatedProject when the project name is MyTemplatedProject.FrontEndContext?

推荐答案

如果只想基于项目名称生成有效的类名称,而不是创建自定义模板参数,则可以将$projectname$更改为记录为:

If you just want to generate a valid class name based on the project name, instead of creating a custom template parameter, you can change $projectname$ to $safeprojectname$, which is documented as:

用户在新建项目"对话框中提供的名称,其中删除了所有不安全的字符和空格.

The name provided by the user in the New Project dialog box, with all unsafe characters and spaces removed.

这篇关于Visual Studio模板-自定义参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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