Skip to content

Commit

Permalink
Fix namespaces generation to handle framework targets other than nets…
Browse files Browse the repository at this point in the history
…tandard2.0 (Azure#44768)

* Fix namespaces generation to handle framework targets other than netstandard2.0

* fix variable name

* If more than 1 is found, just use the first one
  • Loading branch information
JimSuplizio authored and tejasm-microsoft committed Jul 22, 2024
1 parent 26a5b68 commit 191a1f2
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions eng/scripts/Save-Package-Namespaces-Property.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,45 @@ $foundError = $false
foreach ($packageInfoFile in $packageInfoFiles) {
Write-Host "processing $($packageInfoFile.FullName)"
$packageInfo = ConvertFrom-Json (Get-Content $packageInfoFile -Raw)
# Piece together the artifacts bin directory
$artifactsBinDir = Join-Path $repoRoot "artifacts" "bin" $packageInfo.Name $buildConfiguration "netstandard2.0"
# Piece together the artifacts bin directory. Note that the artifactsBinDir
# directory cannot include the netstandard2.0 because anything not building
# with the netstandard2.0 will be in a different subdirectory
$artifactsBinDir = Join-Path $repoRoot "artifacts" "bin" $packageInfo.Name $buildConfiguration
Write-Host "artifactsBinDir=$artifactsBinDir"
if (Test-Path $artifactsBinDir) {
$defaultDll = Join-Path $artifactsBinDir "$($packageInfo.Name).dll"
if ($defaultDll -and (Test-Path $defaultDll)) {
Write-Host "dll file path: $($defaultDll.FullName)"
$namespaces = @(Get-NamespacesFromDll $defaultDll)
if ($namespaces.Count -gt 0) {
Write-Host "Get-NamespacesFromDll returned the following namespaces:"
foreach ($namespace in $namespaces) {
Write-Host " $namespace"
}
# If by some reason, the namespaces already exist, overwrite them with
# what was just computed
if ($packageInfo.PSobject.Properties.Name -contains "Namespaces") {
$packageInfo.Namespaces = $namespaces
}
else {
$packageInfo = $packageInfo | Add-Member -MemberType NoteProperty -Name Namespaces -Value $namespaces -PassThru
}
$packageInfoJson = ConvertTo-Json -InputObject $packageInfo -Depth 100
Write-Host "The updated packageInfo for $packageInfoFile is:"
Write-Host "$packageInfoJson"
Set-Content `
-Path $packageInfoFile `
-Value $packageInfoJson
$dllName = "$($packageInfo.Name).dll"
# This needs to ensure an array is always returned.
$foundDlls = @(Get-ChildItem -Path $artifactsBinDir -Recurse -File -Filter $dllName)
if (-not $foundDlls) {
LogError "$dllName does not exist in any of the subdirectories of $artifactsBinDir"
$foundError = $true
continue
}
$defaultDll = $foundDlls[0]
Write-Host "dll file path: $($defaultDll.FullName)"
$namespaces = @(Get-NamespacesFromDll $defaultDll)
if ($namespaces.Count -gt 0) {
Write-Host "Get-NamespacesFromDll returned the following namespaces:"
foreach ($namespace in $namespaces) {
Write-Host " $namespace"
}
# If by some reason, the namespaces already exist, overwrite them with
# what was just computed
if ($packageInfo.PSobject.Properties.Name -contains "Namespaces") {
$packageInfo.Namespaces = $namespaces
}
else {
LogWarning "Unable to get namespaces for $($defaultDll.FullName)"
$packageInfo = $packageInfo | Add-Member -MemberType NoteProperty -Name Namespaces -Value $namespaces -PassThru
}
$packageInfoJson = ConvertTo-Json -InputObject $packageInfo -Depth 100
Write-Host "The updated packageInfo for $packageInfoFile is:"
Write-Host "$packageInfoJson"
Set-Content `
-Path $packageInfoFile `
-Value $packageInfoJson
}
else {
LogError "$defaultDll didn't exist, unable to get namespaces for $($packageInfo.Name), version=$($packageInfo.Verison)"
$foundError = $true
LogWarning "Unable to get namespaces for $($defaultDll.FullName)"
}
}
else {
Expand Down

0 comments on commit 191a1f2

Please sign in to comment.