-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRename-Project.ps1
41 lines (32 loc) · 1.4 KB
/
Rename-Project.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
function Rename-Project {
$solutionPath="C:\Users\shashibhushan.kumar\source\Newfolder"
$oldName="TVBot"
$newName="ByteBaba"
# Check if solution file exists
if (!(Test-Path "$solutionPath\$oldName.sln")) {
Write-Error "Solution file '$solutionPath\$oldName.sln' not found"
return
}
else{
Write-Output "Solution file '$solutionPath\$oldName.sln' found"
}
# Rename solution file
Rename-Item "$solutionPath\$oldName.sln" "$newName.sln"
# Rename project folders and files
Get-ChildItem -Path $solutionPath -Recurse -Filter "$oldName*" | ForEach-Object {
$newPath = $_.FullName -replace [regex]::Escape($oldName), $newName
Rename-Item -Path $_.FullName -NewName $newPath
}
# Update solution file references
(Get-Content "$solutionPath\$newName.sln") -replace $oldName, $newName | Set-Content "$solutionPath\$newName.sln"
# Update project file references
Get-ChildItem -Path $solutionPath -Recurse -Filter "*.csproj" | ForEach-Object {
(Get-Content $_.FullName) -replace $oldName, $newName | Set-Content $_.FullName
}
# Update namespaces in .cs files
Get-ChildItem -Path $solutionPath -Recurse -Filter "*.cs" | ForEach-Object {
(Get-Content $_.FullName) -replace $oldName, $newName | Set-Content $_.FullName
}
Write-Output "Renaming completed successfully."
}
Rename-Project