I commented further up, but thought I would provide my solution with powershell. I'm running this prior to building on my CI server, which happens to be TeamCity, but this could be run locally or on CI.
Param(
[string]$RoleType, #WebRole or WorkerRole
[string]$RoleName, #RoleName from CSDEF
[string]$VMInstanceSizeIn, #Options for VM Size: Small, Medium, Large, ExtraLarge, A6, A7
[string]$csDefPath #File path for ServiceDefinition.csdef for the cloud service project
)
$timeStampFormat = "g"
if ($VMInstanceSizeIn -eq $null) {$VMInstanceSizeIn = "Medium"}
Write-Output "$(Get-Date -f $timeStampFormat) - Setting $RoleType role type with RoleName $RoleName VM Size to $VMInstanceSizeIn in ServiceDefinition.csdef prior to building the package file."
Try
{
$csDefConfig = "$csDefPath\ServiceDefinition.csdef"
Write-Output "$(Get-Date -f $timeStampFormat) - config file location: $csDefConfig"
$csDefConfigXml = [xml](Get-Content $csDefConfig)
Write-Output "$(Get-Date -f $timeStampFormat) - Found ServiceDefinition File at $csDefConfig"
$csDefCurrentXmlNode = $csDefConfigXml.ServiceDefinition.$RoleType | where {$_.Name -eq $RoleName}
$csDefCurrentXmlNode.SetAttribute("vmsize", $VMInstanceSizeIn)
$csDefConfigXml.Save($csDefConfig)
Write-Output "$(Get-Date -f $timeStampFormat) - Successfully saved the ServiceDefinition.csdef file to $csDefConfig"
}
Catch
{
Write-Output "$(Get-Date -f $timeStampFormat) - Powershell Script Error. An error occurred while attempting to modify the ServiceDefinition.csdef file prior to building the solution."
Write-Error -ErrorRecord $_
##teamcity[buildStatus status='FAILURE' ]
exit(1)
}
Please note that at the time this was written I only had to deal with a single web and worker role, so I'm not sure if this was ever tested with multiple worker roles. It should at least be enough to get you started.