Skip to content

Commit cff0f2a

Browse files
authored
Add tool to connect PS and common repos (#20960)
* script to connect PS and common repos * move all common projects * fix the error with assemblyLoading proj * undo AssemblyLoading.csproj
1 parent d0598b3 commit cff0f2a

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

tools/DevTools/CommonRepo.psm1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<#
2+
.Synopsis
3+
Connects azure-powershell repo to azure-powershell-common repo for debugging.
4+
5+
.Description
6+
Connects azure-powershell repo to azure-powershell-common repo for debugging.
7+
8+
.Parameter CommonRepoPath
9+
Path to the common repo. Relative or absolute.
10+
11+
.Example
12+
Connect-CommonRepo -CommonRepoPath ../azure-powershell-common
13+
#>
14+
function Connect-CommonRepo {
15+
[CmdletBinding()]
16+
param(
17+
[Parameter(Mandatory)]
18+
[system.string]
19+
${CommonRepoPath}
20+
)
21+
22+
Write-Host "1/2 Adding common projects to sln and csproj"
23+
24+
$CommonRepoPath = (Resolve-Path $CommonRepoPath).Path
25+
$CommonProjects = Get-ChildItem -Path "$CommonRepoPath/src/" -Include *.csproj -Exclude *.test.* -Recurse
26+
$CommonProjects = $CommonProjects.FullName
27+
28+
29+
$RepoRoot = "$PSScriptRoot/../.."
30+
31+
Push-Location "$RepoRoot/src/Accounts"
32+
try {
33+
foreach ($csproj in $CommonProjects) {
34+
$csproj = [System.IO.Path]::GetFullPath($csproj)
35+
dotnet sln add $csproj
36+
if ($LASTEXITCODE -ne 0) {
37+
throw "Failed to add $csproj to Accounts.sln"
38+
}
39+
dotnet add ./Authentication/Authentication.csproj reference $csproj
40+
if ($LASTEXITCODE -ne 0) {
41+
throw "Failed to add $csproj to Authentication.csproj"
42+
}
43+
}
44+
45+
dotnet add ./AssemblyLoading/AssemblyLoading.csproj reference "$CommonRepoPath/src/Common/Common.csproj"
46+
if ($LASTEXITCODE -ne 0) {
47+
throw "Failed to add Common.csproj to AssemblyLoading.csproj"
48+
}
49+
}
50+
finally {
51+
Pop-Location
52+
}
53+
54+
55+
Write-Host "2/2: Remove the dependency of those common projects from .targets file"
56+
57+
$Patterns = @(
58+
'<PackageReference Include="Microsoft.Azure.PowerShell'
59+
)
60+
$TargetsFile = (Resolve-Path "$RepoRoot/tools/Common.Netcore.Dependencies.targets").Path
61+
(Get-Content $TargetsFile) | ForEach-Object { # https://stackoverflow.com/questions/10480673/find-and-replace-in-files-fails
62+
[string]$line = $_
63+
$IsMatch = $false
64+
foreach ($pattern in $patterns) {
65+
if ($line.IndexOf($pattern) -ne -1) {
66+
$IsMatch = $true
67+
break
68+
}
69+
}
70+
if ($IsMatch -and -not $line.StartsWith('<!--')) {
71+
return "<!--$line-->"
72+
}
73+
else {
74+
return $line
75+
}
76+
} | Set-Content $TargetsFile
77+
78+
Write-Host "Done connecting both repositories."
79+
}
80+
81+
function Disconnect-CommonRepo {
82+
Write-Host "Please run the following commands to undo Connect-CommonRepo. Double check those files do not have wanted changes.
83+
git checkout -- ./src/Accounts/Accounts.sln
84+
git checkout -- ./src/Accounts/Accounts/Accounts.csproj
85+
git checkout -- ./src/Accounts/AssemblyLoading/AssemblyLoading.csproj
86+
git checkout -- ./src/Accounts/Authentication/Authentication.csproj
87+
git checkout -- ./tools/Common.Netcore.Dependencies.targets
88+
"
89+
}
90+
91+
Export-ModuleMember -Function Connect-CommonRepo, Disconnect-CommonRepo

tools/DevTools/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# What's inside DevTools
2+
3+
## CommonRepo.psm1
4+
5+
A script module to help you connect the azure-powershell and azure-powershell-common repositories for developing or debugging.
6+
7+
```powershell
8+
# Connect
9+
Import-Module .\CommonRepo.psm1
10+
Connect-CommonRepo -CommonRepoPath ..\azure-powershell-common
11+
12+
# Disconnect
13+
Disconnect-CommonRepo
14+
```

0 commit comments

Comments
 (0)