Razor Not Hot Reloading After .Net Core 6 Upgrade - .net-core

I'm using Rider. After updating our .net Core project to 6, the razor hot reloading stopped working.
When I make a change to my razor file, if I'm running the Rider build configuration, I get this "sources are modified" message.
If I click "Configure in settings", this is what I see.
If I click apply changes, and refresh the page in chrome, I still see the old version of the page without the changes I applied. There's also this little bubble in the bottom right.
I tried running with dotnet run and dotnet watch in the command line, and also tried debugging with Rider.
This worked before the upgrade by running the app both via the Rider configuration and the command line, making the change, then refreshing the page.
I think if I'm reading this issue correctly, this is just a known issue with Rider.

I think I figured it out after writing this up and looking at this answer (different issue though). I upgraded Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation to 6.0.7. I'm still getting the "Sources are modified" pop up, and have to click "Apply changes" to see my changes. It'd be great if they could just be applied automatically. But, this is way better than having to rebuild.

I have added these configs to my launchSettings.json and it worked
{
...
"Watch": {
"commandName": "Executable",
"executablePath": "dotnet",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run"
}
}
It's basically adding an Executable run and JetBrains Rider will added it to the list of profilers to the top and you can use it then. This will refresh the page automatically.

Related

How to automatically reload .NET Core project in Visual Studio 2019

I tried to automatically reload ASP.NET Core project as I do using Angular with Node or NPM.
When I change the code of the .NET Core project and save, I want the web page to be automatically refreshed in the web browser.
run this command in project console
dotnet watch run
same works for visual studio code
From Develop ASP.NET Core apps using a file watcher (for 3.0)
dotnet watch is a tool that runs a .NET Core CLI command when source
files change. For example, a file change can trigger compilation, test
execution, or deployment.
The link above contains a tutorial with two sample projects:
WebApp (an ASP.NET Core web API) and
WebAppTests (unit tests for the web API).
Alternatively, you can also this nuget package for runtime compilation.
I think that dotnet watch should work. See the documentation from the link as there are various options.
Add Microsoft.DotNet.Watcher.Tools to the tools section of the
project.json file
Run dotnet restore
Execute with dotnet watch run
You can use dotnet watch. Viz. Docs
I have created custom lunch profile to make it easyer to run in VS.
"Watch": {
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run",
"launchBrowser": false,
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
According to this requirement, we need to run .net core application just like Angular application, loading the pages and contents automatically without built and manual refresh.
I had done some research and experienced that auto-reloading is not possible in ASP.NET core project. However, we have got the success, in our solution we are using dotnet watch which monitors source files and if a file changes, shuts down the application that it started, rebuilds and publishes the project, and then restarts the application then we just need to refresh page manually in the browser to get the changes which made in application, we don’t require to build or start the project.
Steps to follow to use asp.net watch:
1) Create.Net core application.
2) Open a command Window in your Web project's folder
3) Type dotnet watch run
4) Open your browser and navigate to an API or Page
5) Make a change to source code
6) Save the file
7) Go back to the browser and refresh manually
8) You should see the change reflected
Use dotnet watch to recompile the source code. Use Browser Link with "Browser reload on save" from Visual Studio to reload all your browsers. https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BrowserReloadonSave
One of the tasks automatically created in VS Code environment for a ASP.NET Core project (web, mvc, etc.) is called "watch". To check this, from ".vscode" folder, open the file tasks.json and you will see 3 tasks configuration: "build", "publish" and "watch". By default, "build" is used in launch.json. You can then go in the "configurations" section of launch.json and look for "preLaunchTask", and there, you can change the task to "watch". And that's it. Hot reload will be active when you run your web application.
Regards.
You should think triple before going forward to this option. (1) It is a resource-consuming. As it necessitates auto-build, as pre-operation, of the modified project and sometimes the whole solution. (Imagine a medium to a huge Asp.net solution composed from many projects, get built for each modification performed !! how much time is left for programming ???!!) (2), as you know, the page reload consumes much time for the first launch after a successful build !!... Hence, the time you want to gain from this option you will be wasted multiple, especially CLR-based programming languages (e.g. .NET Core). And finally, (3) your project is expected to be in need to develop test samples that can be injected automatically in the view for a better automation process, imagine how difficult it is!
Instead, try to unit test your solution, and then, any next modification is expected to be superficial and low occurring.
If you disagree with my proposition, I suggest developing a visual-studio extension that better reload the target web page on-build rather than an on-save-changes event. Next, Ctrl + b will do the job!
Where to start?
I have developed a VSIX that watches folders to load automatically specific generated files outside the VS UI. check the source code you will have an idea about the project's files management. it revolves in the EnvDTE API, please have a look in this piece of code.
Also, check the source project from here
Follow the procedure indicated in the Microsoft's page.
Nuget package Microsoft. VisualStudio. Web. BrowserLink
Install NuGet Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
app.UseBrowserLink(); in the startup.cs page on the configure method.
and enter image description here
now when you change something on your code Ctrl + Maj + enter and everything is saved and actualized on your browser.

ASP.NET Core with Angular not updating changes

I have created a new project following this tutorial https://www.youtube.com/watch?v=ytDTkFJOJIE using aspnet core spa templates (angular to be specific).
So when I run "dotnet run" the first time it works fine, it runs the site as to be expected.
Now, when I commit a change, like delete the navbar and the references to it, the "main-server.js" and "main-client.js" don't update, nor does the site in the browser.
What am I doing wrong? If any more info is needed, let me know.
I was facing same issue. Below steps worked for me:
Delete all files from dist folder
run "ng build"
When the application runs, if you still don't see the changes, Empty cache and hard reload the chrome browser (hold browser refresh button for long, and select "Empty cache and hard reload")
It appears to be I had to set the environment variable. Although it might be set on launchSettings.json, you have to run this command
$Env:ASPNETCORE_ENVIRONMENT = "Development"
for it to work properly. Took me since yesterday to find this, hope it helps someone else.
For me the problem was Visual studio had checked in the .js and .js.map files for a few of my .ts components.
Visual Studio also checks in the main-client.js, vendor.js, and vendor.css files by default. Makes sure to either remove these from source control (recommended) or check them out before running.
In my case it failed to update because it was still running under IIS Express. I solved it by changing the profile from "IIS Express" to [project name] (both in the VS task bar and in the project properties under "Debug").
I too faced this problem while i executed my angular 7 with.net core app in IIS express in VS2017,
solved this by building the angular app(clientapp) in cmd by "ng build".
Then, close and reopen the application. so that VS loads the project again.
Now run the app using IIS express.
this worked for me. so give a try.
I have passed trought the same problem.
You have two options:
Delete the "dist" folder(this folder will be recreated everytime
you use 'ng-build')
Make the implementation equals the link below. This implementation
makes the application ignore the dist folder. It will only be used
at production environment.
Implementation

Webforms rebuild and use previous browser instance

VS2013 Upd1, .NET 4.5, Webforms
In the past I have been able to RUN (F5 or run button) my project and do some testing. I have then been able to stop the project (Shift-F5 or stop button). Make some code changes and BUILD the project (F6) and press reload in the browser and see what the changes are. Yes no debugging but I did not have to re RUN the project.
However the above behaviour has changed in that I have to always RUN my project after stopping it instead of reload in the browser. I am sure I have changed a setting somewhere. Can anyone point me in the right direction?
It will be the "Edit and Continue" setting.
Please see the answer to this this similar question

The Breakpoint Will Not Currently Be Hit. No Symbols Have Been Loaded For This Document

I've Googled this particular problem, but cannot seem to find a working solution.
Symptoms: After adding a breakpoint in the codebehind for an aspx page in a web application project, the breakpoint displays in the margin as a hollowed out red circle with an exclamation point enclosed in a yellow triangle in the bottom right of the circle. When mousing over the breakpoint, the message "The breakpoint will not currently be hit. No symbols have been loaded for this document."
Note: I'm trying to hit the breakpoints by "attaching to [a] process", namely w3wp.exe, located on a remote computer.
Things I have tried.
Recompiling other projects in the solution.
Checking to make sure that the configuration for each of the projects and the website in the solution is set to "Debug" on "any pc".
Closing the solution and restarting Visual Studio.
Restarting IIS.
Reattaching to the process (w3wp.exe).
I've been trying to hit the breakpoints using Internet Explorer version 9 and Mozilla FireFox version 4. In each case, the breakpoints are never hit.
Any ideas are welcome! Thanks!
Andrew
If you have more than one solution in your project.
Right click on your solution --> Properties
Set as --> Startup Project
Are you deploying your assemblies to the GAC? If not, copy the .pdb file along with the .dll file, placing both in the same bin directory. The debugger should pick up the symbols automatically.
I run into the same problem and guess what? Just do it: At solution explorer, right click on Project -> Package/Publish Settings UNCHECK "Exclude generated debug symbols"...
Maybe it can't solve your specific problem but certainly it will save another people from suffering.
I can't post a screenshot because I don't have 10 of reputation... :(
Like you guys I lost all day searching on google and stackoverflow and the problem was just that. I realized that when I saw the PDB file in the bin folder ready to be published becoming 0 bytes size when I clicked "publish"...
In my case I was trying to debug an ASP.NET Core app hosted in IIS. I noticed that when I published the app (dotnet publish) the generated web.config had this line:
<aspNetCore processPath=".\MyService.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
I had to attach to MyService.exe rather than w3wp.exe to debug the app even though it was running in IIS.
This error produce by many reason, one solution is : its due to different framework version when you try to attach process. For more details, please visit: https://stackoverflow.com/a/13106908/1218422
I realize that this is an old thread, but the one thing that nobody mentioned was to make sure that debugging is enabled in the web.config file.
I had the same problem, fixed it by switching the debugging method. I was clicking F5 with web project set to startup project (and the "Don't open a page. Wait for a request from an external applicaton" selected in project settings).
When I attached VS debugger manually to the w3wp.exe process using the debug menu it worked.

Why am I unable to Debug my ASP.NET website in Visual Studio?

I used to be able to attach to my w3wp process and Debug my web application, but this is not working anymore. I have no idea what changed to break this. I'm using Visual Studio 2008 SP1. And I'm debugging in IIS, not using ASP.NET's own server (i.e. I don't Run my project, I simply attach to a running process (w3wp).
My breakpoints simply have the "breakpoint will currently not be hit. The source code is different from the original version."
What I have tried:
Did a solution Clean.
Did a solution Rebuild.
Made sure that compilation debug=true in my web.config file.
Deleted the bin folder
Restarted Visual Studio
Restarted IIS
Restarted my Computer
Added a simple Response.Write to ensure that the latest DLL is being used. It is.
Made sure that Debug ASP.NET is checked in my project properties. It is.
Made sure that all my projects are compiled in my build configuration. They are.
But none of these help. I attach to w3wp, but my breakpoints never get hit.
Any ideas?
I had this problem recently and I ended up first making sure Visual Studio was not running at all on the system.
Then went into this folder and deleted all its content:
C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
Check your web.config for
<compilation debug="true">...
When you "Attach to process", the Output window should show you (when showing output from "Debug") all the libraries it's loading, and where it's loading them from - for the dll's in your /bin folder these are usually copied to the \Temporary ASP.NET Files\root\ folder - where are yours being read from? Have you definitely cleared them out from there?
The only other things I can think of:
You've compiled your code in "Release" mode rather than "Debug" (not the web.config) from the Solution Configuration drop-down.
The symbol files (.pdb) are missing from your /bin folder.
On the "Build" tab of the project properties, you are in configuration "Active (Debug)", you haven't check "optimize code"?
If you click "Advanced..." on that tab, what value do you have for "Debug Info"? Is it "full" or "none"?
Responding to comment
You will find it harder to debug successfully if your code compiled in "Release" mode, and you'll often get the "source code is different" message when you've not rebuilt the symbols (.pdb files) after changes - but you say you've done a clean/rebuild, so that should cover that.
Yes, your output window will show all the framework dlls that you're referencing as well as your code - but you should see one file listed in there with the name of each project output - those are the ones to look at.
You don't have some post build event that moves files into the correct directory for your site do you that's silently failing?
I also had this problem, solved it by changing the "Attach to" code type to Automatic on the "Attach To Process" dialog. (Previously I had this set to "Silverlight Code" due to debugging a different process... it can be easy to forget to change this back.)
I know this issue has been open for some time, but I think it is the same as I experienced:
I could not debug my .aspx server side code. I had a working WepApp AnyCPU project and I wanted to link to some x86 dlls, so I created an x86 debug target. Did similar things, rebuilt, stopped the development web server, rebooted, clear temporary files, all to no avail.
Fixed the problem by changing the target folder to bin\ (was bin\x86\Debug).
Are you running any add ins that could be affecting this? Or any tools that apply post build operations to the source code that the DLLs you start debugging with have been modified post build and it actually is correct that it's not the same source code so debugging won't work?
Also have tried resetting VS?
devenv.exe /resetsettings
Edit: if none of the information has aided you here, while painful it might be worth uninstalling and reinstalling VS and SP1. If you go through this and the issue is the same afterwards that atleast assures that the issue lies in either the web.config or the project settings.
Did you check your assembly.cs file with this attribute
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.Default)]
After reflecting a optimized code you will probably get this. So you must remove this to be able to debug again.
I faced the same issue. The w3wp process took a lot of memory and did not want to be reset on web application publishing.
Press Ctrl+Alt+Delete > Go to "Processes" tab > find w3wp process and
kill it. Run the app again (if this is an mvc app, just go to a
related url to automatically recreate w3wp process).
Warnings will disappear after that.
I have tried all the below options in my Visual Studio 2013 Update 4.
Reset IIS
Clean solution and rebuild
Delete the friles from temporary folder
C:\Windows\Microsoft.Net\Framework...\Temporary ASP.NET files
Check whether the compilation tag is debug or not
But none of them worked, here I am listing down the two things which worked for me.
Disabling the "Just My Code" option
Tools ->Options -> Debugging -> General -> Uncheck Enable Just My Code.
Edit the web.config file and save (You can always create a space in any line
in web.config, that will do)
Please be noted that this solution can be Visual Studio version specific, and the both fix worked for me in my Visual Studio 2013 Update 4.
in the "Attach to process" dialog, click the checkbox (near the bottom) for "show processes from all users" and if you see two w3wp.exe processes, try the other one.
One should have a comments/description value of something like T-SQL, managed somethingoranother. This is the one you want.
I have had this problem for a while and found my solution on the MS forum (link below).
Debug Diagnostic Tool was the culprit for me, but I did not have to uninstall it. I had a crash rule set up for the w3wp process and I simply removed that rule and restarted everything.
Microsoft Forum for Unable to attach error
On OpenVMS we just used to:
Compile/Debug then Link/Debug
and that was it! Simples!!
but seriously, make sure the file you have your Debugger.Break line in, has 'Copy always' set in its Properties before re-building
I was using the Visual Studio extension VSCommands to attach the debugger (convenient). However, IIS Express was running, and I guessed it might be interfering. Sure enough, when I closed IIS Express, suddenly I was able to debug again.
Joy ensued.
In my case I had a Console Application the hosted web page in .Net Framework 4.6.1. When I added a Debug to Conditional compilation symbols, it started to work:
Make sure that "Current Page" and not "Don't open a page. Wait for a request from an external application." is checked under Properties->Web->Start Action.
add this code in your .csproj file
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

Resources