-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddSharedInfrastructure.ps1
44 lines (36 loc) · 1.44 KB
/
AddSharedInfrastructure.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
git submodule update --init
# Function to list all .csproj files
function Get-ProjectFiles {
$path = ".\infrastructure"
return Get-ChildItem -Path $path -Recurse -Filter *.csproj
}
# Function to read project dependencies
function Get-ProjectDependencies {
param ([string]$projectFile)
[xml]$content = Get-Content $projectFile
return $content.Project.ItemGroup.ProjectReference.Include
}
# Main script execution starts here
$projects = Get-ProjectFiles
$projects | ForEach-Object { Write-Output "$($_.FullName)" }
$selectedProject = Read-Host "Please select a project file from the above list"
$slnName = Read-Host "Enter the solution name"
# Create solution if it doesn't exist
$slnPath = ".\$slnName.sln"
if (-Not (Test-Path $slnPath)) {
dotnet new sln -n $slnName
}
# Add selected project to the solution
dotnet sln $slnPath add $selectedProject -s "3. Shared Infrastructure"
# Get and add dependencies recursively
function Add-Dependencies {
param ([string]$projectFile, [string]$slnPath)
$dependencies = Get-ProjectDependencies -projectFile $projectFile
foreach ($dep in $dependencies) {
$depPath = Join-Path (Split-Path $projectFile -Parent) $dep
dotnet sln $slnPath add $depPath -s "3. Shared Infrastructure"
Add-Dependencies -projectFile $depPath -slnPath $slnPath
}
}
# Recursively add all dependencies of the selected project
Add-Dependencies -projectFile $selectedProject -slnPath $slnPath