Unlike C# projects that can live on one VS solution and be "Packed for shipment", In PowerShell we have nothing to compile. It's a blessing in a way but it can also be a pain as for maintaining the common files needed for the app to run.
Here is what we need for our app to run:
Create your project's folder. Name it whatever you want.
Two "Material Design In Xaml" library (dll) files
PowerShell script file(s)
Xaml file
Configuration file (optionally)
Resources folder containing stuff like media files, fonts etc.
Lets talk about those files for a moment.
The two dll files are precompiled libraries that can be downloaded from MaterialDesignInXAML project. You can either download them from my GitHub (in the assembly folder) or pick them up yourself from two locations:
MaterialDesignThemes.Wpf.dll file can be downloaded from the NuGet package. At NuGet site search for MaterialDesignThemes and you'll get the latest release. Download the package and the file will be in 'lib\452' folder.
MaterialDesignColors and MaterialDesignThemes.Wpf dll files can be found in the DemoApp inside the 'net472' folder
If you know your way on VS you can download the whole toolkit source here and compile those dlls yourself. This is the preferable option because you'll get the latest version as it is being maintained frequently, but again, you have to know how to work with Visual Studio solutions.
So after you download the DemoApp, create a new folder called Assembly inside your project's folder and copy the two files named "MaterialDesignColors.dll" and "MaterialDesignThemes.Wpf.dll" to the newly created Assembly folder.
After downloading the dll files you should always unblock them! If you won't do that, your app will error out. This should do the trick:
Get-ChildItem C:\MyPSFolder\MyApp\Assembly\*.dll | Unblock-File
Remember to check for the latest MDIX dll versions regularly. Newer versions contain many bug fixes and improvements.
PS1 file or files will be your script's files. No need for a module nor a manifest. It is an app and we intend to use it as such. You can, however, add it to your personal module if you have one. You can just create and expose a function that runs the ps1 file. But remember that we must always make our apps portable, that is, keeping the ability to zip the whole project and send it to the user or put is in a shared folder and let multiple users run it from a single location.
The Xaml file is a single file. Yeah. I know, it's not like a C# WPF solution where you have multiple files like app.xaml, mainWindow.xaml plus usercontrols etc.
In PowerShell the script has to load the whole Xaml design at the beginning before it opens the window. Unless you need to open another window, you will only maintain one Xaml file per app.
In PowerShell we can also embed the Xaml part INSIDE our ps1 file, but in my opinion it can make the ps1 file huge and hard to read and maintain.
Configuration file can be in any standard format such as Json, XML, CSV
It usually contains the app's parameters and can store the user's preferences.
In your project's folder create another folder named Resources. This folder will contain your logo, pictures, videos etc. and basically any other file needed in your app.
This is how your project's skeleton should look like (the ps1,xaml,config files will be created once you'll start working on your project):
The pain that I was referring to at the beginning of this post is that once a new version of any library has been released you will want to deploy it in all your existing projects and also test them. It's complicated, but I'm currently working on a nice solution for that. Hope I can post something about it soon.
Well... it's time for some coding. See ya on my next post
Comentários