@@ -178,8 +178,33 @@ function Update-GeneratedSubModule {
178178 if ($csprojName -match " ^Az\.(?<cSubModuleName>\w+)\.csproj$" ) {
179179 $cSubModuleNameTrimmed = $Matches [" cSubModuleName" ]
180180 }
181+
182+ # Get namespace from csproj file
183+ $csprojPath = Join-Path $SourceDirectory $csprojName
184+ Write-Host " Reading namespace from csproj: $csprojPath " - ForegroundColor DarkGreen
185+ $namespace = $null
186+ if (Test-Path $csprojPath ) {
187+ try {
188+ [xml ]$csprojContent = Get-Content $csprojPath
189+ $rootNamespaceNode = $csprojContent.Project.PropertyGroup.RootNamespace
190+ if ($rootNamespaceNode ) {
191+ $namespace = " $rootNamespaceNode " .Trim()
192+ Write-Host " Loading namespace from csproj: $namespace retrieved" - ForegroundColor Green
193+ }
194+ else {
195+ Write-Warning " RootNamespace not found in csproj file"
196+ }
197+ }
198+ catch {
199+ Write-Warning " Failed to read namespace from csproj: $ ( $_.Exception.Message ) "
200+ }
201+ }
202+ else {
203+ Write-Warning " Csproj file not found at path: $csprojPath "
204+ }
205+
181206 # regenerate csproj
182- New-GeneratedFileFromTemplate - TemplateName ' Az.ModuleName.csproj' - GeneratedFileName $csprojName - GeneratedDirectory $GeneratedDirectory - ModuleRootName $ModuleRootName - SubModuleName $cSubModuleNameTrimmed - SubModuleNameFull $SubModuleName
207+ New-GeneratedFileFromTemplate - TemplateName ' Az.ModuleName.csproj' - GeneratedFileName $csprojName - GeneratedDirectory $GeneratedDirectory - ModuleRootName $ModuleRootName - SubModuleName $cSubModuleNameTrimmed - SubModuleNameFull $SubModuleName - Namespace $namespace
183208
184209 # revert guid in psd1 so that no conflict in updating this file
185210 if ($guid ) {
@@ -209,7 +234,9 @@ function New-GeneratedFileFromTemplate {
209234 [string ]
210235 $SubModuleName ,
211236 [string ]
212- $SubModuleNameFull
237+ $SubModuleNameFull ,
238+ [string ]
239+ $Namespace
213240 )
214241 $TemplatePath = Join-Path $PSScriptRoot " Templates"
215242 $templateFile = Join-Path $TemplatePath $TemplateName
@@ -228,6 +255,9 @@ function New-GeneratedFileFromTemplate {
228255 $templateFile = $templateFile -replace ' {ModuleFolderPlaceHolder}' , " $SubModuleName .Autorest"
229256 }
230257 $templateFile = $templateFile -replace ' {RootModuleNamePlaceHolder}' , $ModuleRootName
258+ if ($Namespace ) {
259+ $templateFile = $templateFile -replace ' {NamespacePlaceHolder}' , $Namespace
260+ }
231261 Write-Host " Copying template: $TemplateName ." - ForegroundColor Yellow
232262 $templateFile | Set-Content $GeneratedFile - force
233263}
0 commit comments