Last active
February 21, 2017 17:05
-
-
Save kstrauss/c8bc4392181f6681396a to your computer and use it in GitHub Desktop.
replace nuget references with project references
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
Import-Module VisualStudioProjectModifiers | |
$projs = dir -Recurse -filter *.csproj | |
# lookup of AssemblyName to projectFile | |
$lookup = @{} | |
$projs | % { | |
select-string '<AssemblyName>(.*)</AssemblyName>' $_.FullName } | %{ | |
$lookup[$_.Matches.Groups[1].value] = $_.Path | |
} | |
$projs | select | %{ | |
$fullName = $_.FullName | |
$directory = $_.Directory | |
$refs = $fullName | get-References | |
$refs.References | ? {$lookup.ContainsKey($_.ReferenceName.split(',')[0])} | %{ | |
$key = $_.ReferenceName.split(',')[0] | |
pushd $directory | |
$relativePath = Resolve-Path $lookup[$key] -Relative | |
popd | |
#$relativePath | |
#$lookup[$key] | |
Add-ProjectReference -path $fullName -referencedProjPath $lookup[$key] -IncludeStr $relativePath | |
Remove-Reference -path $fullName -Reference $_.ReferenceName | |
} | |
$_ | Update-NuGetReferencesToUseSolutionDir | |
} |
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
<# do a search and replace to put SolutionDir appropriately#> | |
dir -recurse -filter *.csproj | select-string -SimpleMatch '..\..\..\..\Infrastructure' | | |
sort -Unique Path |%{ | |
ReplaceText-InFile -searchPattern '..\\..\\..\\..\\Infrastructure' -replaceText '$(SolutionDir)\..\Infrastructure' -Debug -inputFile $_.Path | |
$_.Path | |
} | |
# need to do something to remove from the packages.config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you mind sharing VisualStudioProjectModifiers? It doesn't appear to be available online.