-
Notifications
You must be signed in to change notification settings - Fork 7
/
Get-PrimaryProjectOutput.ps1
67 lines (57 loc) · 2.5 KB
/
Get-PrimaryProjectOutput.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#
.SYNOPSIS
Gets the primary output (a dll or exe) for a proj file.
#>
function Get-PrimaryProjectOutput
{
[CmdletBinding()]
Param(
[string] $ProjFilePath,
[string] $BuildConfiguration,
[string] $BuildPlatform
)
Write-Verbose "Getting project output for project file $ProjFilePath"
$projFileFolder = Split-Path $projFilePath -Parent
$projFileContent = [xml] (Get-Content $projFilePath)
$projectBuildPlatform = $BuildPlatform.Replace(" ", "") #"Any CPU" to "AnyCPU"
$conditon = "'`$(Configuration)|`$(Platform)' == '$BuildConfiguration|$projectBuildPlatform'".Trim()
$propertyGroup = $projFileContent.Project.PropertyGroup | Where-Object {$null -ne $_.Condition -and $_.Condition.Trim() -ieq $conditon}
if ($null -eq $propertyGroup)
{
Write-Warning "No build property group found that matches '$conditon'"
return $null
}
$relativeOutputFolderPath = $propertyGroup.OutputPath
$absoluteOutputFolderPath = Join-Path -Path $projFileFolder -ChildPath $relativeOutputFolderPath
$asmName = $projFileContent.Project.PropertyGroup.AssemblyName | Where-Object {[System.String]::IsNullOrWhiteSpace($_) -eq $false} | Select-Object -First 1
Write-Verbose "AssemblyName = '$($asmName)'"
$outputType = $projFileContent.Project.PropertyGroup.OutputType| Where-Object {[System.String]::IsNullOrWhiteSpace($_) -eq $false} | Select-Object -First 1
Write-Verbose "OutputType = ''$($outputType)'"
$fileExt = "dll"
if ($outputType -ieq "Database")
{
if ($propertyGroup | Get-Member -Name SqlTargetName -MemberType Property)
{
$asmName = $propertyGroup.SqlTargetName
}
elseif ($projFileContent.PropertyGroup | Get-Member -Name SqlTargetName -MemberType Property)
{
$asmName = $projFileContent.PropertyGroup.SqlTargetName
}
$fileExt = "dacpac"
}
elseif ($outputType -ne "Library")
{
$fileExt = "exe" #https://docs.microsoft.com/en-us/dotnet/api/vslangproj.prjoutputtype?view=visualstudiosdk-2017
}
$outputName = "$asmName.$fileExt"
Write-Verbose "OutputName = '$outputName'"
$absoluteOutputFilePath = Join-Path -Path $absoluteOutputFolderPath -ChildPath $outputName
if (-Not (Test-Path $absoluteOutputFilePath))
{
Write-Warning "Could not locate project build output '$absoluteOutputFilePath'"
return $null
}
Write-Verbose "Found output at path '$absoluteOutputFilePath'"
return $absoluteOutputFilePath
}