Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with .csproj in git

We are working a couple of people on the same project using Visual Studio 2015 and git. This works reasonably well, expect for the .csproj file (the project file). Everytime you add a new file to the project, the .csproj file changes automatically. Hence if two (or more) people adds a file to their local version, it will require a merge from the last one who commits.

Is there a way to avoid this?

Edit: I can fetch, but not pull or commit. If I try to pull, Visual Studio Git wants to merge the remote .csproj file with my local version. It cannot do this automatically however, and every attempt I have made to assist it results in a non-functional .csproj file.

like image 468
Jakob Busk Sørensen Avatar asked Mar 22 '17 13:03

Jakob Busk Sørensen


1 Answers

The .csproj files Visual Studio creates are XML data. Git does not know anything about XML; it tries to merge these as ordinary text files. The result is rarely valid XML, and even more rarely anything resembling functional.

By default, when Git fails to merge these XML files, you will typically get a merge conflict: Git will stop and make you fix up the mess. It's up to you to get this right. Whether VS provides any tools to help, I have no idea (I avoid Windows). See also this description of the problem (this link is in the linked question's answer as well, but I figure I should include it as a direct link here).

Some people try to use union merge to fully automate the merging of these XML files, so that there is no Git conflict. This is not a good idea. See VS 2013 C# and Git: .csproj files don't merge upon pulling for details.

like image 55
torek Avatar answered Nov 01 '22 10:11

torek