Reputation: 432
My site is written in VB.NET and MVC 3.0 (WebForms) but recently we agreed to migrate to C#, so any new code is written in C# where possible. However, we have limited resources to fully migrate the site across, so much of it is still VB.NET including the main web application project.
I really want to start using Razor views, but as cshtml rather than vbhtml, because my feeling is these will be hard to migrate later. However, I can't see a way of doing this in a VB site. The Web App project won't allow C#, and editing the files would be a nightmare because Intellisense wouldn't work.
The only way I can see for doing this without huge effort is to move all the VB code out of the web project into a separate VB.NET class library, and then create a new C# web project that just contains view files, converting all the inline code in the ASPX files to C#. This would still be a big job though.
Can anyone think of a quicker way?
Upvotes: 2
Views: 1897
Reputation: 71
In 2019 with VS Express 2017 it seems this is possible without any extra software/plugins. After first adding the view (.vbhtml) I renamed the extension to '.cshtml' and translated any view code from VB to C# and it built and run ok.
I tried it after I noticed while developing a VB.net MVC app that the error for a missing view was also looking for a '.cshtml' version of the file.
Upvotes: 0
Reputation: 13706
You can try putting the new Razor files into a separate project, and then using RazorGenerator to compile them into a "View Library" dll which you can then reference from your existing project.
I haven't had much luck with RazorGenerator, but I've only used it for the Template functionality. Your usecase sounds much more like what it's designed for, so you shouldn't have any issues with it.
Upvotes: 2