Click here to Skip to main content
Licence CPOL
First Posted 26 Jul 2006
Views 58,436
Bookmarked 18 times

Compile VB.NET code without Microsoft.VisualBasic.dll

By | 1 Aug 2006 | Article
Compile VB.NET code without an implicit reference to Microsoft.VisualBasic.dll.

Introduction

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.

Background

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.

License

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

Member

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 -
http://rafaelmizrahi.blogspot.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
NewsMicrosoft now released this feature in VB9 ORCAS PinmemberRafael Mizrahi0:37 12 Jun '07  
Questionwhat happen when I use DirListBox in c# PinmemberDo.It1:00 11 Apr '07  
GeneralYou people need to calm down [modified] PinmemberLuharVB7:01 25 Jan '07  
AnswerRe: You people need to calm down PinmemberRafael Mizrahi7:26 25 Jan '07  
Newsnovbruntimeref compiler option PinmemberRafael Mizrahi0:10 4 Aug '06  
GeneralWrong reason Pinmemberjwelch24:42 3 Aug '06  
QuestionWhy? Pinmemberjwelch24:10 1 Aug '06  
GeneralRe: Why? PinmemberAnthony Missico9:01 3 Aug '06  
AnswerRe: Why? [modified] PinmemberMichel Posseth22:51 1 Aug '06  
You are right
 
The person who wrote this article is totally wrong with his arguments
 
i invite him to tell his ferry tale here
 
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.vb&lang=en&cr=US[^]
 
The Microsoft.VisualBasic.dll has nothing to do with Visual Basic 6
 
This hole article is unnecesary
if you are a VB programmer who wants to code without VB syntax well ( i wonder what you do in the VB IDE then just code in C++ or C# or whatever )
 
Wake up ! the visual basic namespace is nothing more as a framework wrapper some of the methods you find there are more efficient as writing it all out in framework code the methods are just shortcuts in the framework
 
simple example ? len() does the same as string.length however it will not raise an error if the string was not initialized but simply returns zero and so i can dig up several examples ,,,
 

It is all a mather of preference , but as i said we are talking about native VB syntax if you do not want to code in VB then Code in another language , but do not tell people to criple there VB
VB is a RAD removing the Microsoft.VisualBasic.dll will make VB a C# / C++ etc etc
 

my personal opinion is that the advantage of the framework is that a vb progger can also choose to use pure framework code if he does not need the additional checks that code in the Visual basic namespace performs to speed up code execution

 
p.s.
 
You can remove the vb namespace under project , properties , references ( the namespace box )
result is C# without the curly braces and weird variabel declaration
 

 
regards
 
Michel Posseth [MCP]
 

-- modified at 6:18 Wednesday 2nd August, 2006
General[Message Deleted] PinmemberRafael Mizrahi23:07 1 Aug '06  
GeneralRe: Why? PinmemberMichel Posseth23:36 1 Aug '06  
GeneralRe: Why? [modified] PinmemberAnthony Missico9:06 3 Aug '06  
GeneralPrevent the reference being added to new projects ... PinmemberDuncan Edwards Jones6:47 28 Jul '06  
GeneralRe: Prevent the reference being added to new projects ... Pinmemberdfinger1:38 1 Aug '06  
GeneralRe: Prevent the reference being added to new projects ... PinmemberDaniel Finger2:28 1 Aug '06  
GeneralRe: Prevent the reference being added to new projects ... Pinmemberlpellerin3:37 6 Sep '06  
GeneralRe: Prevent the reference being added to new projects ... PinmemberRafael Mizrahi21:04 6 Sep '06  
QuestionRe: Prevent the reference being added to new projects ... Pinmembernitkapy2k@gmail.com21:42 12 Mar '08  
GeneralRe: Prevent the reference being added to new projects ... PinmemberRafael Mizrahi22:01 12 Mar '08  
GeneralRe: Prevent the reference being added to new projects ... Pinmembernitkapy2k@gmail.com4:29 13 Mar '08  

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.

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