Last active
October 18, 2018 15:54
-
-
Save rahulpnath/13d3b4f54cec51e22344876b1566b911 to your computer and use it in GitHub Desktop.
This powershell script helps remove all NuGet configurations and files that got added while enabling NuGet Restore. More details @ http://rahulpnath.com/blog/disable-nuget-package-restore-for-a-net-poject/
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
# This powershell script helps remove all NuGet configurations and files that got added while enabling NuGet Restore. | |
# More details @ http://rahulpnath.com/blog/disable-nuget-package-restore-for-a-net-poject/ | |
param([Parameter(Mandatory=$true)][string]$solutionDirectory) | |
$importNugetTargetsTag= [regex]::escape(@' | |
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> | |
'@) | |
$restorePackagesTag = '<RestorePackages>.*?</RestorePackages>' | |
$nuGetPackageImportStamp = '<NuGetPackageImportStamp>.*?</NuGetPackageImportStamp>' | |
$EnsureNuGetPackageBuildImportsTargetTag = '(?smi)<Target Name="EnsureNuGetPackageBuildImports".*?</Target>' | |
foreach ($f in Get-ChildItem -Recurse -Path $solutionDirectory -Filter *.csproj | sort-object) | |
{ | |
$text = Get-Content $f.FullName -Raw | |
$text ` | |
-replace $importNugetTargetsTag, "" ` | |
-replace $nuGetPackageImportStamp, "" ` | |
-replace $restorePackagesTag, "" ` | |
-replace $EnsureNuGetPackageBuildImportsTargetTag, "" ` | |
| set-content $f.FullName | |
} | |
Get-ChildItem -Path $solutionDirectory -include .nuget -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment