forked from StingyJack/Vs-Utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisable-SignAssembly.ps1
59 lines (48 loc) · 1.68 KB
/
Disable-SignAssembly.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
<#
.SYNOPSIS
This will disable assembly signing (strong naming) for a project if the attribute is present.
.PARAMETER $ProjFilePath
The path to the project file.
#>
function Disable-SignAssembly
{
[CmdletBinding()]
Param(
[string] $ProjFilePath
)
Write-Verbose "Looking for 'SignAssembly' property in '$ProjFilePath'"
$projContent = [xml](Get-Content -Path $ProjFilePath)
$nonConditionalPropertyGroups = $projContent.Project.PropertyGroup | Where-Object {-Not $_.Condition}
if ($null -eq $nonConditionalPropertyGroups -or $nonConditionalPropertyGroups.Count -eq 0)
{
Write-Verbose "Only conditional property groups are present."
return
}
$signAssemblyPropertyGroups = @($nonConditionalPropertyGroups | Where-Object {Get-Member -InputObject $_ -Name "SignAssembly"})
if ($null -eq $signAssemblyPropertyGroups -or $signAssemblyPropertyGroups.Count -eq 0)
{
Write-Verbose "No SignAssembly property detected"
return
}
$updatedPropertyCount = 0
foreach ($signAssemblyPropertyGroup in $signAssemblyPropertyGroups)
{
if ($signAssemblyPropertyGroup.SignAssembly -eq $false)
{
Write-Verbose "SignAssembly is already false"
continue
}
Write-Verbose "Updating SignAssembly to be false "
$signAssemblyPropertyGroup.SignAssembly = [bool]::FalseString
$updatedPropertyCount++
}
if ($updatedPropertyCount -gt 0)
{
$projContent.Save($ProjFilePath)
Write-Output "'$ProjFilePath' updated to disable assembly signing"
}
else
{
Write-Output "'$ProjFilePath' was not updated"
}
}