Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Fixes #12712

Context

PR #10928 added _GenerateCompileInputs as a dependency to _GenerateCompileDependencyCache to include embedded resources in incremental build cache. This broke NoBuild publish scenarios: when _GenerateCompileInputs is skipped (MSBuild marks it "Previously built successfully"), _CoreCompileResourceInputs remains unpopulated, causing CoreCompile to produce resource-less DLLs during RID-specific recompilation.

Changes Made

Modified _GenerateCompileDependencyCache target in Microsoft.Common.CurrentVersion.targets:

  1. Added PrepareResources dependency to ensure OutputResource metadata is set before population logic runs
  2. Added fallback ItemGroup that populates _CoreCompileResourceInputs when empty, duplicating the logic from _GenerateCompileInputs
<Target Name="_GenerateCompileDependencyCache" 
        DependsOnTargets="ResolveAssemblyReferences;PrepareResources;_GenerateCompileInputs">
  <ItemGroup Condition="'@(_CoreCompileResourceInputs)' == ''">
    <_CoreCompileResourceInputs Include="@(EmbeddedResource->'%(OutputResource)')" 
                                 Condition="'%(EmbeddedResource.WithCulture)' == 'false' and '%(EmbeddedResource.Type)' == 'Resx'" />
    <!-- Additional resource types... -->
  </ItemGroup>
  <!-- Cache generation continues... -->
</Target>

Testing

Verified with original repro: dotnet build -p:PublishAot=true followed by dotnet publish -p:PublishAot=true -p:NoBuild=true produces working binary with embedded resources.

Notes

Preserves PR #10928's fast up-to-date check benefit while fixing NoBuild scenarios. The fallback only triggers when _GenerateCompileInputs is skipped, avoiding duplicate resource additions.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Broken Build]: PublishAot=true + NoBuild=true produce binary without EmbeddedResources</issue_title>
<issue_description>### Issue Description

In certain situations, MSBuild might fail to correctly embed EmbeddedResource items with MSBuild 17.14 when NoBuild=true is specified.

The easiest way to get that behavior is by using PublishAot=true.

The culprit seems to be #10928.
After that PR, _GenerateCompileInputs does not add any EmbeddedResource to the inputs, see the attached binlog.

Steps to Reproduce

With the .NET SDK 9.0.306 / MSBuild 17.14:

  1. Clone https://github.com/MrJul/repro-publish-nobuild-bug (this is an almost empty console application with a single .resx file).
  2. Run dotnet build -p:PublishAot=true
  3. Run dotnet publish -p:PublishAot=true -p:NoBuild=true
  4. Run the published executable
  5. Notice it fails with a MissingManifestResourceException

Reproducible with SDK versions 9.0.300 through 9.0.306, as well as 10.0.100-rc.2.25502.107.
It works without any issue with 9.0.205.

Expected Behavior

The executable has embedded resources and runs without any issue.

Actual Behavior

The executable doesn't have any embedded resources and fails at runtime.

Ask us questions

No response</issue_description>

<agent_instructions>Thorougly investigate what is going on and propose a validated fix (while preserving the benefit of the PR that introduced this bug)</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dotnet-policy-service
Copy link
Contributor

Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Adds PrepareResources dependency to _GenerateCompileDependencyCache and implements fallback to populate _CoreCompileResourceInputs when _GenerateCompileInputs is skipped

Co-authored-by: JanProvaznik <[email protected]>
Copilot AI changed the title [WIP] Fix embedded resources issue with PublishAot and NoBuild settings Fix embedded resources missing in PublishAot + NoBuild binaries Nov 19, 2025
Copilot AI requested a review from JanProvaznik November 19, 2025 17:58
Copilot finished work on behalf of JanProvaznik November 19, 2025 17:58
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.

[Broken Build]: PublishAot=true + NoBuild=true produce binary without EmbeddedResources

2 participants