Last active
August 29, 2015 13:57
-
-
Save jrotello/9480373 to your computer and use it in GitHub Desktop.
Convert from MSBuild NuGet Package Restore to Automatic Package Restore. Updates nuget.exe, removes nuget.targets, and removes the nuget.targets references from all .csproj files under the solution directory provided.
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
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true)] | |
$SolutionDir | |
) | |
$SolutionDir = Resolve-Path $SolutionDir | |
$nugetTargetsPath = Join-Path $SolutionDir ".nuget\nuget.targets" | |
$nugetExePath = Join-Path $SolutionDir ".nuget\nuget.exe" | |
if (Test-Path $nugetExePath) { | |
Write-Host "Updating NuGet..." | |
& $nugetExePath update -self | |
} | |
if (Test-Path $nugetTargetsPath) { | |
Write-Host "Deleting '.nuget\nuget.targets'..." | |
Remove-Item $nugetTargetsPath | |
} | |
$projectCount = 0 | |
ls -Path $SolutionDir *.csproj -Recurse | % { | |
Write-Verbose "Modifying $($_.Name)..." | |
$contents = Select-String -InputObject $_ -Pattern '^.*<import.*nuget\.targets.*/>.*$' -NotMatch | Select -ExpandProperty Line | |
Out-File -InputObject $contents -FilePath $_.Fullname -Encoding UTF8 | |
$projectCount++ | |
} | |
Write-Host ("{0} projects processed." -f $projectCount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment