Set assembly template for all assembly definitions

I am trying to use powershell to use the TFS API to modify some assembly definitions. I am trying to update the definitions to use a specific assembly template. So far, I have managed to set this assembly template as my default, but I cannot figure out how to update the assembly definitions with this new template.

Any help is appreciated. Here's the script I still have:

$TFS2013_Server = "http://localhost:8080/tfs"
$teamProject = "OOTB_Scrum_2013.2"
$serverPath = "$/OOTB_Scrum_2013.2/BuildProcessTemplates/BuildProcessSource/Templates/Custom Template.xaml"

# VS 2013
$tfsClientVersion = ", Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($TFS2013_Server) 

$tfs.EnsureAuthenticated()
if (!$tfs.HasAuthenticated)
{
Write-Host "Failed to authenticate to TFS"

exit
}
Write-Host "Connected to Team Foundation Server [" $TFS2013_Server "]"

$versionControl =     $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) 
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer]) 

$templates = $buildServer.QueryProcessTemplates($teamProject);

        foreach ($pt in $templates)
        {
            if ($pt.TemplateType -eq "Default")
            {
                Write-Host "Current Template Type: $($pt.TemplateType)"
                #Write-Host "Current Server Path: $($pt.serverPath)"
                $pt.TemplateType = "Custom"
                $pt.Save()

                Write-Host "New Template Type: $($pt.TemplateType)"
                #Write-Host "New Server Path: $($pt.serverPath)"                    
            }
        }

        foreach ($pt in $templates)
        {
            if ($pt.ServerPath -eq $serverPath)
            {
                Write-Host "Template found."
                Write-Host "Changing type for the template to Default."
                $pt.TemplateType = "Default"
                $pt.Save()
                #return
            }

        }


        foreach ($def in $defs)
        {
        Write-Host "Current Server Path: $($def.Process.ServerPath)..." 
        $def.Process.ServerPath = $customBuildTemplate
        $def.Save()

        Write-Host "New Server Path: $($def.Process.ServerPath)..."
        }
+4
source share
1 answer

Your code should be something like this

$templateName = [IO.Path]::GetFileName($newTemplateServerPath)
$processTemplate =
        $Buildserver.QueryProcessTemplates($TeamProject) |
        where { [IO.Path]::GetFileName($_.ServerPath) -eq $templateName }
if (!$processTemplate)
{
    # build process template missing at destination, use default
    $processTemplate =
            $Buildserver.QueryProcessTemplates($TeamProject) |
            where { $_.TemplateType -eq [Microsoft.TeamFoundation.Build.Client.ProcessTemplateType]::Default }
}#if
$buildDefinitionToChange.Process = $processTemplate
$buildDefinitionToChange.Save()
+2
source

Source: https://habr.com/ru/post/1544925/


All Articles