Advertisement
Guest User

temporarily unsign all projects in a visual studio solution

a guest
Mar 10th, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param($sln, [Switch]$revert)
  2.  
  3. $slnContent = [IO.File]::ReadAllText($sln);
  4.  
  5. $projects = [Text.RegularExpressions.Regex]::Matches($slnContent, "Project\(`"\{.*?\}`"\) = `".*?`", `"(.*?)`"");
  6.  
  7. $skips = @("Solution Items");
  8.  
  9. $cd = [IO.Path]::GetDirectoryName($sln);
  10. Write-Host $cd;
  11.  
  12. foreach ($project in $projects) {
  13.  
  14.     $csproj = $project.Groups[1].Value;
  15.  
  16.     if ($skips -contains $csproj -or $csproj.Contains(".") -eq $false) {
  17.         continue;
  18.     }
  19.  
  20.     $fullPath = $cd + "\" + $csproj;
  21.  
  22.     $resolved = new-object IO.FileInfo $fullPath;
  23.  
  24.     Write-Host $resolved.FullName;
  25.  
  26.     if ($resolved.Exists -ne $true) {
  27.         throw "bad resolved path";
  28.     }
  29.  
  30.     $preUnsign = $resolved.FullName + ".unsign.revert";
  31.  
  32.     if ($revert) {
  33.         copy $preUnsign $resolved.FullName;
  34.         Write-Host "reverted " + $resolved.FullName + " from " + $preUnsign;
  35.     } else {
  36.         $content = [IO.File]::ReadAllText($resolved.FullName);
  37.         [IO.File]::WriteAllText($preUnsign, $content);
  38.         $content = $content.Replace("<SignAssembly>true</SignAssembly>", "<SignAssembly>false</SignAssembly>");
  39.         [IO.File]::WriteAllText($resolved.FullName, $content);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement