Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class ApplicationInsightsTelemetry

// The path to the semaphore file which enables telemetry
private static string TelemetrySemaphoreFilePath = Path.Combine(
Utils.GetApplicationBase(Utils.DefaultPowerShellShellID),
Utils.DefaultPowerShellAppBase,
TelemetrySemaphoreFilename);

// Telemetry client to be reused when we start sending more telemetry
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ internal static bool IsInbox
if (IsNanoServer || IsIoT)
{
_isInbox = string.Equals(
Utils.GetApplicationBase(Utils.DefaultPowerShellShellID),
Utils.DefaultPowerShellAppBase,
Utils.GetApplicationBaseFromRegistry(Utils.DefaultPowerShellShellID),
StringComparison.OrdinalIgnoreCase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ internal void Remove(string formatFile)
/// <returns></returns>
public static FormatTable LoadDefaultFormatFiles()
{
string shellId = Utils.DefaultPowerShellShellID;
string psHome = Utils.GetApplicationBase(shellId);
string psHome = Utils.DefaultPowerShellAppBase;
List<string> defaultFormatFiles = new List<string>();
if (!string.IsNullOrEmpty(psHome))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private static bool ProcessBuiltin(
{
var builtInGenerators = new Dictionary<string, Tuple<bool, TypeGenerator>>(StringComparer.OrdinalIgnoreCase);

var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var psHome = Utils.DefaultPowerShellAppBase;

builtInGenerators.Add(Path.Combine(psHome, "Certificate.format.ps1xml"), GetBuiltin(false, Certificate_Format_Ps1Xml.GetFormatData));
builtInGenerators.Add(Path.Combine(psHome, "Diagnostics.Format.ps1xml"), GetBuiltin(false, Diagnostics_Format_Ps1Xml.GetFormatData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal string ApplicationBase
string psHome = null;
try
{
psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
psHome = Utils.DefaultPowerShellAppBase;
}
catch (System.Security.SecurityException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static void Init()
{
// Building the catalog is expensive, so force that to happen early on a background thread, and do so
// on a file we are very likely to read anyway.
var pshome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var pshome = Utils.DefaultPowerShellAppBase;
var unused = SecuritySupport.IsProductBinary(Path.Combine(pshome, "Modules", "Microsoft.PowerShell.Utility", "Microsoft.PowerShell.Utility.psm1"));
});

Expand Down Expand Up @@ -1597,7 +1597,7 @@ private static InitialSessionState CreateRestrictedForRemoteServer()

private static void IncludePowerShellCoreFormats(InitialSessionState iss)
{
string psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
string psHome = Utils.DefaultPowerShellAppBase;
if (string.IsNullOrEmpty(psHome))
{
return;
Expand Down Expand Up @@ -4207,7 +4207,7 @@ internal PSSnapInInfo ImportPSSnapIn(PSSnapInInfo psSnapInInfo, out PSSnapInExce

// We skip checking if the file exists when it's in $PSHOME because of magic
// where we have the former contents of those files built into the engine directly.
var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var psHome = Utils.DefaultPowerShellAppBase;

foreach (string file in psSnapInInfo.Types)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1768,11 +1768,11 @@ private void SetModuleBaseForEngineModules(string moduleName, System.Management.
{
if (m.Name.Equals(moduleName, StringComparison.OrdinalIgnoreCase))
{
m.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
m.SetModuleBase(Utils.DefaultPowerShellAppBase);
// Also set ModuleBase for nested modules of Engine modules
foreach (var nestedModule in m.NestedModules)
{
nestedModule.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
nestedModule.SetModuleBase(Utils.DefaultPowerShellAppBase);
}
}
}
Expand All @@ -1781,11 +1781,11 @@ private void SetModuleBaseForEngineModules(string moduleName, System.Management.
{
if (m.Name.Equals(moduleName, StringComparison.OrdinalIgnoreCase))
{
m.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
m.SetModuleBase(Utils.DefaultPowerShellAppBase);
// Also set ModuleBase for nested modules of Engine modules
foreach (var nestedModule in m.NestedModules)
{
nestedModule.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
nestedModule.SetModuleBase(Utils.DefaultPowerShellAppBase);
}
}
}
Expand Down
58 changes: 29 additions & 29 deletions src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2768,19 +2768,19 @@ internal PSModuleInfo LoadModuleManifest(
}

if (scriptsToProcess != null)
{
Version savedBaseMinimumVersion = BaseMinimumVersion;
Version savedBaseMaximumVersion = BaseMaximumVersion;
Version savedBaseRequiredVersion = BaseRequiredVersion;
{
Version savedBaseMinimumVersion = BaseMinimumVersion;
Version savedBaseMaximumVersion = BaseMaximumVersion;
Version savedBaseRequiredVersion = BaseRequiredVersion;
Guid? savedBaseGuid = BaseGuid;

try
{
BaseMinimumVersion = null;
BaseMaximumVersion = null;
BaseRequiredVersion = null;
BaseGuid = null;
try
{
BaseMinimumVersion = null;
BaseMaximumVersion = null;
BaseRequiredVersion = null;
BaseGuid = null;

foreach (string scriptFile in scriptsToProcess)
{
bool found = false;
Expand Down Expand Up @@ -2812,14 +2812,14 @@ internal PSModuleInfo LoadModuleManifest(
module.ExportedAliases[detectedAlias].Definition);
}
}
}
}
finally
{
BaseMinimumVersion = savedBaseMinimumVersion;
BaseMaximumVersion = savedBaseMaximumVersion;
BaseRequiredVersion = savedBaseRequiredVersion;
BaseGuid = savedBaseGuid;
}
}
finally
{
BaseMinimumVersion = savedBaseMinimumVersion;
BaseMaximumVersion = savedBaseMaximumVersion;
BaseRequiredVersion = savedBaseRequiredVersion;
BaseGuid = savedBaseGuid;
}
}

Expand Down Expand Up @@ -4123,10 +4123,10 @@ internal static PSModuleInfo LoadRequiredModule(ExecutionContext context,
Dictionary<ModuleSpecification, List<ModuleSpecification>> requiredModules = new Dictionary<ModuleSpecification, List<ModuleSpecification>>(new ModuleSpecificationComparer());
if (currentModule != null)
{
requiredModules.Add(new ModuleSpecification(currentModule), new List<ModuleSpecification> { requiredModuleSpecification });
requiredModules.Add(new ModuleSpecification(currentModule), new List<ModuleSpecification> { requiredModuleSpecification });
}
if (requiredModuleSpecification != null)
{
if (requiredModuleSpecification != null)
{
requiredModules.Add(requiredModuleSpecification, new List<ModuleSpecification>(requiredModuleInfo.RequiredModulesSpecification));
}

Expand Down Expand Up @@ -4498,13 +4498,13 @@ private static bool HasRequiredModulesCyclicReference(ModuleSpecification curren
// Only add if this required module has nested required modules (meaning, it could lead to a circular reference)
if (list.Count > 0)
{
nonCyclicRequiredModules.Add(requiredModuleSpecification, list);
// We always need to check against the module specification and not the file name
if (HasRequiredModulesCyclicReference(requiredModuleSpecification, list, availableModules, nonCyclicRequiredModules, out error))
{
return true;
nonCyclicRequiredModules.Add(requiredModuleSpecification, list);
// We always need to check against the module specification and not the file name
if (HasRequiredModulesCyclicReference(requiredModuleSpecification, list, availableModules, nonCyclicRequiredModules, out error))
{
return true;
}
}
}
}
}
}
Expand Down Expand Up @@ -4680,7 +4680,7 @@ private bool GetListOfFilesFromData(

if (listOfStrings != null)
{
var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var psHome = Utils.DefaultPowerShellAppBase;
string alternateDirToCheck = null;
if (moduleBase.StartsWith(psHome, StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ internal static string GetPSHomeModulePath()

try
{
string psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
string psHome = Utils.DefaultPowerShellAppBase;
if (!string.IsNullOrEmpty(psHome))
{
// Win8: 584267 Powershell Modules are listed twice in x86, and cannot be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ internal static IEnumerable<CommandInfo> GetMatchingCommands(string pattern, Exe
tempModuleInfo = new PSModuleInfo(moduleShortName, modulePath, null, null);
if (InitialSessionState.IsEngineModule(moduleShortName))
{
tempModuleInfo.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
tempModuleInfo.SetModuleBase(Utils.DefaultPowerShellAppBase);
}

//moduleVersionRequired is bypassed by FullyQualifiedModule from calling method. This is the only place where guid will be involved.
Expand Down
5 changes: 2 additions & 3 deletions src/System.Management.Automation/engine/TypeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3440,8 +3440,7 @@ public static List<String> GetDefaultTypeFiles()
string typesFilePath = string.Empty;
string typesV3FilePath = string.Empty;

string shellId = Utils.DefaultPowerShellShellID;
var psHome = Utils.GetApplicationBase(shellId);
var psHome = Utils.DefaultPowerShellAppBase;
if (!string.IsNullOrEmpty(psHome))
{
typesFilePath = Path.Combine(psHome, "types.ps1xml");
Expand Down Expand Up @@ -4404,7 +4403,7 @@ private bool ProcessIsBuiltIn(string filePath, ConcurrentBag<string> errors, out
var result = false;
var errorCount = errors.Count;

var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var psHome = Utils.DefaultPowerShellAppBase;
if (string.Equals(Path.Combine(psHome, "types.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase))
{
ProcessTypeData(filePath, errors, Types_Ps1Xml.Get());
Expand Down
18 changes: 5 additions & 13 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,12 @@ internal static string GetApplicationBaseFromRegistry(string shellId)
}
#endif

/// <summary>
/// Gets the application base for current monad version
/// </summary>
/// <returns>
/// applicationbase path for current monad version installation
/// </returns>
/// <exception cref="SecurityException">
/// if caller doesn't have permission to read the key
/// </exception>
internal static string DefaultPowerShellAppBase { get; } = GetApplicationBase(DefaultPowerShellShellID);

internal static string GetApplicationBase(string shellId)
{
#if CORECLR
// Use the location of SMA.dll as the application base
// Assembly.GetEntryAssembly and GAC are not in CoreCLR.
// Use the location of SMA.dll as the application base.
Assembly assembly = typeof(PSObject).GetTypeInfo().Assembly;
return Path.GetDirectoryName(assembly.Location);
#else
Expand Down Expand Up @@ -312,7 +304,7 @@ private static string[] GetProductFolderDirectories()
List<string> baseDirectories = new List<string>();

// Retrieve the application base from the registry
string appBase = GetApplicationBase(DefaultPowerShellShellID);
string appBase = Utils.DefaultPowerShellAppBase;
if (!string.IsNullOrEmpty(appBase))
{
baseDirectories.Add(appBase);
Expand Down Expand Up @@ -381,7 +373,7 @@ internal static bool IsUnderProductFolder(string filePath)
/// </summary>
internal static bool IsRunningFromSysWOW64()
{
return Utils.GetApplicationBase(Utils.DefaultPowerShellShellID).Contains("SysWOW64");
return DefaultPowerShellAppBase.Contains("SysWOW64");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public sealed class PowerShellProcessInstance : IDisposable
static PowerShellProcessInstance()
{
#if UNIX
s_PSExePath = Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID),
s_PSExePath = Path.Combine(Utils.DefaultPowerShellAppBase,
"powershell");
#else
s_PSExePath = Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID),
s_PSExePath = Path.Combine(Utils.DefaultPowerShellAppBase,
"powershell.exe");
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ private string ConstructPluginContent(out string srcConfigFilePath, out string d
}
}

string destPath = System.IO.Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), "SessionConfig",
string destPath = System.IO.Path.Combine(Utils.DefaultPowerShellAppBase, "SessionConfig",
shellName + "_" + sessionGuid.ToString() + StringLiterals.PowerShellDISCFileExtension);
if (string.Equals(ProcessorArchitecture, "x86", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -3414,7 +3414,7 @@ protected override void ProcessRecord()
_gmsaAccount = _configTable[ConfigFileConstants.GMSAAccount] as string;
}

string destPath = System.IO.Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), "SessionConfig",
string destPath = System.IO.Path.Combine(Utils.DefaultPowerShellAppBase, "SessionConfig",
shellName + "_" + sessionGuid.ToString() + StringLiterals.PowerShellDISCFileExtension);

// If the config file with the same guid name already exists then it would be overwritten.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module,
#if !CORECLR // Side-By-Side directories are not present in OneCore environments.
if (IsSystemModule(module.ModuleName) && Environment.Is64BitOperatingSystem)
{
string path = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID).Replace("System32", "SysWOW64");
string path = Utils.DefaultPowerShellAppBase.Replace("System32", "SysWOW64");

destPaths.Add(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal static Collection<PSSnapInTypeAndFormatErrors> GetFormatAndTypesErrors(
Collection<PSSnapInTypeAndFormatErrors> returnValue = new Collection<PSSnapInTypeAndFormatErrors>();

string baseFolder = GetBaseFolder(runspaceConfiguration, independentErrors);
var psHome = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
var psHome = Utils.DefaultPowerShellAppBase;

// this hashtable will be used to check whether this is duplicated file for types or formats.
HashSet<string> fullFileNameSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/security/Authenticode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private static Signature GetSignatureFromCatalog(string filename)

if (!Signature.CatalogApiAvailable.HasValue)
{
string productFile = Path.Combine(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), "Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psm1");
string productFile = Path.Combine(Utils.DefaultPowerShellAppBase, "Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psm1");
if (signature.Status != SignatureStatus.Valid)
{
if (string.Equals(filename, productFile, StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ internal static Version ReadVersionValue(RegistryKey mshsnapinKey, string name,

internal static void ReadRegistryInfo(out Version assemblyVersion, out string publicKeyToken, out string culture, out string architecture, out string applicationBase, out Version psVersion)
{
applicationBase = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID);
applicationBase = Utils.DefaultPowerShellAppBase;
Dbg.Assert(!string.IsNullOrEmpty(applicationBase),
string.Format(CultureInfo.CurrentCulture, "{0} is empty or null", RegistryStrings.MonadEngine_ApplicationBase));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal static void ReportModuleLoad(PSModuleInfo foundModule)
var companyName = foundModule.CompanyName;
bool couldBeMicrosoftModule =
(modulePath != null &&
(modulePath.StartsWith(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID), StringComparison.OrdinalIgnoreCase) ||
(modulePath.StartsWith(Utils.DefaultPowerShellAppBase, StringComparison.OrdinalIgnoreCase) ||
// The following covers both 64 and 32 bit Program Files by assuming 32bit is just ...\Program Files + " (x86)"
modulePath.StartsWith(Platform.GetFolderPath(Environment.SpecialFolder.ProgramFiles), StringComparison.OrdinalIgnoreCase))) ||
(companyName != null &&
Expand Down