Skip to content

Publish with --no-build --no-restore fails when using AOT in .NET 10 #51766

@hojmark

Description

@hojmark

Description

Separate restore/build and publish steps fails when using AOT in .NET 10. This worked in .NET 9 and is thus a regression.

I have prepared a minimal example at https://github.com/hojmark/dotnet-publish-aot-regression with two branches:

  • main (using net10.0 TFM)
  • dotnet9 (using net9.0 TFM)

The TFM in the project file is the only difference between the two branches.

Furthermore there's a GitHub workflow that illustrates the issue. The same workflow is successful when run on the dotnet9 branch while it fails on the main branch.

Successful run (.NET 9)

Run dotnet build
  Determining projects to restore...
  Restored /home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/dotnet-publish-aot-regression.csproj (in 1.83 sec).
  dotnet-publish-aot-regression -> /home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/bin/Debug/net9.0/dotnet-publish-aot-regression.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:08.48

Run dotnet publish --runtime linux-x64 --self-contained --no-restore --no-build
  Generating native code
  dotnet-publish-aot-regression -> /home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/bin/Release/net9.0/linux-x64/publish/

Failed run (.NET 10)

Run dotnet build
  Determining projects to restore...
  Restored /home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/dotnet-publish-aot-regression.csproj (in 1.74 sec).
  dotnet-publish-aot-regression -> /home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/bin/Debug/net10.0/dotnet-publish-aot-regression.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:09.01

Run dotnet publish --runtime linux-x64 --self-contained --no-restore --no-build
/home/runner/.nuget/packages/microsoft.dotnet.ilcompiler/10.0.0/build/Microsoft.NETCore.Native.Publish.targets(70,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/dotnet-publish-aot-regression.csproj]

Reproduction Steps

Create dotnet-publish-aot-regression.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <PublishAot>true</PublishAot>
    <RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
  </PropertyGroup>

</Project>

Create Program.cs

System.Console.WriteLine("Hello, World!");

Build (and implicitly restore)

dotnet build

Publish

dotnet publish --runtime linux-x64 --self-contained --no-restore --no-build

Expected behavior

The project is published.

Actual behavior

The project fails to publish with the following error:

/home/runner/.nuget/packages/microsoft.dotnet.ilcompiler/10.0.0/build/Microsoft.NETCore.Native.Publish.targets(70,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/home/runner/work/dotnet-publish-aot-regression/dotnet-publish-aot-regression/dotnet-publish-aot-regression.csproj]

Regression?

Worked in .NET 9.

Known Workarounds

Skip the --no-restore --no-build flags on the publish command. This avoids the failure, but it also makes separating the build steps (and the flags themselves) pointless.

Configuration

.NET 10.0.100
Ubuntu 24.04.3 x64 (GitHub runner)
Fedora 43 x64 (local workstation)

Other information

Peculiarity
On GitHub’s Ubuntu runners, the publish step consistently fails when using the --no-restore --no-build flags. On my local workstation (Fedora), if I perform a single successful publish without these flags, any subsequent publishes with the flags succeed. This remains true even after deleting the entire project directory and re-cloning the repository. I have verified this on two separate Fedora workstations.

My suspicion is that Ubuntu would behave similarly if state were preserved, but GitHub runners of course provide a clean environment each time.

This suggests that something outside the project directory is being modified after the first successful publish, though I have absolutely no idea what that might be?

Or maybe I’ve just made two faulty observations. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-NativeAOTNative AOT compilationuntriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions