Skip to content

Commit 0059698

Browse files
committed
Fix bad setup in DeploymentSession for the compatibility pathway.
1 parent 1151a76 commit 0059698

20 files changed

Lines changed: 7 additions & 10 deletions

src/PSADT/PSAppDeployToolkit/Foundation/DeploymentSession.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,6 @@ public DeploymentSession(IReadOnlyDictionary<string, object>? parameters = null,
250250
}
251251
}
252252
}
253-
if (compatibilityMode == true)
254-
{
255-
if (SessionState is null)
256-
{
257-
throw new InvalidOperationException("SessionState is not available to set compatibility mode variables.");
258-
}
259-
Settings |= DeploymentSettings.CompatibilityMode;
260-
}
261253
if (noExitOnClose == true)
262254
{
263255
Settings |= DeploymentSettings.NoExitOnClose;
@@ -636,7 +628,7 @@ public DeploymentSession(IReadOnlyDictionary<string, object>? parameters = null,
636628
}
637629

638630
// Announce session instantiation mode.
639-
if (Settings.HasFlag(DeploymentSettings.CompatibilityMode))
631+
if (compatibilityMode == true)
640632
{
641633
WriteLogEntry($"[{appDeployToolkitName}] session mode is [Compatibility]. This mode is for the transition of v3.x scripts and is not for new development.", LogSeverity.Warning);
642634
WriteLogEntry("Information on how to migrate this script to Native mode is available at [https://psappdeploytoolkit.com/].", LogSeverity.Warning);
@@ -1002,8 +994,12 @@ public DeploymentSession(IReadOnlyDictionary<string, object>? parameters = null,
1002994

1003995
// Export session's public variables to the user's scope. For these, we can't capture the Set-Variable
1004996
// PassThru data as syntax like `$var = 'val'` constructs a new PSVariable every time.
1005-
if (Settings.HasFlag(DeploymentSettings.CompatibilityMode) && SessionState is not null)
997+
if (compatibilityMode == true)
1006998
{
999+
if (SessionState is null)
1000+
{
1001+
throw new InvalidOperationException("SessionState is not available to set compatibility mode variables.");
1002+
}
10071003
foreach (PropertyInfo property in typeof(DeploymentSession).GetProperties())
10081004
{
10091005
SessionState.PSVariable.Set(new(property.Name, property.GetValue(this)));
@@ -1012,6 +1008,7 @@ public DeploymentSession(IReadOnlyDictionary<string, object>? parameters = null,
10121008
{
10131009
SessionState.PSVariable.Set(new(field.Name, field.GetValue(this)));
10141010
}
1011+
Settings |= DeploymentSettings.CompatibilityMode;
10151012
}
10161013

10171014

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)