Issue Description
After migrating from .Net7 to 8 I have been unable to publish a project with both self contained and produce single file enabled.
Build output gives the error "access to the path 'C:.....\obj\Release\net8.0\win-x64\singlefilehost.exe' is denied"
reproduceable by creating a new .net8 console project and trying to publish with both of those options enabled.
Minimal example project
publishtest.zip
Note that this minimal example works on my Windows 11 home computer but does not work on my work Windows 10 computer or any of my colleagues computers.
Steps to Reproduce
- Create a .Net8 console project
- Create a new publish profile with self contained enabled and target runtime win-x64
- Enable product single file.
- Attempt to publish.
Expected Behavior
Publish works as normal with both options selected.
Actual Behavior
Build started at 10:29...
1>------ Publish started: Project: publishtest, Configuration: Release Any CPU ------
1>Determining projects to restore...
1>Restored C:\Development\publishtest\publishtest.csproj (in 1.19 sec).
1>The "CreateAppHost" task failed unexpectedly.
1>System.AggregateException: One or more errors occurred. ---> System.UnauthorizedAccessException: Access to the path 'C:\Development\publishtest\obj\Release\net8.0\win-x64\singlefilehost.exe' is denied.
1> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1> at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
1> at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
1> at System.IO.FileStream..ctor(String path, FileMode mode)
1> at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.b__1()
1> at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func)
1> at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign)
1> --- End of inner exception stack trace ---
1> at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign)
1> at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
1> at Microsoft.NET.Build.Tasks.TaskBase.Execute()
1> at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1> at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
1>---> (Inner Exception #0) System.UnauthorizedAccessException: Access to the path 'C:\Development\publishtest\obj\Release\net8.0\win-x64\singlefilehost.exe' is denied.
1> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1> at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
1> at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
1> at System.IO.FileStream..ctor(String path, FileMode mode)
1> at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.b__1()
1> at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func)
1> at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign)<---
1>
1>---> (Inner Exception #1) System.UnauthorizedAccessException: Access to the path 'C:\Development\publishtest\obj\Release\net8.0\win-x64\singlefilehost.exe' is denied.
1> at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1> at System.IO.File.InternalDelete(String path, Boolean checkHost)
1> at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign)<---
1>
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Build completed at 10:29 and took 01.433 seconds ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Publish completed at 10:29 and took 01.433 seconds ==========
Analysis
Build fails when both self contained and produce single file are selected in the publish config. Unticking either makes the publish succeed.
Versions & Configurations
MSBuild version 17.9.5+33de0b227 for .NET Framework
17.9.5.7608