Scripts/VisualStudio.ps1


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
}

function GetVsDevCmdPath
{
    <#
    .SYNOPSIS
    Gets the path to the [vsdevcmd.bat].
    #>

    param(
        [string]$version = "[15,16)"
    )
    $vsPath = GetVsPath $version
    $path = "$vsPath\Common7\Tools\vsdevcmd.bat"
    return $path
}

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 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 GetVsDevEnvExe([string]$version)
{
    <#
    .SYNOPSIS
    Gets the path to the [devenv.exe].
    #>

    
    if(IsNullOrEmpty $version)
    {
        $version = $VsVersion
    }

    $vsPath = GetVsPath $version
    $path = "$vsPath\Common7\IDE\devenv.exe"
    return $path
}

function OpenSafetySolution()
{
    <#
    .SYNOPSIS
    Opens Visual Studio 2017 and loads "S7F_All.sln" with code-analysis disabled.
    #>


    $devenvPath = GetVsDevEnvExe
     $solutionPath = "$LocalWorkspace\src\S7F\_Solutions\Composite\S7F_All.sln"
    $env:DevDivCodeAnalysisRunType = "Disabled"
    & "$devenvPath" "$solutionPath"
}

function OpenRhinoMocksToMoqSolution()
{
    <#
    .SYNOPSIS
    Opens Visual Studio 2019 and loads "Rhino.Mocks.To.Moq.sln" with code-analysis disabled.
    #>

    
    $devenvPath = GetVsDevEnvExe $VsVersion16
     $solutionPath = "D:\GitRepos\RhinoMocksToMoq\master\Rhino.Mocks.To.Moq.sln"
    & "$devenvPath" "$solutionPath"
}