Search code examples
c#gitvisual-studiovisual-studio-2019git-extensions

Reload all Projects after switching branches doesn't Reload Projects


I develop on a large web API that contains eight C# projects. Often, I am switching between branches within our repository to work on different tasks. I use Git Extensions as my tool of choice to work with Git, and whenever I checkout a different branch, Visual Studio will prompt me to reload the projects (if changes are detected). I normally select the "Reload All" button. After doing so, I keep getting errors being caused by what seems like left over changes from the branch I was previously on.

For example, if I am on branchA, which introduces a new file that contains a C# class, reference that class in someway in another already existing file, and then checkout branchB that doesn't contain these changes, Visual Studio will start to produce The type or namespace name 'name' does not exist in the namespace (are you missing an assembly reference?). This also seems to happen the other way around, where if I switch to a branch that introduces new changes not on my previous branch, these errors crop up.

It seems as if the .csproj files for the projects aren't being detected as updated after selecting the "Reload All" button. Evidence of this is that Solution Explorer still shows these files, but with red "X" symbols on them, denoting that the projects expects the file to be present, but it currently is not present on disk. I've made sure that the .csproj files do in fact get updated after changing branches. The only solutions that work for me currently is if I right click on the project(s) and unload then reload them, or if I close the solution/Visual Studio and reopen - both of which are tedious.

I am confident that this was not the behavior previously witnessed in prior versions of Visual Studio. I use to be able to freely switch between branches and not have this happen in the past. Could something be out of sync? How can I resolve this?

This is with Visual Studio 2019 Enterprise (version 16.10.3).


Solution

  • Faced the same problem after updating Visual

    In 16.8 version Microsoft added new Git experience that broke the "reload all" feature.

    You have two ways to work with this:

    1. Go to Tools → Options → Environment → Preview Features. Turn off the option "New Git user experience."

    Preview Setting

    1. Use the Visual studio git panel to checkout (Git → Manage branch).

    Git Panel