forked from aspnet/KestrelHttpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToProjectReferences.ps1
45 lines (36 loc) · 1.27 KB
/
ToProjectReferences.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
param($references)
$ErrorActionPreference = "Stop";
function ToProjectName($file)
{
return $file.Directory.Name;
}
$projectreferences = ls (Join-Path $references *.csproj) -rec;
$localprojects = ls -rec *.csproj;
foreach ($project in $localprojects)
{
Write-Host "Processing $project";
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null;
$changed = $false
$xDoc = [System.Xml.Linq.XDocument]::Load($project, [System.Xml.Linq.LoadOptions]::PreserveWhitespace);
$endpoints = $xDoc.Descendants("PackageReference") | %{
$packageName = $_.Attribute("Include").Value;
$replacementProject = $projectreferences | ? {
return (ToProjectName($_)) -eq $packageName
};
if ($replacementProject)
{
$changed = $true
Write-Host " Replacing $packageName with $($project.FullName)";
$_.Name = "ProjectReference";
$_.Attribute("Include").Value = $replacementProject.FullName;
}
};
if ($changed)
{
$settings = New-Object System.Xml.XmlWriterSettings
$settings.OmitXmlDeclaration = $true;
$writer = [System.Xml.XmlWriter]::Create($project, $settings)
$xDoc.Save($writer);
$writer.Dispose();
}
}