Click here to Skip to main content
13,350,047 members (48,519 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 26 Jul 2006

Compile VB.NET code without Microsoft.VisualBasic.dll

, 1 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Compile VB.NET code without an implicit reference to Microsoft.VisualBasic.dll.


Let's say you are developing a program using Visual Basic .NET (2003 or 2005), and you wish to make sure that your code is using "pure" .NET and is VB6 free.


As you all know, Visual Basic .NET enables you to code using VB 6 legacy syntax and keywords. For example, we can use CInt, Mid, InStr etc. The implementation of the compatibility layer is at the Microsoft.VisualBasic.dll library.

Behind the scene

When compiling your program, using either the Visual Studio IDE or the vbc command line compiler, Microsoft.VisualBasic.dll is added as a reference, and there is no direct approach of removing this reference. The official (and quite not reasonable) solution to the problem is to add the -sdkpath command line option to the vbc (you cannot set this option in a VB Visual Studio project). Copy the .NET platform assemblies that are required by your project references, into a different directory, and build your program from the command line, having the -sdkpath pointing to that directory.

Behind the whole theater

There is an undocumented vbc command line option -novbruntimeref, which you can use (at your own risk :), as an alternative to -sdkpath. Adding -novbruntimeref excludes the implicit addition of the Microsoft.VisualBasic.dll reference. For example, compiling with the -novbruntimeref option will fail if you will use Mid instead of Substring.

Now, your compilation is VB6 free. And don't get me wrong, VB was a great friend of mine since VB3, and some of my best friends are ... well, you got the point.

Should I stop using the Microsoft.VisualBasic namespace?

Yes and No.

No - Productivity. If you wish to parse strings using the VB6 Mid instead of Substring, it's your call. After all, this layer was made for enabling you to import VB6 applications into .NET, seamlessly, without code changes.

Yes - Compatibility. For example, VB6 collections are 0 based for read, and -1 based for insertion. Upgraded application that use VB collections through inconsistent implementations of IList may experience some bugs.

Both points are very important. The choice is all yours.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rafael Mizrahi
Chief Technology Officer Feng-GUI
United States United States
Rafael Mizrahi is a CTO at Feng-GUI

He is also a hacker contributor at the mono project, and a GarageGeeks member.

Rafael Mizrahi personal blog -

You may also be interested in...


Comments and Discussions

NewsMicrosoft now released this feature in VB9 ORCAS Pin
Rafael Mizrahi12-Jun-07 1:37
memberRafael Mizrahi12-Jun-07 1:37 
Questionwhat happen when I use DirListBox in c# Pin
Do.It11-Apr-07 2:00
memberDo.It11-Apr-07 2:00 
GeneralYou people need to calm down [modified] Pin
LuharVB25-Jan-07 8:01
memberLuharVB25-Jan-07 8:01 
AnswerRe: You people need to calm down Pin
Rafael Mizrahi25-Jan-07 8:26
memberRafael Mizrahi25-Jan-07 8:26 
Newsnovbruntimeref compiler option Pin
Rafael Mizrahi4-Aug-06 1:10
memberRafael Mizrahi4-Aug-06 1:10 
GeneralWrong reason Pin
jwelch23-Aug-06 5:42
memberjwelch23-Aug-06 5:42 
QuestionWhy? Pin
jwelch21-Aug-06 5:10
memberjwelch21-Aug-06 5:10 
GeneralRe: Why? Pin
Anthony Missico3-Aug-06 10:01
memberAnthony Missico3-Aug-06 10:01 
AnswerRe: Why? [modified] Pin
Michel Posseth1-Aug-06 23:51
memberMichel Posseth1-Aug-06 23:51 
General[Message Deleted] Pin
Rafael Mizrahi2-Aug-06 0:07
memberRafael Mizrahi2-Aug-06 0:07 
GeneralRe: Why? Pin
Michel Posseth2-Aug-06 0:36
memberMichel Posseth2-Aug-06 0:36 
Well i do not give You up yet Smile | :)

Many people have discussed this before, the Microsoft.VisualBasic.Compatibility.dll is something that I can understand you would want to avoid, but Microsoft.VisualBasic.dll does not fall into the same category.

As a experienced VB6 and VB.Net coder i can tell you ( started on the C64 with basic )
that Microsoft.VisualBasic.dll has some methods that do not behave the same as there legacy VB6 counterparts ( datediff for example )

Also i do not think or believe anything ,, i talk facts .

How do i get these facts ? by beeing active in my job an listen to the people who make the product that i am working with , believe me if the ms VB development team told us that the Microsoft.VisualBasic.dll is there for backwards compatibility purposes i was one of the first to abandon it , when my colegues still coded with DAO i used ADO cause i knew it was the future

the below is written by

Stephen Weatherford, Developer on the Visual Basic team
Cameron Beccario, Developer on the Visual Basic core compiler team

Host: Cameron (Microsoft)
Q: I didn't think the runtime was included if you didn't use it.

A: The VB runtime is always included for every VB program. The VB runtime not only includes familiar functions like UCase and MsgBox, but also a host of helper functions that the compiler uses. For example, the VB runtime has a helper function for converting Strings to Booleans. And the entire mechanism for latebinding also sits in the VB runtime. Note that the VB runtime is different than the compatibility library (Microsoft.VisualBasic.Compatiblity.dll), which you should reference only when you need it (such as when upgrading your code from VB6 to VB.NET using the upgrade tool).

Host: Stephen (Microsoft)

Q: Re: the question, "There are two VB namespaces, right? Compatibility and regular VB?"

A: Let me add to this... There *are* two namespaces--Microsoft.VisualBasic and Microsoft.VisualBasic.Compatibility. Microsoft.VisualBasic.Compatibility is only used when you upgrade a VB6 application, and is for backwards compatibility purposes (it is a separate DLL from Microsoft.VisualBasic.dll). The Microsoft.VisualBasic namespace, however, provides the runtime functions for Visual Basic. As Cameron pointed out, you always get this reference for free (it is different from the VB compatibility runtime). It is *not* for backwards compatibility, but rather for current Visual Basic .NET programs.

I hope to have shined some light on the subject


Michel Posseth [MCP]
GeneralRe: Why? [modified] Pin
Anthony Missico3-Aug-06 10:06
memberAnthony Missico3-Aug-06 10:06 
GeneralPrevent the reference being added to new projects ... Pin
Duncan Edwards Jones28-Jul-06 7:47
memberDuncan Edwards Jones28-Jul-06 7:47 
GeneralRe: Prevent the reference being added to new projects ... Pin
dfinger1-Aug-06 2:38
memberdfinger1-Aug-06 2:38 
GeneralRe: Prevent the reference being added to new projects ... Pin
Daniel Finger1-Aug-06 3:28
memberDaniel Finger1-Aug-06 3:28 
GeneralRe: Prevent the reference being added to new projects ... Pin
lpellerin6-Sep-06 4:37
memberlpellerin6-Sep-06 4:37 
GeneralRe: Prevent the reference being added to new projects ... Pin
Rafael Mizrahi6-Sep-06 22:04
memberRafael Mizrahi6-Sep-06 22:04 
QuestionRe: Prevent the reference being added to new projects ... Pin
nitkapy2k@gmail.com12-Mar-08 22:42
membernitkapy2k@gmail.com12-Mar-08 22:42 
GeneralRe: Prevent the reference being added to new projects ... Pin
Rafael Mizrahi12-Mar-08 23:01
memberRafael Mizrahi12-Mar-08 23:01 
GeneralRe: Prevent the reference being added to new projects ... Pin
nitkapy2k@gmail.com13-Mar-08 5:29
membernitkapy2k@gmail.com13-Mar-08 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 1 Aug 2006
Article Copyright 2006 by Rafael Mizrahi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid