ASP.NET Core, quickest approach for testing simple changes?

As I dig more and more into ASP.NET Core using Mercury (for now mostly with Razor pages), one thing I am frustrated by is the slower debugging cycle for ASP.NET Core. When developing WebForm apps, it seemed like the cycle was quicker, particularly for simple changes like HTML and CSS changes that didn’t require a recompile. I’d just edit my ASPX/ASCX file, save it, then switch to the browser and refresh to test. But with ASP.NET Core + Mercury, it seems every change even simple ones like an HTML element class change require a recompile, and then I need to “Start” the project again. I understand this isn’t RemObjects fault, as this is how ASP.NET Core Razor works.

But I also understand that Microsoft has made changes to improve this via “Hot Reload”. To be honest, when I read about this previously, I didn’t understand what the big deal was, mostly because I didn’t realize that EVERY change requires a recompile. (Yes, some of these new ASP.NET core features are cool, but what a step backwards!) But now I get why everyone was so excited about Hot Reload.

My question is: can I speed up the change/debugging cycle using Mercury? My goal is to have as few steps as possible when making simple changes to my code (even if it is just in the *cshtml file and not the .vb file), and then switch to the browser and refresh the page, without having to:

  1. “Stop” the project
  2. Make changes
  3. Build
  4. “Start” the project
  5. Refresh the browser

For me it would be preferable to have this ability in Visual Studio, but even in Water it would be better than nothing.

I did try using dotnet watch like so:
dotnet watch --project <project.elements> run

But I basically get an MSBuild error about a missing RemObjects.Elements.targets file.

Which makes me realize that this probably isn’t going to help me anyway since I assume I’ll want to use EBuild.

Suggestions welcome!

–Avonelle

Yeah, I miss the old “website” model too, where IIS just (re)builds what’s needed, on the fly. I do hope to bring this back with ESP (but eight now that too focuses on a monolithic build — gotta start somewhere).

But as far as I know (and thats not much ;). ASP.NET Core consent have that…

yeah, dotnet will work for projects using Microsoft’s compiler only, i’d expect.

Not sure what (if any) options there are. ASP.NET Core (and Core in general, IMHO) is just a huge step back/in the wrong direction inn general, IMHO… :(.

I seem to recall a controversy some months back about them making hot reload specific to Visual Studio and then they walked it back, but yeah that’s probably related to allowing other tooling to use this, but not necessarily other compilers.

I do see the advantage of generating cleaner HTML than what WebForms provides (at least out of the box), but yeah some of it does seem like a step backward. Certainly my complaint here is an example of that. I should haven’t to recompile to change a CSS style - ridiculous!

–Avonelle

Yeah…

So…having read some more about this, I thought there was perhaps a small chance I could get this Razor Compilation approach working. I followed the instructions under “Enable runtime compilation in an existing project” for my Mercury project - basically you just add the NuGet package and add a call to AddRazorRuntimeCompilation.

When I try to run my project, I get an error in the Program class in Main on the CreateHostBuilder call.

Which seems weird to me - the package has definitely been added, and the project compiles successfully
image

I don’t end up with the Microsoft.AspNetCore.MVC.Razor.RuntimeCompilation.dll in my /bin folder like I do with a test C# project, so I assume that’s the cause of the error. And I assume this too has to do with the difference between the compilers.

I’m including this here mostly so that you can confirm that a) Yep, that isn’t going to work, and b) anyone else trying to solve this issue for Elements will know that this is a blind alley.

–Avonelle

Yeah, I’d not expect any of this to work, because it won’t be aware of our compiler and toolchain. That said, the concrete error is odd, if you could send me the project as is, I’ll try and have a look.

Sure, here you go.
TestRuntimeComp.zip (1.5 MB)

–Avonelle

Set Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation:* to Copy Local, for start. :wink:

With that changed, it runs, and website loads. Ofc, I have no way to know if it does what it should…

Interesting. When I tried to do that, I get this error:
image

So I’m unable to set it to Copy Local.

FYI, this is VS2022 Version 17.2.5

–Avonelle

Here’s what happens with a C# project with this enabled: If I run the project (with or without debugging) so that the start page is loaded in a browser, and then I edit the *cshtml file of the currently showing page and save it, it automatically triggers a recompile, and when that is done, the browser page is automatically refreshed, showing my changes. For doing quick and simple HTML text or styling changes, it is really handy to not have all of these steps: Stop debugging, make the change, build the project, start debugging, reload the page. Instead, I can just make my changes and save.

Even if I could automatically trigger a build every time I save my cshtml, that would be helpful, even if I still had to manually reload my page in the browser when it was done. Glorious!

That being said, I understand that this probably isn’t going to work with Elements. Frankly, I don’t understand the approach they are using - it makes no sense to me that this uses a Nuget package. That’s probably ignorance on my part, but to me this seems like something that requires an IDE/tool feature, not a library you add to your project. Weird.

Anyway, I hope that clarifies things a bit. I appreciate the effort even if this doesn’t ultimately go anywhere.

–Avonelle

Hmm, that seems to be a VS bug, I’ll log, but can you try setting it in Water or manually?

Logged as bugs://E25973.

Hmmmm…I did change the setting manually, and tried it again. Here’s what happens:

  1. The project runs successfully now instead of erroring out.
  2. When I make a change to the *cshtml file and save it, nothing obvious happens in the output window or looking at the bin in the file system.
  3. However, it IS attempting a recompile, because if I try to reload the resource in the browser, now I get this error:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

Previously if I made a change to the cshtml file, it would just ignore the change. So it is trying to react to the change, it just isn’t getting very far, probably because it doesn’t know how to use your compiler (I’m guessing.)

For what it is worth, I tried it again with my test C# project to see if I could observe more closely what happens when I change a file. I was expecting that I would see updated Date modified values for my dll and exe in my /bin, but that does not happen! Instead in the debug window after changing the cshtml file and saving it, I get this output line:

‘TestCSharpProj.exe’ (CoreCLR: clrhost): Loaded ‘ctbjj45m.vo3’.

So I think it is somehow replacing the EXE in memory with the new one. Also maybe I was wrong about this being different from Hot Reload. There is an option in the Output window called “Hot Reload” that gets updated when I save my changes as follows:
image

I did find this write-up of how Jet Brains implemented Hot Reload in their IDE, which discusses the relevant Roslyn APIs that are exposed for implementing Hot Reload. Apparently it calculates a diff of the old and new compilation, which then gets applied to the currently running instance.

Anyway, I assume that leaves us in a similar place to where we started - this isn’t going to work because your compiler is different. In a perfect world, I’d like to see some ability to do this for ASP.NET Core Mercury projects, even if it was just within Water, because I think it would speed up development, especially during those times when you are making a lot of small incrementation style changes trying to get something to look right visually. But I get that it may not be a practical feature for you guys to focus on.

–Avonelle

Are there any details?

Yeah, I don’t see how it could possibly handle this, right now :wink:

As I was reading along, I was just about to say, this might be rising the same feature regular .NET with VC#/VB has in VS where you can make code changes and they get compiled inline. I assume that is what Hot Reload is. We never supported it (and never got requests for it, so given it would be a huge about of effort to do, we never bothered (and probably won’t, TBH).

I’ve attached the complete HTML with the error and the details.

Internal Server Error.zip (8.7 KB)

Yes honestly I can’t tell what the differences are, either. I wish their marketing group would stop renaming features. Ugh.

It is interesting that you never got requests for it. Does that mean I’m lazier than the average programmer LOL? Bottom line, I’m trying to figure out what I can do to make myself as productive as possible. I charge fixed-fee pricing, not time-based, so anything that helps me to push out features/fixes quicker is better for me. Working with new tools, libraries, or languages is always slower initially anyway, and sometimes there is an obvious feature or technique that I’ve missed, so I wanted to make sure I wasn’t skipping something that would make me more productive.

–Avonelle

Maybe :wink: personally I never once missed or even thought about this feature :wink:

I’ll have a look.

Predefined type ‘System.Object’ is not defined or imported

wow. it looks like its somehow just throwing this one .cs file at the VC# compiler (which of course won’t work/help), but without any system references…

bugs://E25973 was closed as fixed. (Copy Local in VS)