Reputation: 601
I have a file bundled with a powershell binary module. It has a line in the manifest which details the attached file.
# List of all files packaged with this module
FileList = @(".\assets\MoonPhase.sqlite")
This FileList preoperty seems to be pretty useless, just as a note?
List of all files packaged with this module. As with ModuleList, FileList is to assist you as an inventory list, and is not otherwise processed.
How can I then access this file relative the the module root from a cmdlet?
The following seems to be evaluated only when called when the cmndlet is called from a script. Therefore it is not really part of the module but the invocation as the name would suggest.
string path = this.MyInvocation.PSScriptRoot + "\\assets\\MoonPhase.sqlite";
string path = this.MyInvocation.PSCommandPath + "\\assets\\MoonPhase.sqlite";
The following seems a poor choice
string path = @"C:\Users\Me\Path\Project\bin\Debug\netstandard2.0\assets\MoonPhase.sqlite";
Upvotes: 0
Views: 326
Reputation: 601
The FileList Property is available inside the MyInvocation object and the files listed in the manifest have absolute paths.
string path = MyInvocation.MyCommand.Module.FileList
#"C:\\Users\\Me\\Path\\Project\\bin\\Debug\\assets\\MoonPhase.sqlite"
It's an IEnumerable so need to get a string out of it with linq, a loop or by casting.
string path = MyInvocation.MyCommand.Module.FileList.First();
The following is also useful for forming relative paths
string path = MyInvocation.MyCommand.Module.ModuleBase
#"C:\\Users\\Me\\Path\\Project\\bin\\Debug"
string path = MyInvocation.MyCommand.Module.ModuleBase + "\\OtherFile.txt"
#"C:\\Users\\Me\\Path\\Project\\bin\\Debug\\OtherFile.txt"
Upvotes: 1