Damian
Damian

Reputation: 5561

Convert Visual Basic (.net 1.1) project to C#

I have a pretty old Visual Basic (.net 1.1) project that I'm willing to continue developing now, but not in Visual Basic but C#. Is there any way to convert it to C#? I can think of two options:

  1. Using source code converters available online (but they fail most of the times, and the project is big)
  2. Compiling it and decompiling it to C# (Though I will lose comments and pragma marks)

What is the recomended method to do this conversion?

Upvotes: 1

Views: 604

Answers (3)

phoog
phoog

Reputation: 43046

Having just reread Joel's post that Jon Skeet mentioned, I would say do take his advice. Write a new C# project that references the old VB.NET project, and move code from the old project to the new project bit by bit, one class at a time. Every time you need to modify something, move the related code from the old project to the new project.

This should have some advantages:

  1. Old code that works and doesn't need to be touched can remain untouched.
  2. You don't have the overhead that would be required by a complete rewrite of weeks or months of tedious code translation before you can even run your program.

Upvotes: 0

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

For well-written VB 1.1, the online converters should do a decent job. I would try batch-converting the files of the project and then manually skimming them to look for obvious errors.

Online converters rather tend to choke on features that were introduced in more recent versions of .NET (for good reason – those features result in a much more fundamental code transformation during compilation, i.e. they make the languages more difficult).

/EDIT: But what Jon says has merit: .NET 1.1 is quite different, and in many ways inferior to, modern-day .NET, and an automatic conversion won’t help you adopting modern language and CLR features into the code.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500585

Given that .NET has changed pretty significantly since .NET 1.1 - and in particular, there are lots more libraries etc available which would change how you would approach various tasks - I'd be very tempted to just start again. Given that you'll already be changing .NET version and language, you'd be putting a lot of work in even just to get a direct port... so why not take the experience you learned from the existing project, and invest that into creating a new one?

(I'm aware of Joel's blog post on rewriting, but if you've already decided that you want a pseudo-rewrite by converting it to another language, I think some of that pain is inevitable anyway.)

Upvotes: 3

Related Questions