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

2020-03-24 04:15发布

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! =)

3条回答
三岁会撩人
2楼-- · 2020-03-24 04:57

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. :)

查看更多
等我变得足够好
3楼-- · 2020-03-24 04:59

I think you're thinking 'Imports xxlibnamexx'

And as far as I am aware, if they are not in the text source file, they may just be System related ones that are intrinsically imported.

查看更多
劫难
4楼-- · 2020-03-24 05:20

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.

查看更多
登录 后发表回答