-
Notifications
You must be signed in to change notification settings - Fork 7
/
Write-AssemblyVersion.ps1
55 lines (42 loc) · 1.65 KB
/
Write-AssemblyVersion.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
<#
.SYNOPSIS
Writes the assembly attribute values to any file in the search path matching the pattern "*AssemblyInfo.*"
#>
function Write-AssemblyVersion
{
[CmdletBinding()]
Param(
[string] $SearchPath,
[string] $AssemblyVersion,
[string] $AssemblyFileVersion,
[string] $AssemblyInfoVersion
)
$pathToSearch = $SearchPath
if ((Get-Item $SearchPath) -is [System.IO.DirectoryInfo] -eq $false)
{
$pathToSearch = Split-Path $SearchPath -Parent
}
$matchingItems = @(Get-ChildItem -Path $pathToSearch -Recurse -File | Where-Object {$_.Name -ilike "*AssemblyInfo.*" -and $_.FullName -inotlike "*\obj\*"})
foreach($matchingItem in $matchingItems)
{
$linesToSave = [string[]]@()
$existingLines = [string[]]@(Get-Content $matchingItem.FullName)
foreach ($line in $existingLines)
{
$trimmedLine = $line.Trim()
if ($trimmedLine -inotlike "*Assembly*Version(*")
{
$linesToSave += $trimmedLine
}
}
$linesToSave += "[assembly: AssemblyVersion(`"$AssemblyVersion`")]"
$linesToSave += "[assembly: AssemblyFileVersion(`"$AssemblyFileVersion`")]"
$linesToSave += "[assembly: AssemblyInformationalVersion(`"$AssemblyInfoVersion`")]"
Edit-TfVcFile -Path $matchingItem.FullName
if ((Get-ItemProperty -Path $matchingItem.FullName -Name IsReadOnly) -eq $true)
{
Set-ItemProperty -Path $matchingItem.FullName -Name IsReadOnly -Value $false
}
Set-Content -Path $matchingItem.FullName -Value $linesToSave -Encoding Unicode
}
}