Skip to content

Instantly share code, notes, and snippets.

@rahulpnath
Last active October 18, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rahulpnath/13d3b4f54cec51e22344876b1566b911 to your computer and use it in GitHub Desktop.
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 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