I have a web project in Visual Studio.
When at work i can start the project in debug mode (F5), and set break points. Edit the Code Behind or asp controls. When pressing F5, this will refresh and my new code will be represented.
At my home computer i can edit, i can press F5, but my changes will not be shown. And the debugger will step through the code like it does not realize that it has come some new code.
Has anyone experienced this before? This is not the first time I have seen this, but i cant for the life of me figure out how to make it refresh....
Any pointers will be welcome :)
Edit:
Could this by any chance have something to do about the project type? Or the compilation of the web project?
I figured out why this worked as it did.
The project type i had chosen for my project was ASP.NET WEb Forms Application. This implies that the project will compile and be run from an DLL file.
To rebuild this everytime there is made a change is not possible, so it doesn't.
I changed the project type and buildt a Web Site instead. This kind of project does not compile into a DLL, but is rather run on the fly from the files that i code. Because of this i can make changes to my files, hit f5 and it will automatically reload with the new content.
Related
I have an ASP.Net Core MVC simple project. When I start it without debugging (Ctrl + F5) and change any .cs File (Controller, for example), save it, and update the page in browser nothing happens. But it should automatically recompile and show changes, that was said in the book that I read.
Why can this happen?
I use Visual Studio 2019, .Net core 2.1.
If I manually close the page, and press start without debugging again it recompile and show changes in browser.
If I change .cshtml files (View) it takes effect as soon as I update the browser Page. So it is problem only with C# classes.
UPD dotnet watch works just fine for that purpose, but author of the book (A.Freeman, Pro ASP.Net core MVC 2 7th edition, chapter 6) did not use it:
Visual Studio supports detecting changes as soon as an HTTP request is received from the browser and recompiling classes automatically. To
see how this works, select Start Without Debugging. Once the browser
displays the application data, make the changes to the Home
controller. Save the changes to the controller class file and reload
the browser window without stopping or restarting the application in
Visual Studio. The HTTP request from the browser will trigger the
compilation process, and the application will be restarted using the
modified controller class
Why does this not work for me?
The book was written for Visual Studio 2017. It works as the book describes in VS 2017.
However, according to this, the auto-rebuild feature has not yet been added to Visual Studio 2019.
Original answer: (which applies when that feature is not available):
The difference is that .cs files are compiled into your project's DLL at compile time. For any new code to take effect, the DLL needs to be updated, which will only happen if you specifically tell it to recompile. This is why, when you deploy your project, you copy over the .dll file and not the .cs files.
However, views (.cshtml files) stay as plain text files and are compiled when you use them. If you edit a .cshtml, it's recompiled the next time the view is used. This is why, when you deploy your project, you do need to copy the .cshtml files.
Visual Studio does have a feature to let you modify .cs files while debugging and have it take effect immediately, but it doesn't support ASP.NET projects. It's called Edit and Continue.
However, you can setup dotnet watch to detect file changes and restart your application. There are instructions on how to do that here: Develop ASP.NET Core apps using a file watcher
I've searched and come across similar topics, but they all relate to ASP.NET core projects.
I have a traditional ASP.NET MVC web app using the .NET 4.6.2 framework.
When I run this project without debugging (CTRL + F5) I am able to see all changes made to html, js, and css files by simply refreshing my browser.
However, if I make a code change to a .cs file and refresh the browser the change is not shown. It obviously needs to be recompiled - if I then manually build the project, and then refresh the browser the latest change made to the .cs file is then visible.
Is there anyway I can make VS/IISExpress detect a code change, which then will automatically force the app to rebuild?
Here is an example of what I would like:
https://youtu.be/yyBijyCI5Sk?t=880
^ He modifies code (c#), saves the file, jumps back to his browser, hits refresh which then forces a recompile for a few seconds and then reveals the changes.
The project in this video is using ASP.NET core, so I guess automatic compilation is a feature of it.
Any ideas how to achieve similar for non-core asp.net projects?
Thanks
I dont know of any way to let browser force VS to rebuild project, however based on video. You could use something like link.
It is an extension which rebuilds your poject on save. So all .cs changes will be visible after save(build).
I dont personaly use it, just know it exists
Hope it helps.
Clear visual studio cache. step3 working fine for me.
Step 1: clear the Component Cache
Close Visual Studio (ensure devenv.exe is not present in the Task Manager)
Delete the %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache directory
Restart Visual Studio.
Step 2: cleanup your user’s temp folder
Delete the %USERPROFILE%\AppData\Local\Temp directory.
If all the above fails. you can try the hard route.
Step 3: delete the contents from the following folders
%USERPROFILE%\AppData\Local\Microsoft\Team Foundation
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio
%USERPROFILE%\AppData\Local\Microsoft\VSCommon
I have a big application which I develop (ASP.NET MVC), it wasn't initially mine and I received it from my client. When I run it via Visual Studio, it takes about 2-3 minutes to launch.
I'm wondering what is going on after pressing F5 button in VS (except copiling and copying dll's, views, content to output folder).
If I had to guess I'd say that you're compiling the cshtml code and that can be very slow in older versions of visual studio.
Check to see if you have
<MvcBuildViews>true</MvcBuildViews>
in your .csproj file.
see this answer
MVC Application is extremely slow to build
I believe every time you launch it from Visual Studio it creates new dll files, hence the waiting. But I could be wrong.
I am trying out ASP.NET 5.0 Visual Studio Community 2015.
I have a standard Web Application and just going through the tutorial to get familiar with ASP.NET 5.0
The tutorial states
"Save the file and, without rebuilding the project, refresh your web browser. You should see the updated text. ASP.NET 5 no longer requires that you manually build your server-side logic before viewing it, making small updates much faster to inspect during development."
http://docs.asp.net/en/latest/tutorials/your-first-aspnet-application.html
I tried it and it is not working for me. I noticed when I save the file the break points are now disabled. When I reload the page it does not show the change. Is there a setting or configuration that I am missing to allow this to happen?
Make sure you start the project without debugging (Ctrl + F5 in VS instead of F5). The compile on the fly doesn't work with a debugger attached
I am having problems debugging my web applications.
When I try to Debug my website I get an error saying:
The system cannot find the specified file
Now when I try to Debug again, there will be no error and it tries to open the page, but it doesn't load because IIS is not on.
And when IIS is on and I press the debug the page loads fine, but it doesn't hit the breakpoints I set.
Also the start button doesn't say "Google Chrome", but just "Start"
I thought this was only with this project, but this also happens in my other ASP.NET MVC Project.
I've tried restarting Visual Studio and my laptop, but that didn't solve it either. I also tried cleaning and rebuilding the solution.
Has anybody experienced this problem before?
Your problem with the Debug button showing "Start" occurs only if you set the Application Startup¹ to:
a WPF project or
a WindowsForms project or
a ClassLibrary project or something like this.
Otherwise, your WebApplication project or solution needs a review. Did you check these files?
If not, check the configurations.
See the Start Action in Web as the image below².
Another tips I can give you is to always Build your project during coding to see if everything is OK and sometimes do a Clean Solution and Rebuild it.
When something is not correct, try restarting your Visual Studio or disabling some extensions.
Also, here are a few questions to help you too:
F5 or Start Debugging Button is Greyed Out for Winform application?
Error while trying to run project: Unable to start program. Cannot find the file specified
Some of the answers even when not accepted can help you clarify why did you get this issue.
Hope this can be useful and I am glad you've solved the problem. Now, try to understand it.
--
You can set the Application Startup project by right-clicking the project in the solution and then click "Set as StartUp project".
To view the Project Properties as shown, right-click the project in the solution and then click "Properties" or select the project in the solution and use the shotcut ALT + ENTER.