在visual studio中自动创建shelveset或使用命令提示符

时间:2017-02-28 07:39:07

标签: visual-studio tfs shelveset

我想知道是否还有从visual studio中不同工作区的开放式解决方案自动创建搁置集(备份)(例如每1小时)?

2 个答案:

答案 0 :(得分:1)

这是一个扩展程序,可以在VS Marketplace中自动为所有待处理更改的最新版本创建一个shelveset。

TFS Auto Shelve for Visual Studio 2015

默认情况下,间隔为5分钟,您可以设置60分钟的间隔以满足您的需求。

答案 1 :(得分:0)

如果你不想要打开VS和特定解决方案的要求,那么我很久以前写的这个脚本仍然有很多用处。

<#
    .DESCRIPTION
    This script will create a shelveset for each workspace it finds in the form "WorkspaceName_dddHHmm"
    (ex. 'MyWorkspace_Mon1300' for monday at 1PM/1300).  It does NOT require Visual Studio to be running.
    
    .NOTE
    The intention is to run this as a Scheduled Task periodically. I run it every hour during my usual working
    time, and an hour before and after. With the naming pattern it uses, this means I have a rolling week of 
    shelvesets that I can refer back to in case of hardware failure, mucking something up, getting work laptop
    confiscated by TSA, etc. Its also good for teams to use for sharing code or to check on the progress of 
    noobs that may not know when to ask for help
#>

$ErrorActionPreference = 'Stop'
$Error.Clear()
Clear-Host


#the collection should be read from somewhere like $HOME\AppData\Roaming\Microsoft\VisualStudio\15.0_f40892c4\Team Explorer\TeamExplorer.config
#but this was easier. This URL is for Azure DevOps, for on premise, use the project collection url you can get from looking at the workitems.
$projectCollectionUrl = "https://yourOrgUrl.visualstudio.com"

try
{

    $vsWherePath = Resolve-Path  "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
    $tfExeRoot = & "$vsWherePath" -latest -products * -requires Microsoft.VisualStudio.TeamExplorer -property installationPath
    $tfExePath = Join-Path $tfExeRoot "\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe" -Resolve
    
    $workspaces = [xml](& $tfExePath vc workspaces /collection:$projectCollectionUrl /format:xml)
    $workspaceFolders = @($workspaces.Workspaces.Workspace.Folders.WorkingFolder.local)

    $currentDate = (Get-Date).ToString("ddd_HHmm")
    
    foreach($workspace in $Workspaces.Workspaces.Workspace)
    {
        $workspaceFolder = $workspace.Folders.WorkingFolder.local | Select-Object -First 1
        if (-Not (Test-Path $workspaceFolder)) 
        {
            Write-Host "There is no workspace folder at $workspaceFolder" -ForegroundColor Red
            continue
        }
    
        Set-Location $workspaceFolder
        try
        {
            $shelveSetName = "AutoShelve_$($workspace.Name)_$currentDate"

            & "$tfExePath" shelve $shelveSetName /noprompt /replace
        }
        catch
        {
            if ($_.Exception.Message -like "*There are no matching pending changes to shelve*")
            {
                Write-Host "There are no pending changes to shelve for workspace $workspaceFolder" -ForegroundColor Yellow
                continue
            }
            throw

        }
    }
}
finally
{
    Set-Location $PSScriptRoot
}