Skip to content

Misleading Compile Error Message - "You must either set PublishSingleFile to false or set UseAppHost to true." #48152

Open
@ThioJoe

Description

@ThioJoe

Describe the bug

I received this error when trying to compile/publish for net9.0-macos:
Applications published to a single-file are required to use the application host. You must either set PublishSingleFile to false or set UseAppHost to true.

However the actual condition that raises this exception is:

<NETSdkError Condition="'$(PublishSingleFile)' == 'true' and '$(UseAppHost)' != 'true' and '$(PublishAot)' != 'true'"
             ResourceName="CannotHaveSingleFileWithoutAppHost" />

Of the condition above, it turns out that in my case the specific problem was this part: '$(PublishAot)' != 'true'" .
Enabling "Publish Native AOT" fixed the problem -- The error went away and it compiled. Despite the error message's description.

TL;DR:

Put simply, the error description does not mention the possibility that Native AOT is the problem, and misleadingly only mentions UseAppHost which wasn't the issue at all, despite Native AOT clearly being in the condition for the exception.


To Reproduce

This is my publish profile:

<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net9.0-windows\publish\osx-arm64\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net9.0-macos</TargetFramework>
    <RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
</Project>

And this line is in the .csproj:
<PublishAot>False</PublishAot>

Exceptions (if any)

Severity	Code	Description	Project	File	Line	Suppression State	Details
Error		Applications published to a single-file are required to use the application host. You must either set PublishSingleFile to false or set UseAppHost to true.	PlexShowSubtitlesOnRewind	c:\program files\dotnet\sdk\9.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets	197		

Further technical details

dotnet info output:

PM> dotnet --info
.NET SDK:
 Version:           9.0.200
 Commit:            90e8b202f2
 Workload version:  9.0.200-manifests.5c4e24dc
 MSBuild version:   17.13.8+cbc39bea8

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.200\

.NET workloads installed:
 [macos]
   Installation Source: SDK 9.0.200, VS 17.14.35906.104
   Manifest Version:    15.2.9180/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.macos\15.2.9180\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: VS 17.14.35906.104
   Manifest Version:    9.0.14/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.14\WorkloadManifest.json
   Install Type:              Msi

 [ios]
   Installation Source: VS 17.14.35906.104
   Manifest Version:    18.2.9180/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.2.9180\WorkloadManifest.json
   Install Type:              Msi

 [android]
   Installation Source: VS 17.14.35906.104
   Manifest Version:    35.0.50/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.50\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: VS 17.14.35906.104
   Manifest Version:    18.2.9180/9.0.100
   Manifest Path:       c:\program files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.2.9180\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.3
  Architecture: x64
  Commit:       831d23e561

.NET SDKs installed:
  9.0.104 [C:\Program Files\dotnet\sdk]
  9.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview
Version 17.14.0 Preview 2.0

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