Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting VB.NET Winforms Application to C#

Are there any 'good' resources for porting a VB.NET winforms application to C#? I'm sure there are is software that just translates the code, but I'm looking to refactor the code at the same time. Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, and would further complicate future maintanence. Has anyone here gone through that process, and how did you go about doing it? Did you use a translate/refactor approach? Did you just use the end product to recreate functionality without looking at the current codebase for most of it? What would you (collectively) recommend?

Update:

As I was telling Grauenwolf, keeping it in its current language presents the following issues:

  • Not being able to readily add features. VB.NET isn't a language I'm rock solid in. I do appreciate the irony of learning the language to port it over -- but future maintenance will need to account for someone who doesn't know VB.NET.
  • The rest of the application has been ported to C# (a long time ago, in fact); all features that we'd like to add depend on de-coupling the app (right now it's very tightly coupled). My choices are to either refactor it in a language I'm not too familiar with, or to refactor it in a language I understand.

To anyone who voted the question down, I'm not really sure why you did; the concern isn't whether I should leave it in VB.NET; the concern is what is the future cost of not porting it over now. If I'm going to spare great expense in fixing it, why not go the extra step and make it maintainable for a future programmer?

Author's Note: I hadn't looked at this question in ages, there was a recent response, so I moved my 'answer' into the question and deleted the 'answer' (since it wasn't really an answer).

like image 714
George Stocker Avatar asked Dec 02 '08 20:12

George Stocker


People also ask

Can you convert VB to C?

The VB to C# code converter from the SharpDevelop team is now a standalone extension to Visual Studio. Once installed, you can convert an entire VB.NET project to C# by opening the solution, right clicking the solution node in the Solution Explorer and selecting Convert to C#.

Should I migrate from VB.NET to C#?

NET Core, you need to convert VB.NET to C#. If desktop apps are enough for you and your users, VB.NET works with NET 5, but only to target Windows Forms--not WPF. But if you want to write web apps running on ASP.NET Core, you'll need C#.

Does .NET core support Windows form?

NET Core Released. Today we're happy to announce that the Windows Forms designer for . NET Core projects is now available as a preview in Visual Studio 2019 version 16.6!


6 Answers

Based on my experience working with some large applications that mix VB and C# projects, I would recommend leaving it in VB.NET. If there are problems with the design, then fix them, but converting the whole thing to C# sounds like a messy, unnecessary distraction to me.

The non-stylistic differences between the two languages are very minimal, so it is hard to see a functional need that would force a conversion. (There was an old bug in Visual Studio 2003 that ruled out certain chains of project references that mixed C# and VB projects in specific ways, but that is the only one I have ever run into as a practical obstacle.)

Individual developers certainly tend to have a stylistic preference favoring one or the other, but a full conversion is a lot of work to do for something that amounts to a taste for a different flavor of syntactic sugar.

like image 184
McKenzieG1 Avatar answered Oct 05 '22 18:10

McKenzieG1


If you use something like Reflector or Anakrino, its output is based on the IL rather than the original source. Whether or not it produces code that's any better is open for debate... But you could try it out, anyway. :)

like image 45
GalacticCowboy Avatar answered Oct 05 '22 17:10

GalacticCowboy


Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, and would further complicate future maintanence.

And you think C# won't allow for bad designs?

The problem isn't VB, the problem is the guy who wrote it and the guy refusing to fix it. So take a step back, breath deeply, then start fixing the code. And who knows, you may learn that some of those 'bad design practices' actually make a lot of sense.

like image 22
Jonathan Allen Avatar answered Oct 05 '22 18:10

Jonathan Allen


In my job we've used the translator of developerfusion, but nothing automated (just translate the piece of code or the class, and manually paste the result in the c# project).

Reflector is a great tool, but you can find some problems when reading lambda functions.

For refactoring, the best tool we've tried is Refactor Pro.

like image 20
mapache Avatar answered Oct 05 '22 18:10

mapache


I've used C-Sharpener to do the conversion on some of our apps, but it is far from perfect. It converted roughly 95% of the code, and I ended up refactoring while I was manually fixing the remaining 5%.

like image 28
Whytespot Avatar answered Oct 05 '22 16:10

Whytespot


I have some experiences on VB.NET about 2 years, but now I only use C# in my daily development. Before I tried to use VB.Net to C# to convert my VB.NET code to C#, then I learned from it and also from the book.

like image 39
Samnang Avatar answered Oct 05 '22 18:10

Samnang