Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ASP.NET (+core) cshtml/vbhtml files #172

Open
GrahamTheCoder opened this issue Aug 27, 2018 · 4 comments
Open

Convert ASP.NET (+core) cshtml/vbhtml files #172

GrahamTheCoder opened this issue Aug 27, 2018 · 4 comments

Comments

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Aug 27, 2018

Related info for aspx is probably relevant here: #175

May be necessary to use things like

Out of scope: ASP Net Classic will not be supported

Background

For each file that currently has an open editor, we receive a whole project object (same file path as the one containing the vbhtml) with a bit of boilerplate and then a projection of each code block in the vbhtml

e.g. About.vbhtml

@Code
    ViewData("Title") = "About" & CStr(1)
End Code

<main aria-labelledby="title">
    <h2 id="title">@ViewData("Title").</h2><h3 id="title">@ViewData("Title2").</h3>
    <h3>@ViewData("Message")</h3>

    <p>Use this area to provide additional information.</p>
</main>

About.vbhtml.__projection.g.vb:

#ExternalSource("C:\Users\gph77\source\repos\CodeConverterTests\ExampleVbHtml\Views\Home\About.vbhtml",1)
     
    Me.ViewData("Title") = "About" & CStr(1)


#End ExternalSource

#ExternalSource("C:\Users\gph77\source\repos\CodeConverterTests\ExampleVbHtml\Views\Home\About.vbhtml",2)
              Global.ASP._Page_Views_Home_About_vbhtml.__o = Me.ViewData("Title")


#End ExternalSource

#ExternalSource("C:\Users\gph77\source\repos\CodeConverterTests\ExampleVbHtml\Views\Home\About.vbhtml",3)
                                                     Global.ASP._Page_Views_Home_About_vbhtml.__o = Me.ViewData("Title2")


#End ExternalSource

#ExternalSource("C:\Users\gph77\source\repos\CodeConverterTests\ExampleVbHtml\Views\Home\About.vbhtml",4)
   Global.ASP._Page_Views_Home_About_vbhtml.__o = Me.ViewData("Message")

So we need:

  • A method to get the syntax tree (even if it's as hacky as code to open a bunch of editor windows...but preferably not all at once)
    • Using the mechanism the dotnet build process uses to get all the vbhtml projects would be much preferable to forcing editors to open! Most promising: RazorSourceDocument.Create, RazoreCodeDocument.Create, then try to get a syntax tree and visit things like RazorDirectiveSyntax
  • A method to identify code blocks in the vbhtml and create a version with each part of the converted code overwriting it
  • Nice to have: To update any file name references like: Layout = "~/Views/Shared/_Layout.vbhtml"
    • Visual Studio has code to parse these and know they are paths in the project since ctrl+click goes to them. That code may well be closed source

Using internals

Given a bunch of internal interfaces, this may be a good time to try out the new way of accessing such things (with appropriate guards of course): https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute?view=net-8.0#examples

Side note

There's a snippet here which tells us how we should be getting the right one of these projects normally (currently it just grabs the first!)
https://github.com/dotnet/roslyn/blob/e102ec27b9a89b4ee462f93bcd3295a66c439329/src/VisualStudio/Core/Def/Implementation/HierarchyItemToProjectIdMap.cs#L76-L87

@GrahamTheCoder
Copy link
Member Author

GrahamTheCoder commented Mar 11, 2019

A similar solution could probably also cover #219

@camainc
Copy link

camainc commented Jun 13, 2024

Has there been movement on this? We have a huge web application with hundreds of vbhtml files and could use a helping hand.

@GrahamTheCoder GrahamTheCoder changed the title Awaiting user request: Convert ASP.NET (+core) cshtml/vbhtml files. Convert ASP.NET (+core) cshtml/vbhtml files Jun 14, 2024
@GrahamTheCoder
Copy link
Member Author

GrahamTheCoder commented Jun 14, 2024

Just to check I'm looking at the right thing, am I right in thinking it's .net framework 4.8 that's the latest version that supports vbhtml? Is that what you're using?

I've started adding some background information to the issue description. The good news is that it's possible to get at and convert the code itself, the less good news is that it needs a fair amount of surrounding code to be useful on the scale. If you, or anyone else is interested in doing some digging in the roslyn repo for the relevant parts I've mentioned that would be a huge help.

@GrahamTheCoder
Copy link
Member Author

I've got a spike that gets me access to what's needed I think, but it's reflection heavy: #1110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants