运行时
tf proxy /configure
从命令行,tfs根据TFS服务器中设置的AD站点设置代理设置。
如果在第一次运行Visual Studio之前完成此操作,则默认情况下VS会显示这些值。但是,如果重新运行该命令,则Visual Studio不会使用新值进行更新。
我想给我的开发人员一个批处理文件,为他们当前所在的办公室配置他们的代理设置。这样他们可以在不同的办公室或者他们正在远程工作时轻松设置值。
我写了以下内容:
@echo off
set TFDIR=%vs120comnTools%..\IDE
set Path=%Path%;%TFDIR%
tf proxy /enabled:false
echo[
echo Configuring Proxy
tf proxy /configure /collection:[MyUrl]
PAUSE
如果我运行它,它似乎加载了正确的设置,tf proxy
命令返回适当的值。但是,当我打开Visual Studio并转到Tools>>选项>>源控制>> Team Foundation Server,代理设置保留在我手动设置的最后一个值。
有没有办法让批处理文件更新visual studio设置。
更新
感谢下面的Vickys回答,我意识到问题不是相当我认为的那样。
当我运行tf.exe时,它正在更新托管exe的Visual Studio安装的TFS代理设置(即我使用路径的那个)。但是,它不更新其他安装的Visual Studio安装的代理配置。
由于我不想为所有已安装的版本运行该命令,因此我正在寻找一种方法来使它从一个命令更新它们。
答案 0 :(得分:1)
感谢Vickys answer,我已经确定tf.exe
将更新托管它的IDE的TFS设置。例如如果您正在运行/14.0/Common7/IDE/tf.exe
,它将更新Visual Studio 2015的设置。但是,它不会更新2013年,2012年等。
我编写了以下powershell脚本,它将更新其他实例。您需要使用适合TFS集合的URL更新[MyUrl]值
#TODO: Replace [MyUrl] With the collection Url
#Add New Versions to this list when new versions of VS are released
$VsVersionsToDisable = "10.0", "11.0", "12.0", "14.0"
[System.Collections.ArrayList]$VsVersions = $VsVersionsToDisable
[String]$VsProxyVersionToUse = ""
#Find the Highest installed VS Version, and use it for the TFS.exe Command.
foreach ($version in $VsVersions | Sort-Object -Descending)
{
$keyPath = "HKCU:\Software\Microsoft\VisualStudio\$version`_Config"
If (Test-Path $keyPath)
{
$aliasPath = Get-ItemProperty -Path $keyPath | Select-Object `
-ExpandProperty InstallDir
$proxyPath = Join-Path $aliasPath "tf.exe"
set-alias proxyTF $proxyPath
#Remove the VS Version we're using from the array
#the command will auto-set this value, so we don't need to manually set it.
$VsVersions.Remove($version)
$VsProxyVersionToUse = $version
break
}
}
#Gets the last Check time from the Auto-Configuration, to update the other
#versions
function Get-ProxyLastCheckTime()
{
return Get-ItemProperty `
"HKCU:\Software\Microsoft\VisualStudio\$VsProxyVersionToUse\TeamFoundation\SourceControl\Proxy" `
| Select-Object -ExpandProperty LastCheckTime
}
#For each installed version, updates the proxy settings.
function Set-VSIDEConfig
(
[String]
[Parameter(Mandatory=$true)]
$proxyUrl
)
{
$lastCheckTime = Get-ProxyLastCheckTime
foreach ($version in $VsVersions)
{
Push-Location
$regPath = "HKCU:\Software\Microsoft\VisualStudio\$version\TeamFoundation\SourceControl\Proxy"
if (Test-Path $regPath)
{
Write-Output "Updating Proxy IDE Settings for VS $version"
Set-Location $regPath
Set-ItemProperty . Enabled $true
Set-ItemProperty . Url $proxyUrl
Set-ItemProperty . AutoConfigured $true
Set-ItemProperty . LastCheckTime $lastCheckTime
Set-ItemProperty . LastConfigureTime $lastCheckTime
}
Pop-Location
}
}
#Disables the Current proxy Settings.
function Disable-VSIDEConfig()
{
foreach ($version in $VsVersionsToDisable)
{
Push-Location
$regPath = "HKCU:\Software\Microsoft\VisualStudio\$version\TeamFoundation\SourceControl\Proxy"
if (Test-Path $regPath)
{
Write-Output "Disabling Proxy IDE Settings for VS $version"
Set-Location $regPath
Set-ItemProperty . Enabled $false
}
Pop-Location
}
Write-Output ""
}
#Process the response from the Proxy command.
function Process-ProxyResult
(
[String[]]
[Parameter(Mandatory=$true)]
$result
)
{
$resultUrl = $result | Select -Last 1
if ($resultUrl -match "Successfully configured proxy (?<content>.*)\.")
{
$url = $matches["content"].Trim()
#Update the IDE Settings with the new proxy
Set-VSIDEConfig $url
}
Write-Output ""
}
#Run the TFS Proxy Setup.
function Set-TFSProxy()
{
#First, Disable the proxy settings
proxyTF proxy /enabled:$false
Disable-VSIDEConfig
Write-Output "Getting Proxy data from Team02"
#TODO: Replace [MyUrl] With the collection Url
$output = proxyTF proxy /configure /collection:[MyUrl] 2>&1
Write-Output $output
Write-Output ""
Process-ProxyResult $output
}
#Run it by default.
Set-TFSProxy