Rider Hot Reload for .NET Core WebApi not working - ide

So basically If I make a code change, the C# application won't restart, I had to rerun manually the build project everytime I add a new line of code. This is on JetBrains Rider IDE.
So as they say in documentation, this feature is enable by default if I'm using .NET Core 6+ (which I do), I also have all checks
Any ideas so far? Or am I missing something and I need to rerun everytime I change something on the Controller with this IDE?

Related

Razor Runtime Compilation breaks Hot Reload and therefore debugging in ASP.NET

Nomenclature
This question is about three related subjects that allow the developer to introduce code changes in a running application without having to rebuild and restart said application:
Edit and Continue: Visual Studio's functionality to modify assemblies that are being debugged. You can edit managed code while on a breakpoint (within some constraints), and it'll magically be applied to the debuggee.
Hot Reload: introduced with Visual Studio 2022, kind of like Edit and Continue, enabling runtime recompilation of managed code without having to be paused on a breakpoint or even having a debugger running to begin with.
Razor Runtime Compilation: editing Razor views of a running application, by recompiling them on save of a .cshtml file.
Setup
Visual Studio 2022 (17.4.4)
.NET 7 (SDK: 7.0.102) or 6 (SDK: 6.0.403)
NuGet: Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
The problems described below also occur on combinations of earlier versions of those components. Then:
Start Visual Studio 2022
Create an ASP.NET Core Web App running on .NET 6 or 7
Add the NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
Change the generated Program.cs code to the following to add Razor Runtime Compilation:
// Add services to the container.
var mvcBuilder = builder.Services.AddRazorPages();
#if DEBUG
mvcBuilder.AddRazorRuntimeCompilation();
#endif
Reproduction
Now set a breakpoint in any view, Index.cshtml would be fine, and run the application.
As soon as the breakpoint is hit, change some Razor code. Or don't, the issues trigger from just having (multiple?) .cshtml files open as well.
Then hit Ctrl+S and F5 to apply your changes and continue running your application, and tada.wav:
Hot Reload can't automatically apply your changes. The app needs to be rebuilt to apply updates.
Alternatively, change some code in the code behind (.cshtml.cs). Now you will get random NullReferenceExceptions or ExecutionEngineExceptions when continuing.
Workaround
Close all .cshtml files before starting a debug session.
Questions
Is it possible to:
Get some confirmation that I'm not the only one that encounters this?
Have "Edit and Continue" without "Hot reload"? The settings for those seem to have been combined, it's either all or nothing.
Make this (editing Razor files and C# code while debugging) work without getting these dreaded errors?
How can I get Microsoft to set the Cancel key (Esc) to the Continue Editing button?
It would appear that not having Razor Runtime Compilation (Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation) installed in the affected project largely mitigates this error (though the runtime still throws the occasional NullReferenceException/ExecutionEngineException while trying to reproduce the issue do my work).
As Hot Reload will also recompile your Razor views, simply uninstall the RuntimeCompilation package and you should get fewer errors.
Edit: this is not entirely true, the error popup still gets shown, albeit less frequently.
Things to try when Hot Reload won't work:
1.) Check the 'Hot Reload' output window and Error List for clues to why hot reload failed. For instance I found an error about having a 'COR_ENABLE_PROFILING' environment variable in the error list after getting the usual dialog. This appeared in the VS2022 17.5 Preview 6.0 and I'm not sure if it was there before.
2.) Make sure COR_ENABLE_PROFILING is disabled in your environment variables.
3.) Search the entire project for RuntimeCompilation (could appear in web.config, launch properties, packages) and remove them.
4.) Disable 'Native Code' debugging in your debugging profile.
5.) Restart your PC and check again

Changes in local framework are not updated in my project

I'm actually using an internal framework in one of my projects. Now I need to modify some of the code of that framework, however, it looks like the changes are no recognised at all by the project that is using that framework.
After committing some changes in the framework, build it and re-import it in the project and debug them, I can see that lines that I added are not executed at all.
I know this because when I add a breakpoint in the framework in one of the new lines, these are never executed as if they didn't exist.
I've tried to remove the framework from my project and add it again by following the steps of these Stackoverflow answer
I expected that my changes in my framework are recognized/syncronised in the project as they use to do.
Maybe I'm doing something wrong, so it would be really helpful your ideas.
I found that it's necessary to follow the next steps strictly delete to don't have the same problem as I was.
Launch the framework project.
Assign the build type to a generic iOS device. Be sure all the classes are assigned to the Target.
Press the play (build) button.
The framework will appear on your desktop.
In the project that is going to use that framework, be sure to remove all the references related to the previous framework version, then delete it from the folder too.
Add the new framework version to its folder in the project.
Assign the references:
Drag the framework that has just been moved to the project, to the framework folder in Xcode.
Drag the framework, that has just been moved to the project, to Linked Frameworks and Libraries.
This worked for me, so maybe this is helpful for someone.

Is it possible to change .cshtml View and see the changes instantly using .NET Core?

Context
In my .NET Framework 4.x ASP.NET MVC projects, when using the Visual Studio IDE, it was possible to edit a .cshtml view, save, then press ctrl+F5 in the browser and see the change immediately.
This seems to be no longer work in ASP.NET Core applications (using Visual Studio 2019 and .NET Core 3 Preview 5).
Question
Is this feature missing in ASP.NET Core? Is this a preview issue? Or am I missing something?
This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:
Runtime compilation is enabled using the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. To enable runtime compilation, apps must:
Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.
Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:
services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
I've marked Kirk's answer as accepted, but maybe this experience could be useful also.
My goal was a "quick edit (cshtml/css/js/ts) then see" iteration.
No need to add and mod anything... I discovered that .NET Core (3) and VS 2019 is so much faster, so in case if we do not want to debug in VS (which is the scenario in most cases when we are changing cshtml/css/js/ts) there is really great iteration:
Press ctrl+f5 to launch your web app (no debug) in browser
See, test (debug js/ts in Chrome)
Edit your cshtml/css/js/ts
Press ctrl+shift+b to build (fast!)
Switch to your browser and press ctrl+f5 to refresh your page (fast!)
Goto 2

Debug setup for an ASP.NET Core app

Edit: After downgrading to .NET SDK 1.0.4, I can debug my app inside Rider and experience is pretty good.
What is the best way to set up a clean debug configuration for my ASP.NET Core app on Ubuntu in Rider 2017.1?
I want to just click on Debug button and have the tool automatically build the app, host it on some port, and open the url in browser.
Should I just try to use launchSettings.json(as VS automatically creates) or Rider offers something else?
I have .NET Command Line Tools 2.0.0-preview2-006497 installed.
You can't.
Until a new version of Rider with .Net Core support is released, debugging doesn't work.
In fact, you'll see the event log full of messages like this if you try:
12:01 PM .NET Core version problem: .NET Core 2.x is not fully supported. Some features will not work as expected.
(You can still just open a project and hit the play button and it'll run your project; but hitting the debug button doesn't actually work at the moment)
As of the time of writing, testing, nuget restore, project references (ie. between projects in the same solution) and running in debug don't work.
For now it's just a waiting game until the next version of rider comes out with these features in Fall, 2017:
We want to roll out at least two more releases this year: an inevitable bugfix release in a few weeks, and another major release (2017.2) in the Fall. Things that we expect to be addressing include support for MSTest and .NET Core 2.0, as well as releasing an SDK. We’ll certainly be keeping a close eye on your feedback (submitted via the support form, issue tracker or elsewhere) to see what other major issues need to be addressed.

ASP.NET 5 - beta8: no rebuild in background

Before beta8 it was possible to start a Web Application, change some of the code (e. g. the ViewBag.Message of the About-View), save and refresh the browser - voilá, the new Message is displayed without rebuilding the project.
Now when creating a new Web Application with beta8 which uses DNX and Kestrel this seems no longer to work. Any idea why?
Beta8 contains a new library called 'dnx watch' which monitors your project files for changes during execution and automatically rebuilds the project. Install it by running the following from a command prompt:
dnu commands install Microsoft.Dnx.Watcher
Additionally, make sure you've installed the beta8 web tools for Visual Studio.
Finally, make sure you're not running in debug mode as code changes will not reload projects while running with the debugger attached. CTRL+F5 will start your web project without the debugger.
You can read up on this and the other changes in beta8 here:
http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx