简体   繁体   English

Visual Studio,VB.NET和命名空间

[英]Visual Studio, VB.NET and Namespaces

How can I make my VS2017 automatically add namespaces to new *.vb files? 如何使VS2017自动将命名空间添加到新的* .vb文件?

I tried to create new item templates using $itemfolder$ , but it doesn't work: 我尝试使用$itemfolder$创建新的项目模板,但是不起作用:

Template 模板

Namespace $itemfolder$

    Public Class $safeitemrootname$

    End Class

End Namespace

Output 输出量

Namespace $itemfolder$

    Public Class MyClass2

    End Class

End Namespace

Using the $rootnamespace$ parameter, it doens't work as I'm expecting: 使用$rootnamespace$参数,它无法正常运行:

Template 模板

Namespace $itemfolder$

    Public Class $safeitemrootname$

    End Class

End Namespace

Output 输出量

Namespace ConsoleApp1

    Public Class MyClass

    End Class

End Namespace

Solution Explorer 解决方案资源管理器

I was expecting the namespace to be ConsoleApp1.TestNamespace or TestNamespace in that case. 在这种情况下,我期望名称空间为ConsoleApp1.TestNamespaceTestNamespace

Is there any way to VS2017 automatically add namespaces to my new classes? 有什么办法可以让VS2017自动将命名空间添加到我的新类中? I also know that Resharper can do this job, but I'm looking for a free solution. 我也知道Resharper可以做到这一点,但我正在寻找免费的解决方案。

You seem to have been on the right track but you may have missed a step. 您似乎走上了正确的道路,但您可能错过了一步。 There's a command you have to execute from the command line: devenv.exe /InstallVSTemplates as seen on this thread here. 您必须从命令行执行以下命令: devenv.exe /InstallVSTemplates如此处此线程所示。 Have a look and see if it solves your problem. 看看是否能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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