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

A combination of dotnet build and dotnet publish --no-build -p:PublishSingleFile=true does not work in .net8.0 #37367

Open
goldcode opened this issue Dec 6, 2023 · 4 comments
Assignees
Labels
Area-NetSDK needs team triage Requires a full team discussion

Comments

@goldcode
Copy link

goldcode commented Dec 6, 2023

Describe the bug

After migrating from .net6.0 to .net8.0, our builds fail when publishing with PublishSingleFile using
dotnet publish --no-build -r win-x64 --configuration Debug -p:PublishSingleFile=true --output ./publish

we get following error:

11>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1038,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [E:\Software\trunk\Applications\test\test.csproj]

11>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1038,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'E:\Software\trunk\Applications\test\obj\Release\net8.0-windows\win-x64\singlefilehost.exe'. [E:\Software\trunk\Applications\test\test.csproj]

To Reproduce

Fails

  • AppHost.exe is created instead of SingleFile.exe under \obj\Release\net8.0-windows\win-x64\
  • Under dotNet6.0, singleFile.exe is created.
mkdir Fails
cd Fails
dotnet new console
dotnet restore -r win-x64
dotnet build --no-restore -p:PublishSingleFile=true --configuration Release
dotnet publish --no-restore  --no-build -r win-x64 --configuration Release -p:PublishSingleFile=true --output ./publish

Works

what currently works is unified building and publishing.

mkdir Works
cd Works
dotnet new console
dotnet publish -r win-x64 --configuration Release -p:PublishSingleFile=true --output ./publish

I would presume dotnet build does not respect the project property PublishSingleFile and creates an apphost.exe (instead of singlehost.exe) in obj\Release\net6.0-windows\win-x64\

Further technical details

.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.8d38d0cc

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

.NET workloads installed:
Workload version: 8.0.100-manifests.8d38d0cc
There are no installed workloads to display.

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
5.0.414 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]
6.0.408 [C:\Program Files\dotnet\sdk]
7.0.400 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Environment variables:
Not set

global.json file:
Not found

Visual Studio

Microsoft Visual Studio Professional 2022 (3)
Version 17.8.2
VisualStudio.17.Release/17.8.2+34322.80
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Dec 6, 2023
@Vogel612
Copy link

Vogel612 commented Dec 6, 2023

This is IMO likely to have a very similar cause to #37352

@IMDiSc
Copy link

IMDiSc commented Dec 13, 2023

We are experiencing the same behavior.
Initially we were on .NET 7, with the exact same problem.

The solution however mentioned here solved it for us.

A few days ago the project got upgraded to .NET 8 and the publish step failed initially with the following error:
error NETSDK1112: The runtime pack for Microsoft.NETCore.App.Runtime.win-x64 was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'win-x64'.

I then attempted to add the argument --runtime win-x64 to the dotnet restore step in our build and again ended up with the error message above.

We build with the following command:

dotnet build <proj> --configuration Release -p:PublishSingleFile=true

We publish with the following command:

dotnet publish <proj> --no-build --configuration "Release" -p:PublishProfile="<path to pubxml>" -p:PublishDir="<path to dir>" -p:SolutionDir="../"

Contents of pubxml:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121
-->
<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <!-- Not used by CLI, only VS -->
    <Platform>Any CPU</Platform>
    <!-- Not used by CLI -->
    <PublishDir>bin\Release\net8.0\win-x64\publish\win-x64\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net8.0</TargetFramework>
    <!-- Not used by CLI -->
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <!-- Not used by CLI -->
    <SelfContained>true</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
    <PublishTrimmed>false</PublishTrimmed>
  </PropertyGroup>
</Project>

So in short, this worked for .NET 7 but no longer works for .NET 8

eugenelepekhin added a commit to eugenelepekhin/Fusion that referenced this issue Dec 29, 2023
Note I can't upgrade it to .net 8 as the bug below prevents the build.
dotnet/sdk#37367
@goldcode
Copy link
Author

goldcode commented Jan 9, 2024

I managed to created a single file exe using the property <SelfContained>true</SelfContained> I can also verify that recommended property PublishSelfContained didn't work for me.

Also when building in studio, you may need to manually delete obj and bin folders before building. make sure you don't have any autogenerated obj folders just before building. Presumably the visual studio/msbuild toolset watches for csproj file for changes (like editing project properties) and updates the obj folder.

like so (WPF App):

<Project>
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <UseWPF>true</UseWPF>
        <PublishSingleFile>true</PublishSingleFile>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <PlatformTarget>x64</PlatformTarget>
        <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
        <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
        <DebugType>embedded</DebugType>
        <DebugSymbols>true</DebugSymbols>
        <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
        <SelfContained>true</SelfContained>
    </PropertyGroup>
</Project>

@dehghani-mehdi
Copy link

dehghani-mehdi commented Feb 7, 2024

Same problem here, in my case, this command dotnet publish -c Release works, but if I add -p:PublishSingleFile=true or -r win-x64 I get the following error:

error NETSDK1047: Assets file '...\obj\project.assets.json' doesn't have a target for 'net8.0/win-x64'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. [....csproj]

eugenelepekhin added a commit to eugenelepekhin/Fusion that referenced this issue Mar 15, 2024
@MiYanni MiYanni added needs team triage Requires a full team discussion and removed untriaged Request triage from a team member type-investigation labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK needs team triage Requires a full team discussion
Projects
None yet
Development

No branches or pull requests

5 participants