Reputation: 1680
I am wondering if there is anyway to create shelvesets (backup) automatically (e.g. every 1 hr) from open solutions from different workspaces in visual studio?
Upvotes: 0
Views: 1283
Reputation: 19459
If you do not want the requirement of having VS and a specific solution open, then there's this script I wrote a long time ago and still gets a lot of use.
<#
.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
}
Upvotes: 0
Reputation: 51073
Here is a extension create a shelveset for the latest version of all pending changes automatically in VS Marketplace.
TFS Auto Shelve for Visual Studio 2015
By default it's 5 minute interval, you could set interval for 60 minutes to meet your needs.
Upvotes: 1