Skip to content

Instantly share code, notes, and snippets.

@jrotello
Last active August 29, 2015 13:57
Show Gist options
  • Save jrotello/9480373 to your computer and use it in GitHub Desktop.
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.
[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