Click here to Skip to main content
11,412,389 members (67,557 online)
Click here to Skip to main content

Compile VB.NET code without Microsoft.VisualBasic.dll

, 1 Aug 2006 CPOL
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 Smile | :) , 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 -

Comments and Discussions

NewsMicrosoft now released this feature in VB9 ORCAS PinmemberRafael Mizrahi12-Jun-07 1:37 
Questionwhat happen when I use DirListBox in c# PinmemberDo.It11-Apr-07 2:00 
GeneralYou people need to calm down [modified] PinmemberLuharVB25-Jan-07 8:01 
Why is there such hostility towards the author of this article? He offered a solution that some VB programmers, including myself, might find useful.

While some of his reasoning may be off base, the information provided is genuinely useful. If you don't want or need this information, then don't use it. There is no need to bash the author for trying to offer something to the community.

I found this article while trying to figure out how to get Microsoft's XNA Game Studio to work with VB.Net. It appears that one of the main reasons VB.Net can't be used to write XNA games for the Xbox is because of VisualBasic.dll, so there's at least one answer to why this article may be useful.

Thank you Mr. Mizrahi. I appreciate your contribution.

-- modified at 13:06 Thursday 25th January, 2007
AnswerRe: You people need to calm down PinmemberRafael Mizrahi25-Jan-07 8:26 
Newsnovbruntimeref compiler option PinmemberRafael Mizrahi4-Aug-06 1:10 
GeneralWrong reason Pinmemberjwelch23-Aug-06 5:42 
QuestionWhy? Pinmemberjwelch21-Aug-06 5:10 
GeneralRe: Why? PinmemberAnthony Missico3-Aug-06 10:01 
AnswerRe: Why? [modified] PinmemberMichel Posseth1-Aug-06 23:51 
General[Message Deleted] PinmemberRafael Mizrahi2-Aug-06 0:07 
GeneralRe: Why? PinmemberMichel Posseth2-Aug-06 0:36 
GeneralRe: Why? [modified] PinmemberAnthony Missico3-Aug-06 10:06 
GeneralPrevent the reference being added to new projects ... PinmemberDuncan Edwards Jones28-Jul-06 7:47 
GeneralRe: Prevent the reference being added to new projects ... Pinmemberdfinger1-Aug-06 2:38 
GeneralRe: Prevent the reference being added to new projects ... PinmemberDaniel Finger1-Aug-06 3:28 
GeneralRe: Prevent the reference being added to new projects ... Pinmemberlpellerin6-Sep-06 4:37 
GeneralRe: Prevent the reference being added to new projects ... PinmemberRafael Mizrahi6-Sep-06 22:04 
QuestionRe: Prevent the reference being added to new projects ... Pinmembernitkapy2k@gmail.com12-Mar-08 22:42 
GeneralRe: Prevent the reference being added to new projects ... PinmemberRafael Mizrahi12-Mar-08 23:01 
GeneralRe: Prevent the reference being added to new projects ... Pinmembernitkapy2k@gmail.com13-Mar-08 5:29 

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

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

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