Skip to content

Instantly share code, notes, and snippets.

@kstrauss
Last active February 21, 2017 17:05
Show Gist options
  • Save kstrauss/c8bc4392181f6681396a to your computer and use it in GitHub Desktop.
Save kstrauss/c8bc4392181f6681396a to your computer and use it in GitHub Desktop.
replace nuget references with project references
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
}
<# 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
@timabell
Copy link

Would you mind sharing VisualStudioProjectModifiers? It doesn't appear to be available online.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment