public TargetApp Initialize(string appModulePath) { if (_isInitialized) { return(this); } if (CmdletHost == null) { throw new NullReferenceException("The host Cmdlet for this Target App was not set before initialization."); } _isInitialized = true; if (string.IsNullOrWhiteSpace(appModulePath) || !appModulePath.EndsWithCaseless(".3pmTarget.psm1") || !File.Exists(appModulePath)) { throw new ArgumentException("Referenced path does not point to a valid pppm Target Application module."); } var meta = Pppm.GetPsMetaComment(File.ReadAllText(appModulePath)); if (meta == null) { throw new ArgumentException("Referenced pppm Target Application module doesn't contain required meta comment."); } Pppm.IsScriptCompatible(meta, ScriptUsage.App, true); ShortName = meta["ShortName"].ToString(); _defaultRepoRef = meta["DefaultRepository"].ToString(); if (!PackageRepository.TryCreateRepository(_defaultRepoRef, out var defRepo)) { throw new ArgumentException($"Cannot gather default repository for {ShortName}."); } DefaultRepository = defRepo; if (meta.TryGetValue("DefaultArchitecture", out var defArchJt)) { DefaultArchitecture = defArchJt.ToObject <Architecture>(); } _appModule = CmdletHost.ImportModule(appModulePath); var vars = _appModule.ExportedVariables; SafeGet(vars, "executable", "$", "variable", out _exePath); SafeGet(vars, "appRoot", "$", "variable", out _appRoot); var funcs = _appModule.ExportedFunctions; SafeGet(funcs, "Get-FolderForPack", "", "function", out _getFolderForPackFunc); SafeGet(funcs, "Get-InstalledPacks", "", "function", out _getInstalledPacksFunc); CmdletHost.RemoveModule(_appModule.Name); return(this); }