Skip to content

dotnet publish with --no-build and PublishSingleFile fails with "Could not find file singlefilehost.exe" error #17526

Open
@antonyoni

Description

@antonyoni

Description

Running the following on Windows 10 or Server Core 2019:

mkdir test
cd test
dotnet new console
dotnet restore -r win-x64
dotnet build --no-restore -r win-x64 --configuration Debug
dotnet publish --no-build -r win-x64 --configuration Debug -p:PublishSingleFile=true --output ./publish

results in the following error message (truncated):

The "GenerateBundle" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'D:\dev\test\obj\Debug\net5.0\win-x64\singlefilehost.exe'. 

Removing the --no-build parameter or using --no-restore fixes the issue.

Configuration

  • .NET 5.0.101
  • Windows 10.0.19042

Can also be reproduced on docker images:

  • mcr.microsoft.com/dotnet/sdk:5.0
  • mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019

Other information

Full error messages / stack trace:

C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: System.IO.FileNotFoundException: Could not find file 'D:\dev\test\obj\Debug\net5.0\win-x64\singlefilehost.exe'. [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: File name: 'D:\dev\test\obj\Debug\net5.0\win-x64\singlefilehost.exe' [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.BinaryUtils.CopyFile(String sourcePath, String destinationPath) [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:\dev\test\test.csproj]
C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\dev\test\test.csproj]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions