Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] allow main to be built with a .NET 8 SDK #16508

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

jonathanpeppers
Copy link
Member

I've been testing our latest .NET 8 release, and I noticed it was not currently possible to build dotnet/maui/main if you only have .NET 8 installed.

The first issue to get past is global.json:

"sdk": {
    "version": "7.0.200",
    "allowPrerelease": true,
    "rollForward": "latestMinor"
}

latestMinor does not allow it to "roll forward" to a .NET 8 SDK as it stops at any 7.0.x version. I changed this to major, so it can use 8.x or future versions. Alternatively we could completely remove the sdk block here, but I thought this was a reasonable change for now.

The next error I got was:

The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\..\tools\net8.0\Microsoft.NET.Build.Tasks.dll. Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

This was quite confusing, but what I found was:

  • dotnet cake -> uses .NET 8 SDK from my system

  • A .NET 7 SDK is provisioned in .\bin\dotnet\

  • An <Exec/> task runs:

  • .\bin\dotnet\dotnet restore src\DotNet\Dependencies\Workloads.csproj which fails

It looks like the issue is the outer/system .NET SDK passes the $MSBuildSDKsPath environment variable. This makes a .NET 7 SDK import .NET 8 MSBuild targets files -- and everything breaks. I could get past this error by clearing the env var. I also fixed the .binlog location for this command, so it goes in artifacts/logs now.

The last issue I found was:

========================================
dotnet-pack-maui
========================================
Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at System.Management.Automation.PSObject..cctor()
--- End of inner exception stack trace ---
at System.Management.Automation.PSObject.get_Properties()
at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(RunspaceCreationEventArgs args)
at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(RunspaceCreationEventArgs args)
at Microsoft.PowerShell.ConsoleHost.CreateRunspace(RunspaceCreationEventArgs runspaceCreationArgs)
at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName, String configurationFilePath)
at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)

It appears that the pwsh .NET global tool basically doesn't run at all on .NET 8 yet?

https://www.nuget.org/packages/PowerShell/7.3.6

This fails in this way (if you have .NET 8):

dotnet pwsh eng/package.ps1

While this one succeeds:

./bin/dotnet/dotnet pwsh eng/package.ps1

I could fix this in MAUI's build by setting ToolPath in dotnet.cake:

DotNetTool("pwsh", new DotNetToolSettings
{
    ToolPath = dotnetPath,
    //...
});

This makes the command use ./bin/dotnet/dotnet pwsh, which works.

This last change we might have to undo/revert on the net8.0 branch until they fix the pwsh global tool.

I've been testing our latest .NET 8 release, and I noticed it was not
currently possible to build dotnet/maui/main if you only have .NET 8
installed.

The first issue to get past is `global.json`:

    "sdk": {
        "version": "7.0.200",
        "allowPrerelease": true,
        "rollForward": "latestMinor"
    }

`latestMinor` does not allow it to "roll forward" to a .NET 8 SDK as it
stops at any `7.0.x` version. I changed this to `major`, so it can use
`8.x` or future versions. Alternatively we could completely remove the
`sdk` block here, but I thought this was a reasonable change for now.

The next error I got was:

    The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\..\tools\net8.0\Microsoft.NET.Build.Tasks.dll. Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
    The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

This was quite confusing, but what I found was:

* `dotnet cake` -> uses .NET 8 SDK from my system

* A .NET 7 SDK is provisioned in `.\bin\dotnet\`

* An `<Exec/>` task runs:

* `.\bin\dotnet\dotnet restore src\DotNet\Dependencies\Workloads.csproj` which fails

It looks like the issue is the outer/system .NET SDK passes the
`$MSBuildSDKsPath` environment variable. This makes a .NET 7 SDK import
.NET 8 MSBuild targets files -- and everything breaks. I could get past
this error by clearing the env var. I also fixed the `.binlog` location
for this command, so it goes in `artifacts/logs` now.

The last issue I found was:

    ========================================
    dotnet-pack-maui
    ========================================
    Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
    at System.Environment.FailFast(System.String, System.Exception)
    at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
    at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
    System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
    ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
    File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
    at System.Management.Automation.PSObject..cctor()
    --- End of inner exception stack trace ---
    at System.Management.Automation.PSObject.get_Properties()
    at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
    at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(RunspaceCreationEventArgs args)
    at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(RunspaceCreationEventArgs args)
    at Microsoft.PowerShell.ConsoleHost.CreateRunspace(RunspaceCreationEventArgs runspaceCreationArgs)
    at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName, String configurationFilePath)
    at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
    at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
    at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)

It appears that the `pwsh` .NET global tool basically doesn't run at all
on .NET 8 yet?

https://www.nuget.org/packages/PowerShell/7.3.6

This fails in this way (if you have .NET 8):

    dotnet pwsh eng/package.ps1

While this one succeeds:

    ./bin/dotnet/dotnet pwsh eng/package.ps1

I could fix this in MAUI's build by setting `ToolPath` in `dotnet.cake`:

    DotNetTool("pwsh", new DotNetToolSettings
    {
        ToolPath = dotnetPath,
        //...
    });

This makes the command use `./bin/dotnet/dotnet pwsh`, which works.

This last change we might have to undo/revert on the `net8.0` branch
until they fix the `pwsh` global tool.
@Eilon Eilon added the area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions label Aug 2, 2023
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 3, 2023 14:55
@PureWeen PureWeen requested review from Redth and rmarinho August 3, 2023 20:00
@mattleibow mattleibow merged commit 3fe5fec into dotnet:main Aug 3, 2023
@jonathanpeppers jonathanpeppers deleted the buildmainwithnet8 branch August 3, 2023 20:16
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants