Last active
September 9, 2021 03:33
-
-
Save michael-baker/aa346defbc3104caeca6609dc8c31da7 to your computer and use it in GitHub Desktop.
Remove legacy CS Project elements and attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$true)] | |
[String[]] | |
$Path | |
) | |
$ErrorActionPreference = 'Stop' | |
$projs = gci -Path $Path -Filter *.csproj -Recurse | |
foreach ($projFile in $projs) | |
{ | |
$proj = New-Object System.Xml.XmlDocument | |
$proj.PreserveWhitespace = $true | |
$proj.Load($projFile.FullName) | |
#$proj.Project.ToolsVersion = "14.0" | |
$elements = $proj.GetElementsByTagName("BootstrapperPackage") | |
$items = @(); $elements.ForEach({ $items += $_ }) | |
$items | foreach { | |
$_.ParentNode.RemoveChild($_) | |
} | |
$uglyElements = @( | |
"FileAlignment", | |
"BaseAddress" | |
"SccProjectName", | |
"SccLocalPath", | |
"SccAuxPath", | |
"SccProvider", | |
"FileUpgradeFlags", | |
"UpgradeBackupLocation", | |
"Install", | |
"UpdateEnabled", | |
"UpdateMode", | |
"UpdateInterval", | |
"UpdateIntervalUnits", | |
"UpdatePeriodically", | |
"MapFileExtensions", | |
"IsWebBootstrapper", | |
"UseApplicationTrust", | |
"BootstrapperEnabled", | |
"TargetFrameworkProfile", | |
"OldToolsVersion", | |
"PublishUrl", | |
"InstallFrom", | |
"UpdateRequired", | |
"ApplicationRevision", | |
"ApplicationVersion" | |
"DefaultClientScript", | |
"DefaultHTMLPageLayout", | |
"DefaultTargetSchema", | |
"RemoveIntegerChecks", | |
"MinFrameworkVersionRequired", | |
"IsCodedUITest", | |
"NuGetPackageImportStamp", | |
"ReferencePath", | |
"UseVSHostingProcess" | |
) | |
$uglyElements.ForEach({ | |
$items = @() | |
$proj.GetElementsByTagName($_).ForEach( {$items += $_ }) | |
$items.ForEach( { $_.ParentNode.RemoveChild($_) } ) | Out-Null | |
}) | |
# Remove .NET 3.5 stuff | |
$rtf = $proj.GetElementsByTagName("RequiredTargetFramework") | |
for ($i = 0; $i -lt $rtf.Count; $i++) { | |
if ($rtf[$i].InnerText -eq "3.0" -or $rtf[$i].InnerText -eq "3.5") { | |
$rtf[$i].ParentNode.RemoveChild($rtf[$i]) | |
} | |
} | |
$proj.Save($projFile.FullName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment