Since Powershell Core supports Linux, you might want to test your Powershell Module if it works on Linux as it works on Windows. You could setup a virtual machine, which is a litte time consuming and cumbersome. You could use a continous integration service like AppVeyor which does not allow to debug if the test fails.
Another option would be Docker. But anyway i tested the Windows Linux Subsystem (WLS) and it’s pretty good!
The installation is not that complicated. You install Ubuntu, Powershell, configure the environment and finally install Dotnet Core.
The Linux Subsystem and Ubuntu
First you have to enable the WSL, which can be done using this short Powershell command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Then you have to install a Linux distribution that uses the WLS from the Microsoft Store. I used Ubuntu since it’s easy to install Powershell Core on it. Then it should look like this:
You can test it if you type
ubuntu into a Integrated Terminal in VSCode. On the first use it will be initialized and you have to define a username and password. A detailed description can be found in "Windows Subsystem for Linux Installation Guide for Windows 10".
The next step is to install Powershell Core in Ubuntu.
Since Ubuntu from the Microsoft Store is the latest version with long-term support, we have to install the build for Ubuntu 18.04.
We download the Microsoft repository GPG keys:
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
Then we register the Microsoft repository GPG keys:
sudo dpkg -i packages-microsoft-prod.deb
Then we update the package management system:
sudo apt-get update
And finally we install the powershell package:
sudo apt-get install -y powershell
Finally we can test it with the command:
These steps can be found in "Installing PowerShell Core on Linux".
Since we work mostly with Powershell in Ubuntu, we change the our default shell to Powershell:
chsh -s /usr/bin/pwsh
To test this change, we close the terminal and restart Ubuntu. The result should look like this:
Dotnet Core with it’s dependencies can be installed using the following command:
sudo apt-get install dotnet-sdk-2.2
Development and Build
You can access the data from your Windows filesystem for example:
Since i use some Powershell Modules for development, i have to install InvokeBuild for my build script and Pester for my unit tests:
Install-Module InvokeBuild -Scope CurrentUser Install-Module Pester -Scope CurrentUser
Now everything is ready to build and test:
Invoke-Build Clean Invoke-Build Build Invoke-Build Test
Dein KommentarAn Diskussion beteiligen?
Hinterlasse uns Deinen Kommentar!