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.
Related
I want to know what is the command I should execute in the command window of the visual studio 2013, to change directory to:
C/:Users/user/Documents/Visual Studio 2013/Projects/OutlookAddin/publish/<Most_Recent_Version>/OutlookAddin_TemporaryKey.pfx
What is the command I must execute?
Actually, cd cmd works, but in a bit diff like this:
syntax:
cd /d c: or e: etc..
where /d stands for drive
for instance:
cd /d C/:Users/user/Documents/Visual Studio 2013/Projects/OutlookAddin/publish//OutlookAddin_TemporaryKey.pfx
No need for the single or double quote in this case.
Now to execute any type of files for instance simply add '.\' before the executed one.
syntax:
.\OutlookAddin_TemporaryKey.pfx or .\example.exe what so ever
cd does work. However, keep in mind that if the path you're trying to get to has spaces, you need quotes around it (the path). E.g.:
cd "C:\Program Files\Microsoft Visual Studio 10.0" Also, note that the
"Visual Studio command prompt" that is mentioned in Step 6 is not the
"Visual Studio Command Window" - I think this is where the problem
comes from. The command prompt is a separate executable that you can
start by clicking Start, point to All Programs, point to Microsoft
Visual Studio, point to Visual Studio Tools, and then click Visual
Studio Command Prompt. Alternatively, just search "Visual Studio" in
the search bar in the Start menu, and it should show up
Source: Using the Command Window in Visual Studio
First create a file on CMD (COMMAND PROMPT)
1.cd desktop
2.mkdir filename
3.cd filename
4. code .
(It has to be a space between code and the dot to open up the file in visual studio code)
Note: If you just want to open visual studio, then go to CMD and just type in 'code' without the dot.
How to set the default visual studio command prompt location so that I can go straight to my project's directory instead of using the usual navigation.
For Visual Studio 2017 Command Prompt, you need to set environment variable VSCMD_START_DIR to the directory where you want to end up after the command prompt initializes.
I use this script:
set VSCMD_START_DIR=%1
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
It accepts the directory as the first (and only) argument.
Add it as an external tool to Visual Studio (2008 shown here, should be similar in other versions):
Select "Tools", "External Tools...".
Click Add
Title: &Cmd
Command: cmd.exe
Arguments: /k "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
Initial Directory: $(SolutionDir)
Note the arguments come from the "Visual Studio 2008 Command Prompt" shortcut. Yours may vary.
You can can customize the toolbar and add a button for this command as well using "Tools", "Customize...". Open the Tools menu and locate the last External Tool you created and drag it onto the toolbar.
When you click the button, it will open a command prompt in the current solution's root directory.
In Visual Studio 2013,
Right click on "Developer Command Prompt for VS2013" shortcut (which you can find in the "Common7\Tools\Shortcuts" folder from where you installed your VS2013) and choose "Properties",
Change the: "Start in: " directory to your desired location.
Navigate to the "vcvarsall.bat" file. For me the path is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
Add this line to the bottom of the script:
cd /d "D:\WhereverYouWant"
skol
For Developer Command Prompt for VS 2019 you can set VSCMD_START_DIR environment variable with the following command:
setx VSCMD_START_DIR C:\your-folder
You can put these lines in a batch script (vcvar.bat) located in the directory you want to start with:
#echo off
set VCDIR=%ProgramFiles%\Microsoft Visual Studio 10.0\VC
if not exist "%VCDIR%" set VCDIR=%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC
call "%VCDIR%\bin\vcvars32.bat"
Fire a command prompt in this directory, and call vcvar.bat. You now have the VS environment in the command prompt.
Copy Windows Command Processor from "C:\Windows\System32\cmd.exe" and paste to "C:\Your\Project\Directory\cmd.exe"
Edit Visual Studio Command Prompt shortcut by replacing %comspec% with "C:\Your\Project\Directory\cmd.exe" in the Target field.
So the shortcut's Target should look something like: "C:\Your\Project\Directory\cmd.exe" /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64
this will add a menu entry "my compiler " to each directory giving you access to the command prompt in the directory.
save it as something.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\My Compiler]
[HKEY_CLASSES_ROOT\Directory\shell\My Compiler\command]
#="cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat\""
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
In a serious intiative to migrate all my command line operations to PowerShell, I would like to avoid using the old fashioned command console for anything. However, the Visual Studio Command prompt has various environment variables and path settings not found in the default command prompt. How could I create a 'Visual Studio PowerShell' with those same settings?
You can use for example this script to import Visual Studio command prompt environment, see the examples in the script documentation comments, e.g. for Visual Studio 2010:
Invoke-Environment '"%VS100COMNTOOLS%\vsvars32.bat"'
Having done that in the beginning of a PowerShell session (from your profile or manually), you get what you ask for in this PowerShell session.
Or you can use the solution provided by Keith Hill in this answer.
have a look at PowerConsole
PowerConsole has been incorporated into NuGet http://nuget.codeplex.com/. You get PowerShell inside Visual Studio and a package management system.
I use this script that I call Initialize-VisualStudio.ps1, i call it in my profile with dot source, to set the environment variables need it, in my actual session:
param([switch]$ArquitectureX86)
if($ArquitectureX86)
{ $arq= "x86"}
else
{ $arq="x64"}
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC'
cmd /c "vcvarsall.bat $arq&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])";
}
}
popd
What I do is create a simple cmd batch command script that looks like this:
call "%VS80COMNTOOLS%vsvars32.bat"
powershell
Then I create a shortcut that invokes this through cmd. The shortcut target looks like:
%windir%\System32\cmd.exe /k "SetupPSBuildEnvironment.cmd"
If you want the console to look like the powershell console, just modify the Layout to your liking in the shortcut properties.
First, check the contents of this folder:
C:/ProgramData/Microsoft/VisualStudio/Packages/_Instances/
There'll be another folder in it with a name consisting of hex digits (e.g. 2a7a9ed6, but that will vary for different MSVC versions). I'll refer to it as <instance_id>.
Then run from PS:
Import-Module 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell <instance_id> -DevCmdArguments '-arch=x64'
Or you can create a shortcut with the following target:
<path to your powershell.exe> -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell <instance_id> -DevCmdArguments '-arch=x64'}"
Obviously, drop -arch=x64 if you need x86 toolset.
Works for me on Windows 10 with MS Build Tools 16.9.5 and PowerShell 5.1.19041,7.1.3
Both Visual Studio 2005 and Visual Studio 2008 is installed on my PC, but when I open a .aspx or .master file from Explorer, it opens in 2005. I would like them to open in 2008.
I could change the file associations manually, but there are quite a lot of file extensions to go through.
Is there an easy way to give all the file associations back to 2008?
maybe this:
Options -> Environment -> General -> Restore File Associations
You should be able to do it like this.
First create a text file (assocs) with all your existing settings
assoc | findstr -i VisualStudio > assocs
Next edit this file change 8.0 to 9.0 in cases like:
.vbdproj=VisualStudio.vbdproj.8.0 -> .vbdproj=VisualStudio.vbdproj.9.0
Next save this file and run the following command to create a batch file to alter the settings:
for /f "tokens=1-10 delims==" %i in (assocs.) do #echo assoc %i=%j >> new_assocs.bat
Finally run the batch file:
new_assocs.bat