VB.NET, Visual Studio, and Namespaces

0

How to make Visual Studio 2017 + VB.NET create new classes already with the namespace, as it does in C #?

I've tried creating and editing item templates using the $itemfolder$ parameter, but it does not seem to work:

Template

Namespace $itemfolder$

    Public Class $safeitemrootname$

    End Class

End Namespace

Output

Namespace $itemfolder$

    Public Class MyClass2

    End Class

End Namespace

Already using the $rootnamespace$ parameter, it does not work as it should:

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 .

Is there a way to make VS2017 automatically add namespaces to new VB.NET classes?

I know Resharper works, but it gets paid.

    
asked by anonymous 11.07.2017 / 03:44

1 answer

1

No, this is not possible. Visual Basic does not support the concept of creating namespaces equal to C #, so you create a " project with multiple default namespaces" you must first remove the namespace project pattern.

Whereitsays"Your Application" you leave empty, without writing anything. Unfortunately it's a pretty annoying thing to do.

And to create a file, just type the namespace in the file itself:

Namespace System
    Public Class ConsoleClone
        Public Shared Sub WriteLine(ByVal text$)
             Console.WriteLine(text)
        End Sub
    End Class
End Namespace

And you'll call it like:

System.ConsoleClone.WriteLine("Olá, mundo!")

Not to be ignorant, I tried to find a way to do this a long time ago, and found none. I do not even know if it's possible to do this, all my programming time with Visual Basic has turned me this way, and it's not as laborious as I expected.

    
12.07.2017 / 20:20