diff --git a/d365fo.tools/functions/get-d365model.ps1 b/d365fo.tools/functions/get-d365model.ps1 index bd8f604e..730db913 100644 --- a/d365fo.tools/functions/get-d365model.ps1 +++ b/d365fo.tools/functions/get-d365model.ps1 @@ -185,7 +185,9 @@ function Get-D365Model { [string] $BinDir = "$Script:BinDir\bin", - [string] $PackageDirectory = $Script:PackageDirectory + [string] $PackageDirectory = $Script:PackageDirectory, + + [string] $MetaDataDir = $Script:MetaDataDir ) begin { @@ -221,7 +223,7 @@ function Get-D365Model { Write-PSFMessage -Level Verbose -Message "Machine is onebox. Initializing DiskProvider too." $diskProviderConfiguration = New-Object Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration - $diskProviderConfiguration.AddMetadataPath($PackageDirectory) + $diskProviderConfiguration.AddMetadataPath($MetaDataDir) $metadataProviderFactoryViaDisk = New-Object Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory $metadataProviderViaDisk = $metadataProviderFactoryViaDisk.CreateDiskProvider($diskProviderConfiguration) diff --git a/d365fo.tools/internal/functions/get-applicationenvironment.ps1 b/d365fo.tools/internal/functions/get-applicationenvironment.ps1 index 019445f3..c2fba8d3 100644 --- a/d365fo.tools/internal/functions/get-applicationenvironment.ps1 +++ b/d365fo.tools/internal/functions/get-applicationenvironment.ps1 @@ -21,6 +21,7 @@ function Get-ApplicationEnvironment { $AOSPath = Join-Path $script:ServiceDrive "\AOSService\webroot\bin" Write-PSFMessage -Level Verbose -Message "Testing if we are running on a AOS server or not." + $isUDE = $false if (-not (Test-Path -Path $AOSPath -PathType Container)) { Write-PSFMessage -Level Verbose -Message "The machine is NOT an AOS server." @@ -28,8 +29,20 @@ function Get-ApplicationEnvironment { Write-PSFMessage -Level Verbose -Message "Testing if we are running on a BI / MR server or not." if (-not (Test-Path -Path $MRPath -PathType Container)) { - Write-PSFMessage -Level Verbose -Message "It seems that you ran this cmdlet on a machine that doesn't have the assemblies needed to obtain system details. Most likely you ran it on a personal workstation / personal computer." - return + Write-PSFMessage -Level Verbose -Message "The machine is NOT a BI/MR server" + $RegSplat = @{ + Path = "HKCU:\Software\Microsoft\Dynamics\AX7\Development\Configurations" + Name = "FrameworkDirectory" + } + $frameworkDirectoryRegValue = $( if (Test-RegistryValue @RegSplat) { Get-ItemPropertyValue @RegSplat } else { "" } ) + $BasePath = Join-Path $frameworkDirectoryRegValue "bin" + if (-not (Test-Path -Path $BasePath -PathType Container)) { + Write-PSFMessage -Level Verbose -Message "It seems that you ran this cmdlet on a machine that doesn't have the assemblies needed to obtain system details. Most likely you ran it on a personal workstation / personal computer." + return + } + Write-PSFMessage -Level Verbose -Message "The machine is a unified development environment" + $isUDE = $true + $null = $Files2Process.Add((Join-Path $BasePath "Microsoft.Dynamics.AX.Authentication.Instrumentation.dll")) } else { Write-PSFMessage -Level Verbose -Message "The machine is a BI / MR server." @@ -59,6 +72,60 @@ function Get-ApplicationEnvironment { Write-PSFMessage -Level Verbose -Message "All assemblies loaded. Getting environment details." $environment = [Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory]::GetApplicationEnvironment() + if ($isUDE) { + # In case of unified development environments, the system information returned by the assemblies is lacking. + # In this case, the .NET object gets replaced with a PowerShell object that contains the necessary information. + $environment = Initialize-UnifiedDevelopmentEnvironment -environment $environment + } $environment +} + +function Initialize-UnifiedDevelopmentEnvironment { + [CmdletBinding()] + param ( + [Object] + $environment + ) + + $RegSplat = @{ + Path = "HKCU:\Software\Microsoft\Dynamics\AX7\Development\Configurations" + Name = "FrameworkDirectory" + } + $frameworkDirectoryRegValue = $( if (Test-RegistryValue @RegSplat) { Get-ItemPropertyValue @RegSplat } else { "" } ) + $RegSplat.Name = "CurrentMetadataConfig" + $metadataConfigFileRegValue = $( if (Test-RegistryValue @RegSplat) { Get-ItemPropertyValue @RegSplat } else { "" } ) + $metadataConfig = Get-Content -Path $metadataConfigFileRegValue -Raw | ConvertFrom-Json + + $psEnvironment = New-Object -TypeName PSObject -Property @{ + Aad = @{ + TenantDomainGUID = $environment.Aad.TenantDomainGUID # TODO mapped to $Script.TenantId + } + Aos = @{ + AppRoot = $environment.Aos.AppRoot # TODO mapped to $Script.AOSPath; is usually */AOSService/webroot + PackageDirectory = $frameworkDirectoryRegValue # aka the PackagesLocalDirectory + MetadataDirectory = $metadataConfig.ModelStoreFolder # TODO on UDE, this is different from the PackagesLocalDirectory + } + DataAccess = @{ + # TODO all values are empty on UDE + DbServer = $environment.DataAccess.DbServer + Database = $environment.DataAccess.Database + SqlUser = $environment.DataAccess.SqlUser + SqlPwd = $environment.DataAccess.SqlPwd + } + Common = @{ + BinDir = $frameworkDirectoryRegValue # aka the PackagesLocalDirectory + DevToolsBinDir = $frameworkDirectoryRegValue + '\bin' + IsOneboxEnvironment = $true # TODO check what this controls, maybe $false is better for UDE? + } + Monitoring = @{ + MARole = $environment.Monitoring.MARole + } + Infrastructure = @{ + HostName = "UnifiedDevelopmentEnvironment" # TODO Ugly solution to identify UDE + HostUrl = $environment.Infrastructure.HostUrl + } + } + + $psEnvironment } \ No newline at end of file diff --git a/d365fo.tools/internal/scripts/enums.ps1 b/d365fo.tools/internal/scripts/enums.ps1 index c669c79b..a499cbc9 100644 --- a/d365fo.tools/internal/scripts/enums.ps1 +++ b/d365fo.tools/internal/scripts/enums.ps1 @@ -4,6 +4,7 @@ AzureHostedTier1 MSHostedTier1 MSHostedTier2 + UnifiedDevelopmentEnvironment } enum ServerRole { diff --git a/d365fo.tools/internal/scripts/variables.ps1 b/d365fo.tools/internal/scripts/variables.ps1 index 4bcd088f..fd20c62c 100644 --- a/d365fo.tools/internal/scripts/variables.ps1 +++ b/d365fo.tools/internal/scripts/variables.ps1 @@ -78,6 +78,9 @@ elseif ($environment.Infrastructure.HostName -like "*sandbox.ax.dynamics.com*") elseif ($environment.Infrastructure.HostName -like "*sandbox.operations.*dynamics.com*") { $Script:EnvironmentType = [EnvironmentType]::MSHostedTier2 } +elseif ($environment.Infrastructure.HostName -eq "UnifiedDevelopmentEnvironment") { + $Script:EnvironmentType = [EnvironmentType]::UnifiedDevelopmentEnvironment +} $Script:Url = $environment.Infrastructure.HostUrl $Script:DatabaseUserName = $dataAccess.SqlUser