Skip to content

Commit 9c6bcf3

Browse files
authored
[Tools]Throw exception if a solution reference a not exist csproj. (Azure#15101)
* Throw exception if a solution reference a not exist csproj. * Throw exception if a solution reference a not exist csproj. Co-authored-by: wyunchi-ms <[email protected]>
1 parent 0d6f89a commit 9c6bcf3

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tools/CreateFilterMappings.ps1

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ function Create-ProjectToFullPathMappings
9696
$CsprojFiles = Get-ChildItem -Path $ServiceFolder -Filter "*.csproj" -Recurse
9797
foreach ($CsprojFile in $CsprojFiles)
9898
{
99+
if ($Mappings.Contains($CsprojFile.BaseName))
100+
{
101+
throw ($CsprojFile.FullName + " is conflicts with " + $Mappings[$CsprojFile.BaseName])
102+
}
99103
$Mappings[$CsprojFile.BaseName] = $CsprojFile.FullName
100104
}
101105
}
@@ -149,11 +153,23 @@ function Add-ProjectDependencies
149153
)
150154

151155
$CommonProjectsToIgnore = @("ScenarioTest.ResourceManager", "TestFx", "Tests" )
152-
153-
$ProjectDependencies = @()
156+
$CsprojList = @()
154157
$Content = Get-Content -Path $SolutionPath
155-
$Content | Select-String -Pattern "`"[a-zA-Z0-9.]*`"" | ForEach-Object { $_.Matches[0].Value.Trim('"') } | Where-Object { $CommonProjectsToIgnore -notcontains $_ } | ForEach-Object { $ProjectDependencies += $_ }
156-
$Mappings[$SolutionPath] = $ProjectDependencies
158+
$SolutionFoloderPath = Split-Path -Parent $SolutionPath
159+
$Content | Select-String -Pattern "`"[a-zA-Z0-9`.`\\`/]*.csproj`"" | ForEach-Object { $_.Matches[0].Value.Trim('"') } | Where-Object { $CommonProjectsToIgnore -notcontains $_ } | ForEach-Object { $CsprojList += $_ }
160+
161+
foreach ($Csproj in $CsprojList)
162+
{
163+
try
164+
{
165+
$CsprojAbslutionPath = Resolve-Path -Path ($SolutionFoloderPath + "\\" + $Csproj)
166+
}
167+
catch
168+
{
169+
throw "${SolutionPath}: $Csproj is not found!"
170+
}
171+
}
172+
$Mappings[$SolutionPath] = $CsprojList | ForEach-Object { (Split-Path -Path $_ -Leaf).Replace('.csproj', '') }
157173
return $Mappings
158174
}
159175

@@ -260,7 +276,7 @@ function Get-ModuleFromPath
260276
[string]$FilePath
261277
)
262278

263-
return $FilePath.Replace('/', '\').Split('\src\')[1].Split('\')[0]
279+
return $FilePath.Replace('/', '\').Split('\src\')[-1].Split('\')[0]
264280
}
265281
function Add-CsprojMappings
266282
{

0 commit comments

Comments
 (0)