Merge-Script in Linux

We are currently evaluating the PowerShellProTools PowerShell module in order to package a PowerShell Core script into a self-contained executable for Linux.

We installed the .NET SDK (3.1.301) and PowerShell Core (7.0.2) on an Ubuntu machine. Next up we tried to run the following command:

 Merge-Script -Verbose -Config @{
>> Root = "/home/dr/My.ps1"
>> OutputPath = "/home/dr/My"
>> Package = @{
>> Enabled=$True
>> PowerShellCore=$True
>> }
>> Bundle = @{
>> Enabled=$True
>> Modules=$True
>> }
>> }

It starts working, but fails with:

/usr/share/dotnet/sdk/3.1.301/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [/tmp/bf3bf0c9032740e2b325b3c7638b90d3/My.csproj]
0 Warning(s)
1 Error(s)

Of course we can’t install the .NET Framework 4.6.2 on Linux, we don’t even know why it is trying to use .NET 4.6.2 when we’ve installed .NET Core only.

Can you help us?

Best regards,
D.R.

Can you try this?

Merge-Script -Verbose -Config @{
Root = "/home/dr/My.ps1"
OutputPath = "/home/dr/My"
Package = @{
Enabled=$True
PowerShellVersion= '7.0.2'
DotNetVersion = 'netcoreapp31'
RuntimeIdentifier = 'linux-x64'
}
Bundle = @{
Enabled=$True
Modules=$True
}
}

I tried this and it still fails with a simple:

VERBOSE: Checking license
VERBOSE: OutputPath is /home/dr/My
VERBOSE: Bundling /home/dr/My.ps1
VERBOSE: Packaging /tmp/My.ps1
Merge-Script: Unable to find the specified file.

BTW: I had to use PowerShellVersion 7.0.1, 7.0.2 failed.

I tried to run the same cmdlet in Windows, we don’t need to build the script on Linux we just need it to be executable on Linux .

However, it also fails, with a different error though:

VERBOSE: Checking license
VERBOSE: OutputPath is C:\Temp\MyCore
VERBOSE: OutputPath does not exist. Creating directory.
VERBOSE: Bundling C:\Temp\My.ps1
VERBOSE: Packaging C:\Users\dr\AppData\Local\Temp\My.ps1
VERBOSE: Checking dotnet version.
VERBOSE: 3.1.301

VERBOSE: 3.1.301

VERBOSE: Creating package project.
VERBOSE: Using .NET Framework version: netcoreapp31
VERBOSE:   Determining projects to restore...
  Restored C:\Users\dr\AppData\Local\Temp\3d89977364c04f01ae2ac4fc903fb7c2\My.csproj (in 567 ms).

VERBOSE:   Determining projects to restore...
  Restored C:\Usersdr\AppData\Local\Temp\3d89977364c04f01ae2ac4fc903fb7c2\My.csproj (in 567 ms).

VERBOSE: Packaging C:\Users\dr\AppData\Local\Temp\My.ps1 -> C:\Temp\MyCore\My.exe
VERBOSE: Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\Users\dr\AppData\Local\Temp\3d89977364c04f01ae2ac4fc903fb7c2\My.csproj (in 5,68 sec).
ConsolePowerShellHost.cs(26,13): error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [C:\Users\dr\AppData\Local\Temp\3d89977364c04f01ae2ac4fc903fb7c2\My.csproj]

Merge-Script: Failed to build.

Looks like your trial license dialog gets in the way. Is there a way to obtain a temporary license so we can try the script and see if it works?

Yep. Email me at adam[at]poshtools.com. I’ll have to take a look at some of these issues as well. See if we can smooth this out.

Done :slight_smile:

1 Like