-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-projects-not-in-solutions.ps1
46 lines (41 loc) · 1.34 KB
/
find-projects-not-in-solutions.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
<#
.SYNOPSIS
Find c# projects in subdirectories not included in solution
with all migrations applied
#>
[cmdletBinding()]
Param
(
[Parameter(Mandatory = $false)][string]$sln = "./src/Cortside.RestFS.sln"
)
Function Global:Get-ProjectInSolution {
[CmdletBinding()] param (
[Parameter()][string]$Solution
)
$SolutionPath = Join-Path (Get-Location) $Solution
$SolutionFile = Get-Item $SolutionPath
$SolutionFolder = $SolutionFile.Directory.FullName
Get-Content $Solution |
Select-String 'Project\(' |
ForEach-Object {
$projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') }
[PSCustomObject]@{
File = $projectParts[2]
Guid = $projectParts[3]
Name = $projectParts[1]
}
} |
Where-Object File -match "csproj$" |
ForEach-Object {
Add-Member -InputObject $_ -NotePropertyName FullName -NotePropertyValue (Join-Path $SolutionFolder $_.File) -PassThru
}
}
Get-ProjectInSolution $sln | select-object Fullname | sort > projects.txt
# add projects not already in solution file
gci *.csproj -r | select-object fullname | %{
$in = Select-String -Path .\projects.txt -SimpleMatch $_.FullName;
if ($in -eq $null) {
echo "Adding $_ to $sln"
dotnet sln $sln add $_.FullName
}
}