简体   繁体   中英

Converting large ASP.NET VB.NET project to C# - incrementally?

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?

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.

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.

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.

try #Develop . I think this the best way to convert ANY .net supported to any .net suppported languages.

Other tools convert only the code but this converts the whole project.

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#.

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.

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.

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.

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.

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

Of course there are freeware converters available as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM