views:

1826

answers:

9

Was looking for some approaches to incrementally converting an large existing ASP.NET VB.NET project to C# while still being able to deploy it as a single web application (currently deployed on a weekly basis).

My thoughts were to just create a new C# ASP.NET project and slowly move pages over, but I've never attempted to do this and somehow merge it with another ASP.NET project during deployment.

(Clarification: Large ASP.NET VB.NET projects are absolute dogs in the VS IDE...)

Any thoughts?

+2  A: 

A like for like port I take it? I don't really see the point and what you will gain for all the effort. Maybe write any new features or refactor sluggish/bad existing logic/service layers into c# but as for web pages I don't see the 80/20 benefit.

redsquare
Right, we are refactoring and moving code down to presenters, services, etc. But if you've ever worked in the VS IDE with a large ASP.NET VB.NET project before, you know how much VB.NET kills the IDE. So we're looking for a short-term solution to get past the VB.NET impediment.
Joey
Hi,no I have never worked with a vb.net solution, but I cant see how a rewrite to c# is a short-term solution if the site is large.
redsquare
Thanks for the response. I'ma actually not talking about a rewrite. I can use SharpDevelop for the actual conversion one page at a time. I was more wondering about the incremental part as it relates to merging 2 asp.net web projects to be deployed as one. Thanks!
Joey
A: 

It can be done. Well I hope it can be done as I am doing this bit by bit on a legacy ASP.net application. You could just change over 1 Webform at a time. Where you may struggle is that I can't seem to have mixed languages in the app code folder as they are compiled together.

John Nolan
+1  A: 

Keep the old stuff in VB. All new stuff in C#. The transistion might be slow but you will not loss time. On free time, change stuff in C#.

Daok
+4  A: 

Start with the business logic and work your way out to the pages. Encapsulate everything you can into C# libraries that you can add as references to the VB.NET site.

Once you've got all of your backend ported over and tested, you can start doing individual pages, though I would suggest that you not roll out until you've completed all of the conversion.

Wayne
Thanks. That's pretty much the approach we've been taking up until now. But since we do weekly releases to production, I'm not sure the "wait until they're all done before deploying" part would work for us too well.
Joey
A: 

I did this with one project by doing the following:

  1. Create a C# class library
  2. Reference the C# class library from the VB web application
  3. Create the code behind class in the C# library
  4. Update the "Inherits" property in the aspx/ascx file to reference the C# class (this file still exists in the original VB project)

It worked somewhat ok; It's a bit of a pain sometimes in that you now have to browse across multiple projects to view a single page/control, but it did let me do what you are wanting to do.

Chris Shaffer
+1  A: 

You can simply make a new c# class library project in the solution. recode a few classes at a time in here and then replace the vb classes in the main project.

but to be honest I would agree I don't see the benefit unless your trying to learn c# or just really don't like vb or just bored.

Hath
+1  A: 

You are allowed to keep your App_Code Directory with both VB code and C# code in it. So effectively, you could do it very slowly when you have the spare time to convert it.

I currently have both VB.Net and C# code in my App_Code directory and on my spare time I convert to VB.Net code or anytime I have to go back to a page with VB.Net and mess with it I convert it to C#.

Easy Peasy and Microsoft made it even nicer when they allowed you to have both VB.NET and C# on the same app. That was one of the best ideas they could have implemented in the entire app making process.

If you want to add both code directories in your one directory add this to your Web.config

<compilation>
<codeSubDirectories>
    <add directoryName="VB_Code"/>
    <add directoryName="CS_Code"/>
</codeSubDirectories>
</compilation>

And then add a folder named VB_Code and another folder named CS_Code in your App_Code directory. Then throw all you vb/C# code in your folders and your good.

Scott
A: 

If you've got $179 you're done.

Of course there are freeware converters available as well.

Axl
Thanks, but the actual conversion itself is not really the issue. Guess my question title was not all that clear. It's the "incremental" part of the conversion that relates to merging/deployment of the web project that was really what I was wondering about.
Joey
+1  A: 

I've had success pulling in dlls of vb projects with Reflector(it's free) and viewing the code as C#. Local variables don't always translate but you can compare the translation and refactor things as you go.

minty