I'm editing a Powershell script written by Owen Johnson on GitHub for migrating MSBuild-Integrated solutions to use Automatic Package Restore with Nuget. Here is the original migration script:
########################################
# Regex Patterns for Really Bad Things!
$listOfBadStuff = @(
#sln regex
"\s*(\.nuget\\NuGet\.(exe|targets)) = \1",
#*proj regexes
"\s*<Import Project=""\$\(SolutionDir\)\\\.nuget\\NuGet\.targets"".*?/>",
"\s*<Target Name=""EnsureNuGetPackageBuildImports"" BeforeTargets=""PrepareForBuild"">(.|\n)*?</Target>"
"\s*<RestorePackages>\w*</RestorePackages>"
)
#######################
# Delete NuGet.targets
ls -Recurse -include 'NuGet.exe','NuGet.targets' |
foreach {
remove-item $_ -recurse -force
write-host deleted $_
}
#########################################################################################
# Fix Project and Solution Files to reverse damage done by "Enable NuGet Package Restore
ls -Recurse -include *.csproj, *.sln, *.fsproj, *.vbproj, *.wixproj, *.vcxproj |
foreach {
sp $_ IsReadOnly $false
$content = cat $_.FullName | Out-String
$origContent = $content
foreach($badStuff in $listOfBadStuff){
$content = $content -replace $badStuff, ""
}
if ($origContent -ne $content)
{
$content | out-file -encoding "UTF8" $_.FullName
write-host messed with $_.Name
}
}
I want to also remove <Target> tags and their contents where Name= "EnsureBclBuildImported". I'm not very experienced with regular expressions, and my initial attempts to get this to work have failed unfortunately. I tried changing the regex for the target tag to be "\s*<Target Name=""(EnsureNuGetPackageBuildImports|EnsureBclBuildImported)""/.+?(?=>)/(.|\n)*?</Target>"
I also tried making a new regualar expression like this: "\s*<Target Name=""EnsureBclBuildImported"" ^[^\>]*(.|\n)*?</Target>"