Skip to content

Fix PublishSingleFile failure when GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false#53156

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-publish-single-file-bug
Open

Fix PublishSingleFile failure when GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false#53156
Copilot wants to merge 2 commits intomainfrom
copilot/fix-publish-single-file-bug

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false, the XML doc file is never written to the bin/ output directory. However, ComputeResolvedFilesToPublishList was unconditionally adding it to ResolvedFileToPublish via @(FinalDocFile) (which resolves to the bin/ path), causing GenerateBundle to throw FileNotFoundException during PublishSingleFile.

Changes

  • Microsoft.NET.Publish.targets: Add '$(CopyDocumentationFileToOutputDirectory)' != 'false' to the condition guarding the XML doc file entry in ResolvedFileToPublish, mirroring how PDB publishing already gates on $(CopyOutputSymbolsToPublishDirectory):
<ResolvedFileToPublish Include="@(FinalDocFile)"
                        Condition="'$(PublishDocumentationFile)' == 'true' and
                                   '$(CopyDocumentationFileToOutputDirectory)' != 'false'">
  <RelativePath>@(FinalDocFile->'%(Filename)%(Extension)')</RelativePath>
  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
  • GivenThatWeWantToPublishASingleFileApp.cs: Add regression test It_succeeds_when_xml_docs_generated_but_not_copied_to_output covering the GenerateDocumentationFile=true + CopyDocumentationFileToOutputDirectory=false + PublishSingleFile=true combination.
Original prompt

This section details on the original issue you should resolve

<issue_title>PublishSingleFile publish fails when XML docs are generated but not copied to the output directory</issue_title>
<issue_description>### Describe the bug
dotnet publish fails when GenerateDocumentationFile and PublishSingleFile are set to true while CopyDocumentationFileToOutputDirectory is set to false.

To Reproduce

  1. Create a project with the following .csproj file:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <CopyDocumentationFileToOutputDirectory>false</CopyDocumentationFileToOutputDirectory>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>

</Project>
  1. Run dotnet publish
Restore complete (0.3s)
  PublishingBug net10.0 win-x64 failed with 1 error(s) (0.3s) → PublishingBug\bin\Release\net10.0\win-x64\PublishingBug.dll
    C:\Program Files\dotnet\sdk\10.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1132,5): error MSB4018:
      The "GenerateBundle" task failed unexpectedly.
      System.IO.FileNotFoundException: Could not find file 'C:\Users\User\source\repos\PublishingBug\PublishingBug\bin\Release\net10.0\win-x64\PublishingBug.
      xml'.
      File name: 'C:\Users\User\source\repos\PublishingBug\PublishingBug\bin\Release\net10.0\win-x64\PublishingBug.xml'
         at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
         at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 pr
      eallocationSize, Nullable`1 unixCreateMode)
         at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preall
      ocationSize, Nullable`1 unixCreateMode)
         at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, In
      t64 preallocationSize, Nullable`1 unixCreateMode)
         at System.IO.File.OpenRead(String path)
         at Microsoft.NET.HostModel.Bundle.Bundler.IsAssembly(String path, Boolean& isPE)
         at Microsoft.NET.HostModel.Bundle.Bundler.InferType(FileSpec fileSpec)
         at Microsoft.NET.HostModel.Bundle.Bundler.GetFilteredFileSpecs(IEnumerable`1 fileSpecs)
         at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs)
         at Microsoft.NET.Build.Tasks.GenerateBundle.<>c__DisplayClass56_0.<ExecuteWithRetry>b__0()
         at Microsoft.NET.Build.Tasks.GenerateBundle.DoWithRetry(Action action)
         at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteWithRetry()
         at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore()
         at Microsoft.NET.Build.Tasks.TaskBase.Execute()
         at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
         at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost
      taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

Further technical details

details of dotnet --info

.NET SDK: Version: 10.0.100 Commit: b0f34d51fc Workload version: 10.0.100-manifests.5fb86115 MSBuild version: 18.0.2+b0f34d51f

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

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0
Architecture: x64
Commit: b0f34d51fc

.NET SDKs installed:
9.0.112 [C:\Program Files\dotnet\sdk]
10.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0 [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:
DOTNET_CLI_UI_LANGUAGE [en-US]
DOTNET_GCHeapCo...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…tory=false

When GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false,
the XML doc file is never copied to the output (bin/) directory. However, the
ResolvedFileToPublish item group was using @(FinalDocFile) which points to the bin/
path, causing GenerateBundle to throw FileNotFoundException.

Fix: add CopyDocumentationFileToOutputDirectory != false condition, mirroring how
PDB files gate on CopyOutputSymbolsToPublishDirectory.

Also adds a regression test in GivenThatWeWantToPublishASingleFileApp.

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PublishSingleFile publish failure with XML docs Fix PublishSingleFile failure when GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false Feb 25, 2026
Copilot AI requested a review from baronfel February 25, 2026 16:50
@baronfel baronfel marked this pull request as ready for review February 25, 2026 17:03
@baronfel baronfel requested review from a team as code owners February 25, 2026 17:03
Copilot AI review requested due to automatic review settings February 25, 2026 17:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a FileNotFoundException that occurs during PublishSingleFile when GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false. The issue was that the XML documentation file was being added to the publish list even though it was never copied to the output directory.

Changes:

  • Added a condition check in Microsoft.NET.Publish.targets to prevent adding XML doc files to the publish list when CopyDocumentationFileToOutputDirectory=false
  • Added a regression test to verify the fix works correctly with PublishSingleFile

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets Added CopyDocumentationFileToOutputDirectory != 'false' condition to prevent FileNotFoundException when XML docs are generated but not copied to output
test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs Added regression test verifying PublishSingleFile succeeds when GenerateDocumentationFile=true and CopyDocumentationFileToOutputDirectory=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PublishSingleFile publish fails when XML docs are generated but not copied to the output directory

4 participants