3

I have inherited a vast web forms application that was auto generated from a classic asp site.

This has left .aspx pages with code embedded into them (No separate codebehind) Some attempts have been made to modernise and so some pages exist with C# code behind. These are mixed in the same folders as the pages with vb.net embedded.

I am having a go at getting the codebase into some kind of shape... and my first step was to move embedded code into a code behind... but I cannot as the compiler is expecting codebehind to be in C# and does not recognise the codebehind files I create (neither will Visual Studio combine the files in its GUI).

What steps can I take here? If I must pull c# files into separate folders I can do that, but I am not sure I could get a separate project working, it would change the deploy steps to much (I think)

The aim is to get the logic under some sort of test framework so I can work on re-factoring and safely making changes.

Loofer
  • 6,841
  • 9
  • 61
  • 102
  • I believe if you open your site as a website in Visual Studio (via "Open Web Site" and pointing for a local folder or IIS virtual directory) - you should be able to compile and run mix-and-matched code. – Yuriy Galanter Nov 14 '14 at 15:54
  • Well I can open it like that... it then fails to build completely! Is there a blog that will help me understand the difference in opening normally or as a website? – Loofer Nov 14 '14 at 16:05
  • I might be wrong but from experience, each project need to have all of it's code files in the same language. aspx files are different because they are compiled when the page is accessed. – the_lotus Nov 14 '14 at 20:33
  • Is it possible to translate the VB code to C# using one of the online utilities? – lurker Nov 15 '14 at 14:00
  • The only to have C# and VB.NET code side by side is to use web site, see http://stackoverflow.com/a/2339827/1314859. – Alexander Manekovskiy Nov 16 '14 at 09:58

2 Answers2

1

This is impossible. When the compiler is building your project it's expecting one language. You either need to leave the VB.Net in the aspx (which is interpreted and not compiled), or move the code behind files for those VB.Net pages into another assembly that is referenced in your main app.

Shriike
  • 1,351
  • 9
  • 20
1

A single project must have a single language. (Folders are pretty much irrelevant, except for making sure you keep your namespaces correct.) But I've successfully created a separate C# project for a VB.Net aspx project with terribly intertwined code-in-the-page, as you are describing. The way I did it, that worked quite well, was to

  1. Create a separate C# project with business logic
  2. Call the C# business logic from the VB aspx pages

Each project compiles into its own assembly (dll), and it is easy to call functions in one project from another. I didn't have trouble (that I remember anyway) with the deployment. And if your project is "vast" and contains many folders, it probably should be broken into separate projects anyway. Good luck! :)

CindyH
  • 2,986
  • 2
  • 24
  • 38