My Issue
I am using Visual Studio Professional 2022 version 17.2.5 and I have a Blazor Server project, targeting .NET 6, where the Hot Reload feature is giving me a headache. This feature works fine in other projects of mine, built entirely the same way.
Problem Description
The Hot Reload feature seems to work only when it comes to c# code-behind. However, in my .razor files, the hot reload does not work. When I make a simple change of text, and hit save, I notice at the bottom of Visual Studio the message:
No code changes were found.
And thus, no Hot Reload. This is not an issue in the other projects of mine, when I make the same changes on them I get the message:
Item(s) SavedCode changes were applied successfully.
And Hot Reload works as intended.
I want to point out, I expect it to function like it does in my other projects by just clicking save or hitting the Hot Reload button. I don't want to have to use dotnet watch --project run and then have to wait for it to recompile every single time.
Settings and what I have tried
I have gone into Tools > Options > Debugging > .NET / C++ Hot Reload and made sure all of those settings were checked.
I have compared the launchSettings.json files of both projects, they look the same.
I have compared the Program.cs files of both projects. Nothing stood out to me that would seem like the cause.
Like I mentioned above, I have tried the dotnet watch run approach and this works. It say's Hot Reload enabled, but for any minor changes to take effect the project gets recompiled - I do not want this.
I have been researching my issue over the passed couple weeks but keep coming up empty handed. Most of the answers on SO seem to be either targeted towards Blazor WASM or they are dealing with issues prior to Hot Reload working out of the box in .NET 6. Though maybe I have missed something.
Edit
I have tried running the project with and without the debugger, no difference.
With the suggestion from Scott Perry, I have tried closing VS and deleting the .vs, bin, and obj folders and then reloading my project. Still nothing.
So, does anyone have any idea what could have gone wrong with this project? Any insight on what I should look into?
Thanks
Since you said your problem seems to be project-specific, have you tried closing Visual Studio, deleting the .vs, bin, and obj folders, then reloading the project? That may help clean the build environment.
I finally got to the bottom of it.
In my .csproj file I had the code below:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>
I'm not sure why I had the <UseRazorSourceGenerator> line in there to begin with... but setting the value to true like in the updated code below solved my Hot Reload issue.
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseRazorSourceGenerator>true</UseRazorSourceGenerator>
</PropertyGroup>
Related
I have (fairly large) C# solution in VS 2019, running with ReSharper. Since a few days - and I can't make out the trigger - the following happens:
I change code, add a breakpoint (not required, but makes the issue show nicely), click "Start" (triggering a build and a run) and the application runs, but using old code.
The breakpoint changes to "broken" after the build, which is quick. And the build log is unbelievably short, without any warnings, but also without errors. It lists that the project I made the change in was successfully rebuilt or at least that the build was started.
I thought I may have this issue, but the code executed is the old.
Is this a caching issue? Can I get better logs somewhere?
Is this (full re-install of VS) the only solution?
EDIT: It appears to be getting worse, by now I have to manually/explicitly rebuild my solution before running (almost) every time. And, if this is any hint: while trying to fix the issue, I deleted the hidden .vs folder (where the. suo files lives) - and it has not been re-created. Shouldn't it have been?
EDIT2: The link from dwcanillas below inspired me to search deeper in my solution folder for any nested .vs folders and, indeed, I found a few - not for every project, but for some. I deleted them all and today so far it appears to be better.
CURRENT SOLUTION (another visual studio voodoo recipe):
Clean top-level solution
Close Visual Studio
Delete all ".vs" folders (hidden, in every solution folder)
Open Visual Studio
Rebuild top-level solution
Observed side-effects: Previously unloaded projects will be loaded again. But there's probably more...
You may have to, though try rebuilding it first, and cleaning the solution as well.
A couple of weeks ago I cleared the NuGet cache in Visual Studio... this broke everything for some time as it would not automatically restore all the NuGet packages for some reason.
After a lot of effort and manually restoring stuff, I have now got most projects in my (quite large) solution working, except one.
I am in the process of moving most of my code from .NETFramework projects, to .NETStandard and the websites to .NETCore, that in itself is a headache and may/may not be related to the problem, but I don't think so.
Anyway, this one project, which is a .NETFramework (4.7.2) web application and references many other projects in my solution, will not build properly.
Each time I build it, I get thousands of stupid errors from MSBuild, see the screenshot (ignore the top 4,they are genuine!). These are all errors which should be warnings, or ignored.
In the Project settings page I do NOT have "treat all warnings as errors" checked - in fact, in an effort to fix this, I have turned warnings off altogether as well.
The weird thing is, that if I build every individual project in the solution first, usually twice, and then build this one with out touching anything else, it then will build and launch in IIS (or publish)
So the site is actually working but something is wrong in MSBuild or VS that is breaking it.
I have tried running a Visual Studio repair, but that made no difference either.
EDIT also, it only does it on one PC, if I load the same solution onto my laptop, it will all build fine.
And from some of the errors, if seems that the you should change the Assembly Name of the SAM project to Sam. It is quite strange. Not sure whether you have install some extra Code Analysis extensions on your current PC but other PCs works well.
So please try the following steps:
Steps
1) disable any third party installed vs extensions under Extensions-->Manage Extensions-->Installed
It needs a restart.
2) run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console
3) close VS, delete .vs hidden folder under the solution folder, every bin and obj folder of the projects under the solution.
Besides, you could use devenv /safemode to start a initial VS without any third party tools to test whether the issue happens.
I have all my references setup to "PackageReference" and it works and builds fine but I don't have intellisense with Razor. I can't move to .netcore, but it builds and runs fine I just lose a lot with intellisense. I guess I can do the "choose" switch in the csproj to point it to DLLs, but what is the bare minimum that I need to get intellisense to run?
All my references setup to "PackageReference"
How do you handle the references like system, system.web?
We should only need to change the format of Hintpath in xx.csproj(assemblies from nuget), and keep other things the same. If this is actually what you did, close vs=>delete the hidden .vs folder in Solution folder=>restart vs and reload the project to check if Intellisense can work now.
In addition: It's not officially supported to migrate asp.net full framework projects from packages.config to PackageReference format. For me, I use this extension in VS2017 to make this job for me, you can give it a try. And there's one discussion about the official support for that migration in DC, you can vote for it and track the latest info there.
I have a Visual Studio 2010 Ultimate C++ project (not managed or .NET). When I press F5 (i.e., start debugging), I want it to save all the files, rebuild those that changed, link the whole thing, and then run. Instead, it appears to use the last build. Thus, when I try to step into a function or something, I get the following error:
Based on my research, I have verified these options, the first three of which are in the Options dialog (can be reached under "Debug->Options and Settings"):
"Projects and Solutions->Build and Run->Only build startup projects and dependencies on Run" is checked. Some research indicated that it should be unchecked, but in my case I actually do only want it to rebuild the startup project. For what it's worth, I've tried unchecking it, with no effect.
"Projects and Solutions->Build and Run->On Run, when projects are out of date:" is set to "Always build".
"Debugging->Edit and Continue->Enable Edit and Continue" is checked, though it's greyed out.
In the Configuration Manager ("Build->Configuration Manager"), all solution configurations and platforms have their "Build" checkbox checked.
I have also tried deleting all Debug and Release directories as well as the .sdf and ipch directory.
For completeness, I suppose I should mention that I'm using precompiled headers, though I kinda doubt it matters.
[EDIT: I should note that it only seems to be one file (a .h file) that's doing it. I tried renaming it and recompiling, and also removing it from the solution and adding it back in, but it didn't work. ]
I was able to bring my solution back into the right state after deleting all .suo and .csproj.user files. Answer led to this solution. Hope this saves someone time.
I fell into this state after installing Ultimate over Professional and running profiling tools.
Once I had similar problem with my C# project and I think I have tried every possible suggestion available on internet but none worked and then this is what I have done:
Created an empty Project
Added startup function to verify that it does not show any error
Imported all my source code manually one by one
So, Yes, it was the solution. You already have done a lot so I would say you can get lucky by trying here and there however having a new project and importing your individual source file would be faster.
Another solution could be that switching the platform. I noticed that when I when to project properties, the new project I had just created had a platform of 'win32' and my other projects in the same solution had it set at x64. After I switched my project to x64, everything worked just fine. This worked for my interop(C,C+, C#) project and hopefully works for other projects as well.
I have successfully resolved it, try the following:
remove all temporary and intellisense files
remove all project from solution and then add them back(most important)
check projects 'Frameworks and References' to ensure they are valid
If there's configured binding of the solution with TFS, when you opening a solution VS asks you:
---------------------------
Microsoft Visual Studio
---------------------------
Go Online
This solution is offline but its associated Team Foundation Server is available.
Would you like to go online with this solution after it has loaded?
---------------------------
Yes No Help
---------------------------
Or alternatively if TFS is not available it proposed the choice to work temporarily offline or remove bindings at all.
Is there a way to suppress these dialogs?
To give you some context. Part of our team is working with TFS directly and other part is working via git-tfs. When working with git-tfs - I don't need online mode at all. So every time I open a solution or reload a project in the solution - I should answer the same things, over and over again. But I couldn't delete bindings as then the people working with TFS directly will lose ability to connect to TFS seamlessly.
Does the connections command in tfpt (it was tweakui in the 2008 tfpt) accomplish what you need? You can mark the server (actually the collection in 2010) as offline for VS.
Buck
VS 2012 doesn't show this dialog, but rather writing some info to output about unavailability of TFS, which is acceptable.
For VS 2010 and VS 2008 the most irritating thing is that sometimes this dialog showed for each project, i.e. if you have 30 project in solution - you have to click 'OK' 30 times at each solution opening. For these I may suppose a partial solution - create a file named "ProjectConfiguration.xml" in the root folder of your solution with this content:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
</Project>
Then, in each *.csproj file, remove all SccXxx elements and add this line (as a first-level XML node, not in the PropertyGroup): <Import Project="$(SolutionDir)ProjectConfigurations.xml" />
After that VS fires the dialog just one time. Moreover, if you, like me, are working with git, you can issue git update-index --assume-unchanged 'ProjectConfigurations.xml' and comment these lines without committing them (assume-unchanged basically commands git to ignore changes even if file is tracked already - here is brief description of this option).
P.S. We also included in these file some other option as well, e.g. <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - it is handled by both VS and MSbuild perfectly.
I don't know a way to suppress these dialogs but you can always make the changes to the solution file to remove the bindings without checking it in to affect other developers. I know this is sometimes annoying when the locally edited (not checked out) file is changed a lot, but that's probably not the case for the solution file.
In my case, what I did was to open up the sln file in a text editor, and looked for "GlobalSection(TeamFoundationVersionControl)" and deleted the section all the way to the corresponding "EndGlobalSection" line. (not the last one, but the one after the first GlobalSection(TeamFoundationVersionControl) line)
I then re-loaded the solution and it no longer asks to connect to TFS (which we do not have... it was used by a contractor house that we hired, and we got the source code with the TFS information).
It was a breeze.