Command/Environment/UpdateSafeSys.ps1


# Global User variables
[string] $global:WorkspaceName = "Step7_Safety_T"
[string] $global:LocalWorkspace = "D:\WS\Step7_Safety_T"
[string] $global:ServerWorkspace = "$/TIA Portal/TPE/dev/Step7_Safety_T"
[string] $global:BuildDefinition = "TPE.Step7_Safety_T.Rolling"

# Global System variables
[string] $global:CmxVersion = "1.0.0.0"
[string] $global:VsVersion = "[15,16)" 
[string] $global:VsVersion14 = "[14,15)" # VisualStudio 2015
[string] $global:VsVersion15 = "[15,16)" # VisualStudio 2017
[string] $global:VsVersion16 = "[16,17)" # VisualStudio 2019
[string] $global:VsWherePath = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
[string] $global:TfsUrl = "https://jupiter.tfs.siemens.net/tfs/tia"
[string] $global:CmxRootFolder = $PsScriptRoot
[string] $global:BinariesFolder = "$LocalWorkspace\Binaries"

function IsVsDev()
{
    <#
    .SYNOPSIS
    Whether the script is running in a Visual Studio development environment.
    If [CallVsDev] has been called, this function returns true.
    #>

    return ![string]::IsNullOrEmpty($env:DevEnvDir)
}

function CallVsDev 
{
    <#
    .SYNOPSIS
    Calls [vsdevcmd.bat] of the given VS version to include the development-environment.
    #>

    param(
        [string]$version = "[15,16)"
    )
    $vsPath = GetVsPath $version
    $vsd = "$vsPath\Common7\Tools\vsdevcmd.bat"
    & "${env:COMSPEC}" /s /c "`"$vsd`" -no_logo && set" | Foreach-Object {
        $name, $value = $_ -split '=', 2
        Set-Content "env:\$name" $value
    }
}

function GetVsPath
{
    <#
    .SYNOPSIS
    Gets the VS installation path of the given version e.g. [15,16). Returns e.g. "C:\Program Files (x86)\Microsoft
    Visual Studio\2017\Enterprise".
    .EXAMPLE
    $vsPath = GetVsPath $vsVersion "[15,16)"
    #>

    param(
        [string]$version = "[15,16)"
        )
    $path = & "$VsWherePath" -legacy -property installationPath -version $version
    return $path
}

Write-Output "Update the SafeSys lib . . . "
$x64 = "$BinariesFolder\Release\x64"
$lib = "$x64\Lib"
$combining = "$lib\Combining"
$safeSys = "$lib\Spec\99BE5FABBC914803AAC385A073A90F20"
$libSln = "$LocalWorkspace\src\SYSLIB\_Solutions\MasterBuild\Library.sln"

if(-not (Test-Path -Path $lib -PathType Container))
{
    Write-Host "No Lib folder found to update. The path $lib does not exist."
    Read-Host "The script has finished. Press any key to exit"
    exit
}
if(Test-Path -PathType Container -Path $combining)
{
    Write-Host "Remove Combining folder . . . "
    Remove-Item -Path $combining -Recurse -Force
}

if(Test-Path -Path $safeSys -PathType Container)
{
    Write-Host "Remove SafeSys folder . . . "
    Remove-Item -Path $safeSys -Recurse -Force
}

if((IsVsDev) -eq $false)
{
    CallVsDev "$VsVersion" *>$null
}

Write-Host "LibSln: $libSln"
if(-not (Test-Path -Path $libSln -PathType Leaf))
{
    Write-Host "The SLN file $libSln does not exists. Cannot update the syslib."
    Read-Host "The script has finished. Press any key to exit"
    exit
}

Write-Host "Build the syslib . . . "
& msbuild "$libSln" /t:Build /p:Configuration=Release`;Platform=x64
Write-Host "Build the syslib has finished. "

Read-Host "The script has finished. Press any key to exit"