Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET 2K8: How to make all imports visible within a class?

Generally speaking, a common VB.NET class should look like the following:

Public Class MyClassName

End Class

Besides, I have already seen, if I remember correctly, all of the import statements visible just like in C#:

Imports System
Imports System.Data
Imports System.Linq

Public Class MyClassName

End Class

How to make these default imports visible by default in VB.NET using Visual Studio 2008?

Is there some setting or the like in the options I shall set?

Thanks! =)

like image 299
Will Marcouiller Avatar asked Dec 29 '22 01:12

Will Marcouiller


2 Answers

Good question. The VB.NET Language spec only mentions "implicit imports" without giving an authoritative list. I can reverse-engineer it from the command line as shown in the output window, VS2008 and VS2010 uses this /Imports command line option:

  • Microsoft.VisualBasic,
  • System,
  • System.Collections,
  • System.Collections.Generic,
  • System.Data,
  • System.Diagnostics,
  • System.Linq,
  • System.Xml.Linq

MSBuild sets these in Microsoft.VisualBasic.targets from the Import variable. Which is set in the .vbproj file:

  <ItemGroup>
    <Import Include="Microsoft.VisualBasic" />
    <Import Include="System" />
    <Import Include="System.Collections" />
    <Import Include="System.Collections.Generic" />
    <Import Include="System.Data" />
    <Import Include="System.Diagnostics" />
    <Import Include="System.Linq" />
    <Import Include="System.Xml.Linq" />
  </ItemGroup>

Altering the Project + Reference setting does alter this list but there's no obvious one-to-one correspondence since this screen changes assembly references, the <Import> build variable lists name spaces. I'll have to punt, this ultimately is determined by the project template.

like image 162
Hans Passant Avatar answered Jan 11 '23 22:01

Hans Passant


Right click on the project in Visual Studio then go to Properties. On the "References" tab there is a list of imported namespaces at the bottom. Anything added there doesn't need to be imported for any file in the project.

So to see the ones that are defaulting, you can just look there. :)

like image 25
Tridus Avatar answered Jan 11 '23 22:01

Tridus