private void LoadFileIntoModule(PSModuleInfo moduleInfo, Path path) { // prevents accidental loops while loading a module moduleInfo.NestingDepth++; if (moduleInfo.NestingDepth > 10) { var msg = "The module is too deeply nested. A module can be only nested 10 times. Make sure to check" + " the loading order of your module"; throw new PSInvalidOperationException(msg, "Modules_ModuleTooDeeplyNested", ErrorCategory.InvalidOperation); } moduleInfo.Path = path; // update path for nested modules var stringComparer = StringComparer.InvariantCultureIgnoreCase; var ext = path.GetExtension(); if (_scriptExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Script; LoadScriptModule(moduleInfo, path); // actually load the script } else if (_binaryExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Binary; LoadBinaryModule(moduleInfo, path); } else if (_manifestExtensions.Contains(ext, stringComparer)) { moduleInfo.ModuleType = ModuleType.Manifest; LoadManifestModule(moduleInfo, path); } else { var msg = "The extension '" + ext + "' is currently not supported"; throw new PSInvalidOperationException(msg, "Modules_InvalidFileExtension", ErrorCategory.InvalidOperation, null, false); } moduleInfo.ValidateExportedMembers(); }
private void LoadBinaryModule(PSModuleInfo moduleInfo, Path path) { Assembly assembly = Assembly.LoadFrom(path); // load into the local session state of the module moduleInfo.SessionState.Cmdlet.LoadCmdletsFromAssembly(assembly, moduleInfo); // load providers. they aren't scoped, so the SessionState object used doesn't matter _executionContext.SessionState.Provider.Load(assembly, _executionContext, moduleInfo); moduleInfo.ValidateExportedMembers(); // make sure cmdlets get exported }