Visual Studio is not recognizing git repo - visual-studio

Upon opening my ASP.NET Core project with an existing git repo in Visual Studio 2022, the git repo is not being loaded. However, opening a freshly cloned repo of this project from GitHub works fine. And opening other projects with git repos work fine. What could be the issue?

Had the same issue after upgrading to latest version of VS2019 and had a look at the output from "Source Control - Git", there were messages of a fatal error because of no access and suggesting running the following:
git config --global --add safe.directory path/to/repo
After running it and restarting VS2019 it works OK.

Had the same problem running VS2022 under Win10.
Problem was that the ownership of the file system directory containing the solution and git data had changed to Administrator. After changing the ownership back to my normal windows user account everything worked fine again.

If you run VS 2022 as an Administrator, it should load everything as it should.

In my case the project was cloned in console with Administrator rights. All worked good in console but Visual Studio was not read the .git folder.
Actually folders has enough rights for Authenticated Users group that was assigned for all child objects but Visual Studio still not see .git folder.
Only after change owner of project folder and all child objects to current account Visual Studio seen .git
Steps:
Open Properties of project folder.
On tab Security select button Advanced.
Select tab Owner and button Change.
In List select your account plus check "Replace owner on subcontainers and objects".
Click Apply

I ran into the same problem.
Visual Studio Code and Git bash correctly recognized the repo but not Visual Studio 2022.
I installed the latest version of Git in the system, and the visual studio recognized the git repo correctly.

Related

Visual Studio 2022: System.InvalidOperationException: "git" is not present in PATH

I'm trying to compile the following project:
https://github.com/xoofx/markdig
In Visual Studio 2022, How to resolve the error message:
System.InvalidOperationException: "git" is not present in PATH.
What's the correctly way to install 'git' for visual studio? I thought Visual Studio Already has git installed out of the box, judging by the label "Git" on the menu bar.
Here's a picture of my screen:
Menu: Tools->Command-Line:
Thanks for adding the picture. You need to have git installed. This can be done independently or through visual studio installer.
https://git-scm.com/downloads
It will ask you during installation if you want it to be added to the path - choose yes.
Once you have installed, launch the command window from start menu
and run git command. That should show something like this -
[2]
Once you have git command running from command line it should work from visual studio as well. Essentially VS is trying to launch that command from its shell and failing to find it because you dont have git installed.
VS does come with git installed but you have to choose it in its workloads. You have to go through all available installation options. See the screenshot below from VS 2017 installation workload. You can do this by re-launching your VS installer and selecting the products that you want installed. Since I use most of the things, I dont uncheck anything but that takes close to 50Gig space on the disk - something you want to be aware of.

Visual Studio 2019 doesn't see my git repo

After installing the latest VS update, VS doesn't see my git repo when I open project's folder. It offers me to create a new repo or to clone an existing one but not to open the one I have in folder.
Any ideas why it might be happening?

Visual Studio TFS Git not seeing any changes

I'm not getting something about Visual Studio's Git for TFS.
I cloned a colleague's solution in Git on TFS and started adding code. I then realised that I needed my own branch for the changes I was making, and so following the instructions in Push a new local branch to a remote Git repo and track it too I ran
git checkout -b e4ctim
git push -u origin e4ctim
When I make changes to my code visual studio shows the familiar red-tick icon by the code file to reassure me that the change has triggered the file to be checked out:
And then when I save the file the Visual Studio returns the icon to the blue padlock. I assume that this change from red-tick to blue padlock signifies that the change has been checked-in locally in Git:
But when I look at the history of the modified file, there is none!
I would like to commit my changes locally and sync them with the TFS server.
Visual Studio does not see any changes at all:
From the command line I can see that Git has noticed all of my modifications by running the command
git status
and seeing lots of changes not staged for commit and untracked files.
Looing at the Git book I could use
git add
or more specifically
git add -u .
to stage the files ready for a commit but I'm reluctant to do that as the Develop your app in a Git repository (track, commit) Visual Studio documentation states:
Q: Where is the Git stage?
A: If you are an experienced Git user, you might have noticed that
Visual Studio handles changes differently than the command prompt.
You might have wondered if the Included Changes section contains
your staged changes. In fact, Visual Studio usually bypasses the Git
stage for you. When you commit changes, Visual Studio simultaneously
stages and commits them. The one exception occurs when you add a
file to your Git repository; Visual Studio does stage this kind of
change.
Visual Studio stages and commits changes simultaneously. But why is it not listing any of the modifications I have made to tracked files as changes, and thus letting me commit them?
This is more of a workaround than an explanation, but I found that if I ignored the documentation "when you commit changes, Visual Studio simultaneously stages and commits them" and instead added the modifications to staging with the command
git add -u .
then Visual Studio suddenly became aware of the modifications and let me commit them locally and sync them with the TFS server. Moreover it then put the 'new file' green cross on the files I had added and I found I could do another commit and then another sync to pick up the additions and deletions I had made.
Since then Visual Studio is doing what I would expect: when I make a change to the file the file is listed as changed in the commit window.
I still do not know why Visual Studio failed to pick up the changes until after an initial git add but at least it works now.
I had to add this line to my .gitignore:
[path to project]/node_modules/
Apparently VS2015 was crashing on some very long path in there and would just decide to give up all hope
delete the file myProject\.git\index.lock fixed it in my case.
I had the same probem and I realized the following:
In order to show the changeset, As #dumbledad said, Visual Studio runs the command
git add -u
internally for staging the updates.
If some of the files that you are trying to add to your changeset is open by another process, then the git command gets a permission error. And Visual Studio won't show the changes.
In my case, I had a document in my repo that was open by another application, and that caused Visual Studio not to show the modifications because of the Git permission error. So check if any of the files of your git repository is not open by any other application.
I'm using VS 2015 Update 1 and also meet this problem. Furthermore, at the same time, the VS' output window told me my VC.opendb file under the solution folder is occupied by another program. According to this, I fixed the issue of occupying: add *.VC.opendb and *.VC.db to the .gitignore file. Then everything goes well.
I was having the same issue with Visual Studio Update 3. VS was saving locally but not picking up any changes so I couldn't commit.
I downloaded Git for Windows from https://git-for-windows.github.io/ (thanks #fhilton), opened the Developer Command Prompt and changed directory to C:\Repos\Scheduler (the location of my source code).
I then ran GET ADD -U and received the following error...
error: open("WindowsServices\Scheduler.WindowServices.InstallLog"):
Permission Denied
error: unable to index file
WindowsServices\Scheduler.WindowServices.InstallLog
fatal: updating files failed
As others have said, it looks like the GIT tools in Visual Studio can fail silently, even for the most basic Windows level errors. Worse, it can tell you GIT is fully in sync. Command line is certainly your friend for the time being.
Open View > Output, select 'Source Control - Git' in Show Output from and check for any errors. As others mentioned, any error in Git makes MS Project silently ignore any changes.
I had this problem on a new machine with a fresh install of both VS2013 Update 5 and VS 2015 and it was driving me crazy. Then I found if I installed Git for Windows, the problem went away! https://git-for-windows.github.io/
Then i was trying to make changes but files doesn't get effected...There is a easy solution for this. The major problem is one of your git ignore files ignoring your files..
Open your local repo for instance D://repos, then look file you want
--> D://repos/project1/HomeViewModel.cs
--> Right click on it and click on Git Extentions
--> Choose +Add Files
--> then Force option
--> Click on Addfiles..Here you go you file will be added in changes
Helpful article! Using Git Bash (git add -u) helped me get closer to the cause of the problem. After committing changes previously not shown in Visual Studio, only half-way commit was done because of using a SQL Server Database Project; Apparently, Windows 10 started to add jfm-files in the same folder keeping it open all the time and preventing it from beeing accessed by VS. Solution was to add it to the .gitignore before committing.
See this thread for further information:
Visual Studio 2015 Database Project directory contains a file with extension jfm
In my case my problem was I am using Linux with symbolic links in the path to my projec (cannot tell if windows with symbolic links has the same problem)

Is there any way to release all SVN references after checking out the project?

We are using SVN repository. Please note this is the 1st time I am using it and I have used TFS before.
To get latest code from SVN we do a checkout on the project folder.
After that there is a green checkmark on the locally downloaded folder.
When we try to open a visual studio solution from this folder, we get error loading project due to SVN references. Is there anyway to release the SVN checkout lock or something?
I have resolved this by deleting the SVN reference lines from the Project file by opening it in notepad

NuGet.exe pack gives access to the path is denied

When I try to pack my MVC project (NuGet.exe pack) I get:
NuGet.exe : Access to the path '...' is denied.
This happens to be the case for all files in the content and script folder of my MVC solution. If I remove the readonly flag on all these files NuGet.exe is able to create the NuGet package.
Why do I have to remove the readonly flag? Is there another way?
I'm using TFS which specify the readonly flag on all files under source control.
I am running:
NuGet Version: 1.7.30402.9028
Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel
I'm using the NuGet.exe that you get when you install the NuGet package NuGet.CommandLine which is located at http://nuget.org/packages/NuGet.CommandLine.
Apparently, you need to set ReadOnly=false for the files it accesses
Try running it as administrator.
I ran into this with nuget restore after doing a git clean -fd with VisualStudio open: the packages/ directory was marked for deletion, and while several files were deleted, the packages/ folder itself was not as VisualStudio had the .nupkg files open.
Once I closed VisualStudio and re-ran git clean, it removed the packages/ directory and then nuget was able to restore everthing correctly.
In my case something happened when switching branch in git. Everyone lost execute permissions for Nuget.exe.
This blog post helped me: http://mannysiddiqui.wordpress.com/2013/05/11/nuget-access-is-denied-command-existed-with-code-5/
I was running into a similar problem. I attempted to restart Visual Studio, Run as Administrator (Which I always do), Set the folder attributes to ensure the 'Read-Only' flag was off. Regardless, whatever I did, I still encountered the error "access to the path is denied" when updating my Nu-Get packages.
I was able to fix the issue by updating packages one-by-one. Choosing instead to go through each dependency and updating it. Once the dependency was updated I would choose another, sometimes the same error resulted in which case I would choose another until all my packages were successfully updated.
It appears in my case the Nu-Get packages had to be updated in a particular order.
Hope this helps someone out there
I had this problem and it turned out windows had an update waiting for the next restart. Cleared with no problem after restarting and waiting for the update.
My collegue just got this error, during all "worked on my machine". After some research I found out that the *.nuspec file for some reason wasn't added to the version control.
In order to Restore nuget packages, remove read only permissions from the folder level (for windows). Clean the solution and Build. It will works
In my case it was *.gitattributes in the git repo root recently modified (incorrectly), so git started to checkout nuget.exe on the build server and converted all LF to CRLF inside, making it non-executable.
Run your Visual Studio with administrator rights.

Resources