is it normal that Hot Reload VS 2022 rebuild my project? - visual-studio

I am new in .net core 6 because I just finished migrating my project.
I would like to know if this behavior is normal about the native hot reload in vs 2022.
I am on a .Net Core 6 Web App and when I modify a razor page while i'm running without debugging (ctrl +f5), the whole web project is rebuilt and this results in a reload of the application, which for me is not really a hot reload.
Did I miss something ? Or is it the normal behavior ?

I finally found the issue here, looks like a bug because my project configuration is not named "Debug"

Related

How to avoid to recompile project every time I made a change to a view in .NET Core project?

I am new to .NET Core 6 project using Razor views. One problem I am having now is that, every time I make a minimal change to a page, I need to recompile so that I can see the change in the browser.
I am using IIS Express as the server. That way, I can develop while the server is still running, but there is a thing left to solve, and it is to avoid to recompile the project when I change a view.
I realized if I make a change to a view, change is not seen until I recompile the project.
Any help?
I think what you want is Hot Reload:
Supported ASP.NET Core Scenarios
For ASP.NET Core developers who are targeting .NET 6, there are additional capabilities not available for lower versions of .NET. These capabilities include:
CSHTML: Editing a Razor CSHTML file supports many types of edits.
Browser Refresh: Editing a razor file automatically refreshes the changes in your web browser when debugging. This feature was
previously only available when starting the app without the debugger.
CSS Hot Reload: You can change CSS files while the app is running, and changes are applied immediately to the running app as you type.
No Debugger: You get Hot Reload support when using Visual Studio to start your web app without the debugger (CTRL-F5).
You can enable Hot Reload by going to Tools → Options → Debugging → .NET / C++ Hot Reload:

Hot Reload For CSS Not Working With Blazor WebAssembly Hosted

I noticed the following behaviour in Visual Studio 2022 (version 17.0.0) with a .Net 6.0 Blazor project:
Create a new Blazor WebAssembly project and DO NOT select the 'ASP.NET Core hosted' option.
Run the application without debugging.
Ensure Hot Reload is enabled
Make a change to the CSS. You will notice the browser instantly displays the change without needing a refresh / reload.
Repeat the steps above but this time during step 1 select the 'ASP.NET Core hosted' option. Now the CSS hot reload functionality is not working, even though making a change to the razor page itself does still hot reload (such adding or changing a HTML element).
According to the documentation*, hot reload is supported by WebAssembly when running without a debugger. I can't understand why only the CSS hot reload does not work if the 'ASP.NET Core hosted' option is chosen. The CSS and server appear to be unrelated.
*https://devblogs.microsoft.com/dotnet/update-on-net-hot-reload-progress-and-visual-studio-2022-highlights/
Ok, so this is what I did in order for an existing project (web assembly hosted version) to work with .net hot reload WITHOUT DEBUGGING:
Install Visual Studio 2022.
Download and install latest version of sdk and runtime. You could already have them but just to be safe:
SDK and Runtime
Make sure your solution is targeting .NET 6 or update the existing solution to .net 6. Follow the steps provided here: Update to .NET 6 from .NET 5
Go to Tools -> Options and check everything that is connected to hot reload including the CSS Hot Reload box like this:
Delete .bin and .debug folders from your solution, restart your PC and rebuild the solution after restart.
I was facing this problem while working with blazor server projects with .net 7 and this solution was very usefull for me and solved the problem for hot reloading on updating css files on blazor server projects.
Even you don't need to do refersh for your page.
https://www.nuget.org/packages/Toolbelt.AspNetCore.CssLiveReloader/1.1.4?_src=template
I hope this is useful for you.

ASP.NET Core precompiled views on publish

I've previously created an ASP.NET Core project with .NET Core 2.0 preview 1 and Visual Studio 2017 15.3 preview. Just the default stuff from the project template, no custom code yet. Then I used the Publish command and have everything copied to the directory bin\Release\PublishOutput. All nice and good. 5 MB, can be deployed to the production web server and it works.
Now I've tried the same thing with VS Code and just won't get anywhere. I created the project with dotnet new mvc and opened it in VS Code with code .. After closing and opening it a few times and editing .cs files, I think I've now jumped over all the hurdles that VS Code comes with. I can run the application locally.
But the publishing doesn't quite produce the desired result. I run dotnet publish -c Release manually because VS Code doesn't seem to offer anything here. I get tons of files in bin\Release\netcoreapp2.0, along with a subdirectory called publish. Both have a copy of MySite.dll and MySite.pdb, but no precompiled views DLL. Also, the publish directory has 54 MB of runtime DLLs that weren't required for what Visual Studio gave me.
What is the intended method to publish an ASP.NET Core MVC application with VS Code? Everything is the latest version, downloaded and installed today.
Do I need components from the full Visual Studio to get the complete publishing experience, with all the advertised features?
For the record, I have recently discovered in ASP.NET Core 2.0 preview 2 that this has been resolved. A project created with dotnet new mvc has the MvcRazorCompileOnPublish property set in the csproj file, and dotnet publish does the same as publishing through Visual Studio 2017 (15.3) now.

Visual Studio 2010 gets stuck with solution with MVC3 Razor and Azure

I've a solution with several .dll projects, an Asp.NET MVC3 Razor project and an Cloud project.
If I try to compile the solution with the Cloud project loaded, VS2010 gets stuck in "Buil started".
I have to forcefully close VS2010 killing the process and restart. Then the compiling works good once, the next time it will get stuck again.
If I unload the project and set the mvc project as start-up, everything works (but azure of course).
What could be the problem?
Cheers.
Was it by any chance an ASP.NET MVC project to which you added a CloudService project later on or did you start off with a CloudService from the very beginning?
I was in the former situation and I had no end of problems, like not being able to open property pages or deploying the application. It's not quite your issue, but the following article might help:
http://tomkrueger.wordpress.com/2010/07/27/azure-deployment-issue-after-upgrading-to-visual-studio-2010-and-net-4-0/
As I say, my problems started because I actually added an Azure project to an existing ASP.NET MVC solution and there were some unnecessary settings left over in the web.csproj file.
All I had to do was open web.csproj in notepad and remove all occurrences of the <PlatformTarget> element.
My MVC prjoject was x86 and of course Azure works on x64 only. Even though I had the platform target set up as AnyCPU somehow Azure couldn't quite get along with it.
Maybe cleaning up your project files helps as well.

Visual Studio Keep Session between rebuilds etc

I would like to know if there is a way to keep the session going.
I've got sick of losing my session between rebuilds/builds, if I change too much in my project or submit code to our SVN (tortoise via VisualSVN). I'm developing an ASP.NET MVC project with lots of jQuery.
I would like to do this as I test my project on one screen with Firefox (Firebug wins) and edit on the other in visual studio. As my project has a session system and I would like to be able to develop without having to keep re-logging into my system.
Thanks
Edit:
Visual Studio 2008 Professional with the build in IIS development server.
Windows Vista Business 64bit
I don't think that's possible, given that the application restarts on each build. What you could do though, is add a temporary jQuery post call to the login page, that will run on startup.
$(function() {
$.post('/login/', { username: 'phil', password: 'noonewillguessthis' });
});
That way you'll be logged on to the system "automatically" each time the page loads. Just remember to remove it before you deploy live... ;)
It is not possible, when you rebuild and change the content of your libraries they have to be reloaded into the process space. However, in .Net you can never remove assemblies from an AppDomain once they are loaded. To reload your library the AppDomain needs to be unloaded and loaded again. In addition, if there are any changes to your web.config, it will also unload/reload your AppDomain.
You could use something like pushing session state to SQL server so that the AppDomain recycle doesn't impact you. You can do this with the sessionState element of the web.config file.
I have faced the same problem. I use VS 2015 on a machine. I rebuild/build project and on my first debugging the first generated session is lost. Think i mention about 2 paged project. first page is "Default.aspx", second page is "Home.aspx".
Default.aspx page is loaded first
Session["UserID"] is generated on Default.aspx
Page is redirected to Home.aspx by using Response.Redirect("Home.aspx",false) code.
Session["UserID"] is checked on Home.aspx.cs' s Page_Load function if it is existing or not
Session["UserID"] is not existing.. lost!
Solution:
I have instaled Visual Studio on other machine and I built the project on that machine. As result session missing problem is solved. Publishes are worked well on servers too. Maybe this problem is sourced by Visual Studio configurtions or machine configurations, I am not sure but installing VS may solve the problem.

Resources