How to configure Visual Studio to use Beyond Compare - visual-studio

I would like to configure Visual Studio to open Beyond Compare by default as the diff tool. How can I do this?

In Visual Studio, go to the Tools menu, select Options, expand Source Control, (In a TFS environment, click Visual Studio Team Foundation Server), and click on the Configure User Tools button.
Click the Add button.
Enter/select the following options for Compare:
Extension: .*
Operation: Compare
Command: C:\Program Files\Beyond Compare 3\BComp.exe (replace with the proper path for your machine, including version number)
Arguments: %1 %2 /title1=%6 /title2=%7
If using Beyond Compare Professional (3-way Merge):
Extension: .*
Operation: Merge
Command: C:\Program Files\Beyond Compare 3\BComp.exe (replace with the proper path for your machine, including version number)
Arguments: %1 %2 %3 %4 /title1=%6 /title2=%7 /title3=%8 /title4=%9
If using Beyond Compare v3/v4 Standard or Beyond Compare v2 (2-way Merge):
Extension: .*
Operation: Merge
Command: C:\Program Files\Beyond Compare 3\BComp.exe (replace with the proper path for your machine, including version number)
Arguments: %1 %2 /savetarget=%4 /title1=%6 /title2=%7
If you use tabs in Beyond Compare
If you run Beyond Compare in tabbed mode, it can get confused when you diff or merge more than one set of files at a time from Visual Studio. To fix this, you can add the argument /solo to the end of the arguments; this ensures each comparison opens in a new window, working around the issue with tabs.

Visual Studio with Git for Windows
If you're using GIT as your source code management system instead of the (fairly dated) TFVC then Visual Studio doesn't have options to configure anything like this.
Instead it (rightly in my opinion) uses the GIT config file's setting. So if you already have GIT setup to use Beyond Compare or any other third party comparison software it will just pick this up and start using it.
If not then just set that up (see here for further and likely more up to date help). The relevant info for setting up Visual Studio with Beyond Compare 4 is:
Open Visual Studio.
Select Options from the Tools menu.
Select Plug-In Settings under the Source Control branch of the left-side tree control.
Select Microsoft Git Provider under Plug-In Settings on the right-hand pane.
Edit the global git config file (location is OS specific for windows it's %HOMEDRIVE%%HOMEPATH%/.gitconfig. See here for info) OR if you want it to be repo specifict then after starting a project in a Git repository, edit the config file in the .git folder in the project folder.
Change the config file to reflect the following changes:
[diff]
tool = bc4
[difftool "bc4"]
cmd = \"C:\\Program Files (x86)\\Beyond Compare 4\\BComp.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
tool = bc4
[mergetool "bc4"]
cmd = \"C:\\Program Files (x86)\\Beyond Compare 4\\BComp.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"
If 64bit installer is used, verify the name of the executable. Mine
was BCompare.exe
[diff]
tool = bc4
[difftool "bc4"]
cmd = \"C:\\Program Files\\Beyond Compare 4\\BCompare.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
tool = bc4
[mergetool "bc4"]
cmd = \"C:\\Program Files\\Beyond Compare 4\\BCompare.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"
Issues: If you create a new project and get VS to create the git repo at
the same time it WILL add a load of overrides to the .git/config file
forcing it to use Visual Studio again (Thanks for that MS!).
SO either create the git repo via another means after the project has been setup
(like via SourceTree or the command line etc...) OR edit the .git/config file
(in the solution folder) and remove any overrides for the above settings.
Thanks to minnow in the comments for bringing my attention to it again.
Note: I keep coming across this but I am using VS with GIT and the
answers aren't correct and although some of the comments mention a URL
with the correct answer it's not clear and if I kept missing it I'm
sure others will so hopefully this will solve that issue.

If you are using the TFS, you can find the more information in diff/merge configuration in Team Foundation - common Command and Argument values
It shows how to configure the following tools:
WinDiff
DiffDoc (for Word files)
WinMerge
Beyond Compare
KDiff3
Araxis
Compare It!
SourceGear DiffMerge
Beyond Compare 3
TortoiseMerge
Visual SlickEdit

I got bored of doing this every 6 months when a new version of Visual Studio comes out, or I move PCs, or a new member joins the team. So, PowerShell:
# .Synopsys
# Sets up Beyond Compare professional as Diff tool for all instances of Visual Studio on this PC
# If you don't use TFS, change the sccProvider as appropriate
[CmdLetBinding()]
param(
$bcPath = 'C:\Program Files (x86)\Beyond Compare 3\BComp.exe',
$sccProvider = 'TeamFoundation'
)
$ErrorActionPreference = 'stop';
$baseKey = 'REGISTRY::\HKCU\Software\Microsoft\VisualStudio\*'
function SetRegKeyProperties($keyPath, [hashtable]$keyProps){
if(!(Test-Path $keyPath)){
Write-Verbose "Creating $keyPath"
# Force required here to recursively create registry path
[void] (new-item $keyPath -Type:Directory -Force);
}
foreach($prop in $keyProps.GetEnumerator()){
Set-ItemProperty -Path:$keyPath -Name:$prop.Key -Value:$prop.Value;
}
}
$configBases = dir $baseKey | ? { $_.PSChildName -match '^\d+\.\d$' }
foreach($item in $configBases){
Write-Host "Configuring $item"
$diffToolsKey = Join-Path $item.PSPath "$sccProvider\SourceControl\DiffTools"
SetRegKeyProperties (Join-path $diffToolsKey '.*\Compare') #{Command=$bcPath;Arguments='%1 %2 /title1=%6 /title2=%7'}
SetRegKeyProperties (Join-path $diffToolsKey '.*\Merge') #{Command=$bcPath;Arguments='%1 %2 %3 %4 /title1=%6 /title2=%7 /title3=%8 /title4=%9'}
}
Works on my machine. YMMV. No warranties, no refunds. VS doesn't appear to cache the key, so takes effect immediately.

In Visual Studio 2008 + , go to the
Tools menu --> select Options
In Options Window --> expand Source Control --> Select Subversion User
Tools --> Select Beyond Compare
and click OK button..

The answer posted by #schellack is perfect for most scenarios, but I wanted Beyond Compare to simulate the '2 Way merge with a result panel' view that Visual Studio uses in its own merge window.
This config hides the middle panel (which is unused in most cases AFAIK).
%1 %2 "" %4 /title1=%6 /title2=%7 /title3="" /title4=%9
With thanks to Morgen

I'm using VS 2017 with projects hosted with Git on visualstudio.com hosting (msdn)
The link above worked for me with the "GITHUB FOR WINDOWS" instructions.
http://www.scootersoftware.com/support.php?zz=kb_vcs#githubwindows
The config file was located where it indicated at "c:\users\username\.gitconfig" and I just changed the BC4's to BC3's for my situation and used the appropriate path:
C:/Program Files (x86)/Beyond Compare 3/bcomp.exe

VS2013 on 64-bit Windows 7 requires these settings:
Tools | Options | Source Control | Jazz Source Control
CHECK THE CHECKBOX Use an external compare tool ... (easy to miss this)
2-Way Compare
Location of Executable: C:\Program Files (x86)\Beyond Compare 3\BCompare.exe
3-Way Conflict Compare
Location of Executable: C:\Program Files (x86)\Beyond Compare 3\BCompare.exe

BComp.exe works in multiple-tabbed scenario as well, so there is no need to add /solo unless you really want separate windows for each file comparison. Tested/verified on Beyond Compare 3 and 4. Moral: use BComp.exe, not BCompare.exe, for VS external compare tool configuration.

I use BC3 for my git diff, but I'd also add vscode to the list of useful git diff tools. Some users prefer vscode over vs ide experience.
Using VS Code for Git Diff
git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"

Can't comment because my reputation score is low.
Here's a waybackmachine link to Fresky's link

Related

MAC OSX, Beyond compare as Perforce's merge tool

As described in the title, I want to config Beyond compare as Perforce merge tool.
reference to the following link
(http://www.scootersoftware.com/support.php?zz=kb_vcs), I tried these steps:
Choose Preferences from the Edit menu.
Switch to the Diff tab.
Change the Default Diff Application option to "Other application".
Enter the path to BComp.exe in the Location edit.
Switch to the Merge tab.
Change the Default merge application to "Other application".
Enter the path to BComp.exe in the Location edit.
In the Arguments edit, enter: %1 %2 %b %r
But it can not work, anyone has successfully configured this?
beyond compare version: 4.0.7.
p4client version: DARWIN90X86_64/2015.1/1227227 (2015/08/27).
The instructions you listed are for Beyond Compare for Windows.
To configure Beyond Compare as the diff and merge tool in Perforce on Mac:
Launch Beyond Compare, go to the Beyond Compare menu and run Install
Command Line Tools.
Diff:
Go to the P4V menu and select Preferences.
Go to the Diff section and select Other application.
Location: /usr/local/bin/bcomp
Arguments: %1 %2
Merge
Go to the P4V menu and select Preferences.
Go to the Merge section and select Other application.
Location: /usr/local/bin/bcomp
Arguments: %1 %2 %b %r
Reference: Using Beyond Compare with Version Control Systems under OS X

Faster way to compare changes made in Changeset for TFS Source Control

IF I have a large changeset and want to be able to compare all changes before checking them in, is there a faster way than manually clicking compare to latest on every file? I have something like 900 files I changed, and that seems veryinefficient. There has to be a way to open all files in compare and be able to click close or ignore on each file one by one.
Best way to compare large changeset vs existing code?
Try this:
Open a Visual Studio Command Prompt (All Programs | Visual studio | Visual Studio Tools | Developer Command Prompt
(this is just a normal command prompt but with some extra env variables set, and with the visual studio tools in your path).
use the cd command to switch directory to the root directory that your project is in on your local disk that you want to compare: example: cd \MyProjects\TheProject
execute this command:
tf folderdiff . $/The/Tfs/Folder/Path/To/Corresponding/ProjectDir/On/Server /recursive /view:different
(there is a space between the "folderdiff" and the ".", and another space between the "." and the $/ The "." just says "use the current local path (you should be sitting on it). Being on the current path also gives the TFS command the context that it needs so that it knows how to connect to your TFS server, and which team project and collection to use.

TFS compare options

Is there an option in TFS to compare while not returning whitespace differences? ie. linebreaks, tabs set differently.
SourceSafe had this option, but I cannot find it in TFS.
Yes.
Tools -> Options -> Source Control -> Visual Studio Team Foundation Server -> Configure Users Tools.. ->
Add "%5 /ignorespace" to the arguments as per this post: Whitespace in Team System Compare Results
[You can run diffmerge /? to see other options]
A somewhat better option (IMO) is to replace the out-of-the-box diff tool with the free SourceGear DiffMerge tool, or with BeyondCompare.
If you opt to use the SourceGear's tool, then the command line options (as of 8/17/2011) for Studio 2010 is:
-caption=%1 -nosplash -ro2 -shex -t1=%6 -t2=%7 %1 %2
For the merge, remove the -ro2 (readonly) option

Compare files on double click in Pending Changes view

Is there a way in visual studio to change the behavior when I double click a file in the 'Pending Changes' view.
The default behavior is, that Visual Studio opens the file in code editor, but I want that it opens the 'Compare'-Dialog with the latest version. (same behavior as in TortoiseSVN)
Do shift + double-click instead.
There is a way to make this permanent so you don't need to shift + double-click: http://www.richard-banks.org/2010/07/how-to-double-click-to-diff-pending.html
Path: HKCU\Software\Microsoft\VisualStudio\<ver>\TeamFoundation\SourceControl\Behavior
Value: DoubleClickOnChange (DWORD)
0 == view as the primary command (default)
1 == compare as primary command
The steps from VS2017 onward are a bit different.
VS 2017 uses its own private registry, which is stored in your AppData folder.
Steps
Close all visual studio instances
Select the HKEY_USERS node, and click File > Load Hive
Open privateregistry.bin which can be found at %UserProfile%\AppData\Local\Microsoft\VisualStudio\15.0_[*some key*]
Provide a key name. Eg VS2017PrivateRegistry
Navigate to the following path and create a new DWORD with value of 1.
Path:HKEY_USERS\VS2017PrivateRegistry\Software\Microsoft\VisualStudio\15.0_[*some key*]\TeamFoundation\SourceControl\Behavior
Value: DoubleClickOnChange (DWORD) 1
Select HKEY_USERS\VS2017PrivateRegistry
Click File > Unload Hive
VS 2017
This PowerShell script should turn this on for the latest installed instance (adapted from Anish's answer)
You'll need to close all VS instances first.
$instanceId = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property instanceId).Trim()
reg.exe load HKLM\VS2017PrivateRegistry $env:LOCALAPPDATA\Microsoft\VisualStudio\15.0_$instanceId\privateregistry.bin
reg.exe add HKLM\VS2017PrivateRegistry\Software\Microsoft\VisualStudio\15.0_$instanceId\TeamFoundation\SourceControl\Behavior /v DoubleClickOnChange /t REG_DWORD /d 1 /f
reg.exe unload HKLM\VS2017PrivateRegistry
VS 2015 or older
This PowerShell command should turn this on for all installed versions:
Set-ItemProperty HKCU:\Software\Microsoft\VisualStudio\*\TeamFoundation\SourceControl\Behavior DoubleClickOnChange 1
VS 2019 And Beyond (hopefully)
Building on Tereza's answer using powershell
Run powershell as adminstrator and close Visual Studio.
(you might have to wait a couple of seconds for VS to release some files)
(if you copy paste make sure to send the last command, or else VS won't start)
$instanceId = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property instanceId).Trim()
$versionMajor = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationVersion).Trim().Substring(0,2)
$year = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property catalog_productLineVersion).Trim()
reg.exe load HKLM\VS$yearPrivateRegistry $env:LOCALAPPDATA\Microsoft\VisualStudio\$versionMajor.0_$instanceId\privateregistry.bin
reg.exe add HKLM\VS$yearPrivateRegistry\Software\Microsoft\VisualStudio\$versionMajor.0_$instanceId\TeamFoundation\SourceControl\Behavior /v DoubleClickOnChange /t REG_DWORD /d 1 /f
reg.exe unload HKLM\VS$yearPrivateRegistry
This attempts to determine the major version as well.
Put this on a .reg file and and double click it, this will make your double click compare instead of opening the file in the pending changes window.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\TeamFoundation\SourceControl\Behavior]
"DoubleClickOnChange"=dword:00000001
Make sure the Visual Studio version is correct.
You could also apply some Visual Studio keyboard short cuts for the various comparison types - Latest, WorkSpace and Previous.
See the following post: Comparison keyboard shortcuts for Pending Changes in TFS
In all versions, you can:
double click for one action
click, then Shift + Double Click to perform the alternate action
In later versions of Visual Studio (including 2019 and 2022), you can also change the default double click action in the git changes window without messing around with registry changes:
Go to the "Git Changes" window
On the line where it says "Changes", click the three dots "..." on the right (immediately to the right of a plus button)
Select the first option. The option will alternate between "Compare File as Default Action" and "Open File as Default Action"
Screenshot
Slight update for 2022, as there doesn't seem to be a vswhere.exe to pull a version number, and it's 64-bit. I haven't looked to see if there's another option to pull that, but for the once-in-an-install task, I'm okay with two steps and a manual copy/paste.
Same close Visual Studio instances and wait at least a few seconds for it to unload the registry, and open a Powershell as admin. Run this first to find your version number.
dir $env:LOCALAPPDATA\Microsoft\VisualStudio\
Then add it to the $version string and run the rest below.
$version = "17.0_[*some key*]"
reg.exe load HKLM\VSPrivateRegistry $env:LOCALAPPDATA\Microsoft\VisualStudio\$version\privateregistry.bin
reg.exe add HKLM\VSPrivateRegistry\Software\Microsoft\VisualStudio\$version\TeamFoundation\SourceControl\Behavior /v DoubleClickOnChange /t REG_DWORD /d 1 /f
reg.exe unload HKLM\VSPrivateRegistry
Maybe this method will be more shelf-stable for future versions, though judging from the history of this page, I shouldn't expect that.

Is there a command line option like devenv.exe /Edit for Sql Server Management Studio

I'm using visual studio's external tools to open .sql scripts in Sql Server Management Studio (SSMS). The problem is, each time I use the external tools command to open a .sql file from visual studio, it opens a new instance of SSMS.
Visual Studio has a switch /Edit that will do this, is there one for SQL Server Management Studio?
Choose to open the file with Explorer[1] instead of SSMS. That way the system will search for any existing instances of SSMS first.
[1] %windir%\explorer.exe
I don't think the problem is with Visual Studio external tool command. Look at SSMS command line options - maybe there is a way to force reusing existing SSMS instance.
The following works for me ( I am SQL Server 2008 though) :
So the real answer I quess is to use cmdow
Edit: After more testing I realized the following :
First open the files with connenction with: ( remove any enters while copying, this is one liner )
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\
Common7\IDE\Ssms.exe" "C:\Users\yordgeor\Desktop\Trigger.sql"
"C:\Users\yordgeor\Desktop\Trigger1.sql" -S ysg -d poc_dev -E -nosplash
In this example it opens two files ( but you could open less of course ; )
after which , No matter how many times I run
cmdow /Run "C:\Users\yordgeor\Desktop\Trigger1.sql"
cmdow /Run "C:\Users\yordgeor\Desktop\Trigger2.sql"
cmdow /Run "C:\Users\yordgeor\Desktop\Trigger3.sql"
it opens the same instance of the Microsoft Sql Server Management Studio with the same connection
you could open at once at the command line many files , but I quess you asked for the upper answer.
So you could find the path to the Ssms.exe by:
cd %ProgramFiles%
dir *ssms.exe /s /b
so the syntax of the command is:
pathToTheExe pathToFile1 pathToFile2 -S serverName -d DatabaseToConnectTo -E (toUseWindowsAuthentication) -nosplash
After 20 seconds of googling I cheated from here:
The correct answer is no. The SSMS has a limited set of options, and although it uses the VS framework, does not support the edit command. This could be an interesting feature to add.
I am assuming you need to open these scripts in SSMS to be able to run them as well, otherwise I would suggest pointing them to Visual Studio directly since it does support syntax highlighting. However it will not solve your problem.
If you associate that file extension with Visual Studio, then VS should open it.
If you're finding that VS starts a new instance every time, then you need to specify the /edit command line option.
Take a look at http://stevedunns.blogspot.com/2009/03/programs-that-launch-or-should-launch.html for more information.

Resources