How can I get C # and vb.net code in the same ASP.NET Web Forms application?

I inherited a huge web forms application that was automatically generated in a classic asp site.

This left the .aspx pages with code embedded in them (no separate code). Some attempts have been made to modernize, so some pages exist with C # code. They are mixed in the same folders as pages with embedded vb.net.

I'm going to get the code in some form ... and my first step was to move the inline code into the code behind ... but I can't, as the compiler expects the codebehind to be in C # and doesn't recognize the codebehind files I create (neither Visual Studio merges files in a GUI).

What steps can I take here? If I have to pull the C # files into separate folders I can do that, but I'm not sure if I can work on a separate project, it will change the deployment steps significantly (I think)

The goal is to get the logic underneath some test framework so that I can work on re-factoring and making changes safely.

+3


source to share


2 answers


It's impossible. When the compiler builds your project, it expects one language. You either need to leave VB.Net in aspx (which is interpreted and not compiled), or move the code behind the files for these VB.Net pages to a different assembly that is referenced in the main application.



+1


source


One project must have one language. (The folders are pretty much irrelevant, except that you keep your namespaces correctly.) But I have successfully created a separate C # project for an aspx VB.Net project with complex intertwined code in the page as you describe.This is how I do it did, worked well, was

  • Create a separate C # project with business logic
  • Calling C # business logic from aspx VB pages


Each project is compiled into its own assembly (dll) and can be easily called in one project from another. I had no problem (I remember anyway) with the deployment. And if your project is "large" and contains many folders, it should probably be split into separate projects. Good luck! :)

+1


source







All Articles