question

DionMisic-7981 avatar image
0 Votes"
DionMisic-7981 asked ·

How do I use a custom diff tool for specific file types in Visual Studio (with Git)?

Disclaimer: New to this forum, please retag if in the incorrect area of the site. I've also posted this question to StackOverflow for reference: https://stackoverflow.com/questions/66774427/how-do-i-use-a-custom-diff-tool-for-specific-file-types-in-visual-studio-with-g





I want to use a custom diff-tool in Visual Studio (2019) for specific file types, for example, I want to use the default visual studio diff tool for every other file type except for .xls and .xlsx extensions.

My use case is similar to https://stackoverflow.com/questions/20069976/setup-git-diff-for-special-file-types, however, I want to do it in Visual Studio (with git-scm).

~/.gitconfig

[diff "excel"]
    command = <path_to_my_diff_tool_for_xls>

~/.gitattributes

*.xls   diff=excel
*.xlsx  diff=excel


I have tried doing this at a repository-level and at a global-level with no success - Visual Studio just doesn't seem to pickup my diff-tool when I try to compare .xls files. It works successfully when I run git diff in the command-line - just not through the VS GUI.

Is there a reason that Visual Studio doesn't respect my diff-instructions in .gitattributes?




I found that when adding a local .gitattributes file through Visual Studio (Team Explorer > Settings > Repository Settings) it will generate a default, commented attribute file.

Within this file:

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs     diff=csharp


This wording (to me, atleast) implies that VS might not respect these types of entries in the .gitattribute files (besides through command prompt).





note: I am aware that I can override the diff tool, but I only want to use this tool on excel files and I can't find a way to do that like you could in TFS with the Configure User Tools popup.



vs-generalvs-extensions
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TianyuSun-MSFT avatar image
1 Vote"
TianyuSun-MSFT answered ·

Hi @DionMisic-7981 ,

Welcome to Microsoft Q&A forum.

I think you may need to do more, for example create an extension to let the custom diff tool work through VS GUI. As the “note” mentioned if you only change .gitattributes file it will only be used(work) by command line. So the workaround should be try to follow this reply: Visual Studio with Git for Windows which you mentioned “override the diff tool” or try to install and use the existing extensions which have the features that you need from Visual Studio Marketplace.

Best Regards,
Tianyu


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 9 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, thanks for the response & the welcome!

I'll look into creating an extension, however, do you know if there is a reason that .gitattributes doesn't work? Have you come across any other documentation about it?
The tool works when I completely override the difftool as in https://stackoverflow.com/questions/4466238/how-to-configure-visual-studio-to-use-beyond-compare/34944506#34944506 however it is then used for all comparisons which is not ideal as it is only suitable for .xls.

Is there perhaps another way I could assign a diff-tool to a file extension? My current workaround is using a script as a difftool which selects the comparison tool to use, but it is somewhat clunky.

Thanks!

0 Votes 0 ·

Hi @DionMisic-7981 , thanks for your feedback. Did you change to use your custom diff tool when following this link to override the diff tool?

0 Votes 0 ·

Yep, but as I said, doing those instructions will set the default diff-tool (it will always compare using my custom diff tool). My custom diff tool is strictly for excel files - when used on other file-types it will break.

I only want it to run on file extension .xls. You could do this using Configure User Tools in TFS.

0 Votes 0 ·
Show more comments