Embed C# code within VB application
-
I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?
-
I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?
It's not possible to embed C# within VB.NET source, sadly. You could, however, add any new functionality to a seperate dll. Your VB.NET code can easily call your C# code and vice-versa. FYI, there's lots of programs out there, including some free ones, that automatically convert C# to VB and vice-versa. I suggest doing a google search if you're interested in that. #include "witty_sig.h"
-
I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now. I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?
As Judah said, you could can easily communicate with both because they do compile to IL (this is the fundamental principal of the CLI). A single compiler can't handle both, though. If you want to maintain a single DLL with this, however, there is a way (though VS.NET 2002 and 2003 won't be any help). You can compile either the VB.NET or C# source to a module using the command-line compiler and passing the switch
/t:module
. When you compile the other language source, you can embed this module into your assembly using/addmodule:_filename_
on the command line, along with the rest of the params (like/t:dll
). Your assembly now contains two modules that define the IL. Consumers of your assembly won't know the difference (unless they used a disassembler, but that really doesn't matter).Microsoft MVP, Visual C# My Articles