|
9 | 9 | using Microsoft.PowerShell.EditorServices.Hosting;
|
10 | 10 | using Microsoft.PowerShell.EditorServices.Utility;
|
11 | 11 | using System.Collections.Generic;
|
12 |
| -using System.IO; |
13 | 12 |
|
14 | 13 | namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility
|
15 | 14 | {
|
@@ -166,10 +165,13 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat
|
166 | 165 | {
|
167 | 166 | var profileVariable = new PSObject();
|
168 | 167 |
|
169 |
| - pwsh.AddProfileMemberAndLoadIfExists(profileVariable, nameof(profilePaths.AllUsersAllHosts), profilePaths.AllUsersAllHosts) |
170 |
| - .AddProfileMemberAndLoadIfExists(profileVariable, nameof(profilePaths.AllUsersCurrentHost), profilePaths.AllUsersCurrentHost) |
171 |
| - .AddProfileMemberAndLoadIfExists(profileVariable, nameof(profilePaths.CurrentUserAllHosts), profilePaths.CurrentUserAllHosts) |
172 |
| - .AddProfileMemberAndLoadIfExists(profileVariable, nameof(profilePaths.CurrentUserCurrentHost), profilePaths.CurrentUserCurrentHost); |
| 168 | + var psCommand = new PSCommand() |
| 169 | + .AddProfileLoadIfExists(profileVariable, nameof(profilePaths.AllUsersAllHosts), profilePaths.AllUsersAllHosts) |
| 170 | + .AddProfileLoadIfExists(profileVariable, nameof(profilePaths.AllUsersCurrentHost), profilePaths.AllUsersCurrentHost) |
| 171 | + .AddProfileLoadIfExists(profileVariable, nameof(profilePaths.CurrentUserAllHosts), profilePaths.CurrentUserAllHosts) |
| 172 | + .AddProfileLoadIfExists(profileVariable, nameof(profilePaths.CurrentUserCurrentHost), profilePaths.CurrentUserCurrentHost); |
| 173 | + |
| 174 | + pwsh.InvokeCommand(psCommand); |
173 | 175 |
|
174 | 176 | pwsh.Runspace.SessionStateProxy.SetVariable("PROFILE", profileVariable);
|
175 | 177 | }
|
@@ -200,22 +202,6 @@ public static string GetErrorString(this PowerShell pwsh)
|
200 | 202 | return sb.ToString();
|
201 | 203 | }
|
202 | 204 |
|
203 |
| - private static PowerShell AddProfileMemberAndLoadIfExists(this PowerShell pwsh, PSObject profileVariable, string profileName, string profilePath) |
204 |
| - { |
205 |
| - profileVariable.Members.Add(new PSNoteProperty(profileName, profilePath)); |
206 |
| - |
207 |
| - if (File.Exists(profilePath)) |
208 |
| - { |
209 |
| - var psCommand = new PSCommand() |
210 |
| - .AddScript(profilePath, useLocalScope: false) |
211 |
| - .AddOutputCommand(); |
212 |
| - |
213 |
| - pwsh.InvokeCommand(psCommand); |
214 |
| - } |
215 |
| - |
216 |
| - return pwsh; |
217 |
| - } |
218 |
| - |
219 | 205 | private static StringBuilder AddErrorString(this StringBuilder sb, ErrorRecord error, int errorIndex)
|
220 | 206 | {
|
221 | 207 | sb.Append("Error #").Append(errorIndex).Append(':').AppendLine()
|
|
0 commit comments