I have a PowerShell module written in C#. Recently I upgraded it to .NET 8. My project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AssemblyName>MyAssemblyName</AssemblyName>
<Nullable>enable</Nullable>
<Version>0.0.0</Version>
<AssemblyVersion>0.0.0</AssemblyVersion>
<SelfContained>true</SelfContained>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Path\To\Domain\Project.csproj" />
</ItemGroup>
</Project>
I publish it like this:
dotnet publish $projectFile --self-contained --configuration Release --output C:\Some\Path
The module works fine in PowerShell 7.4 but does not work in PowerShell 7.2. Import-Module always fails with this error:
Import-Module: Could not load file or assembly 'System.Console, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (0x80131621)
Is this expected? When I publish as self-contained, I expect it will work without a need to upgrade PowerShell. Is the expectation wrong?
PrivateAssets="all"for the package reference of the powershell SDK.