Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 25, 2025

当库项目(Lib1)使用 LuYao.ResourcePacker.MSBuild 生成 .dat 文件时,引用该库的应用项目(App1)的输出目录中不包含 .dat 文件。

Changes

Modified LuYao.ResourcePacker.MSBuild.targets:

  • Changed PackResources to run BeforeTargets="AssignTargetPaths" (was BeforeTargets="CopyFilesToOutputDirectory")
  • Add generated .dat file to None item group with CopyToOutputDirectory="PreserveNewest" and Link metadata immediately after creation
  • This allows MSBuild's AssignTargetPaths to process the item for copying to referencing projects

Created test projects:

  • examples/Lib1 - Library project with resource packing enabled
  • examples/App1 - Application project that references Lib1
  • examples/Lib2, examples/Lib3 - Additional library projects to test multi-layer transitive dependencies
  • Validates .dat files now appear in App1's output directory

Example

<Target Name="PackResources" BeforeTargets="AssignTargetPaths" Condition="'$(ResourcePackerEnabled)' == 'true'">
  <PropertyGroup>
    <ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
  </PropertyGroup>
  <ResourcePackerTask
    ProjectDir="$(ProjectDir)"
    OutputPath="$(OutputPath)"
    AssemblyName="$(AssemblyName)"
    ResourcePattern="$(ResourcePackerPattern)"
    OutputFileName="$(ResourcePackerOutputFileName)" />
    
  <ItemGroup>
    <None Include="$(OutputPath)$(ResourcePackerOutputFileName)">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Link>$(ResourcePackerOutputFileName)</Link>
    </None>
  </ItemGroup>
</Target>

Results

Single-layer dependency: When App1 references Lib1, Lib1.dat now appears in App1/bin/Debug/net8.0/.

Multi-layer transitive dependencies: When App1 → Lib3 → Lib2 → Lib1, all three .dat files (Lib1.dat, Lib2.dat, Lib3.dat) correctly appear in App1's output directory. MSBuild's MSBuildCopyContentTransitively feature (enabled by default) ensures .dat files propagate through the entire dependency chain.

Original prompt

This section details on the original issue you should resolve

<issue_title>生成的 dat 文件应该可以出现在依赖该项目的输出文件中</issue_title>
<issue_description>客户反馈,有个 Lib1 项目,和一个 App1 项目。

其中 Lib1 项目引用了 LuYao.ResourcePacker.MSBuild 且正常生成了 .dat 文件。

App1 项目是程序入口,它引用了 Lib1 项目。但是 .dat 文件并没有出现在 App1 的生成结果中,这不符合预期。</issue_description>

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.

Copilot AI and others added 3 commits October 25, 2025 10:19
Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Modified MSBuild targets to ensure .dat files are included in project references by:
- Running PackResources before AssignTargetPaths
- Adding generated .dat file to None items with CopyToOutputDirectory metadata
- This allows MSBuild to properly copy .dat files to referencing projects

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
The Link metadata is necessary to control where the .dat file is placed in the referencing project's output directory. Without it, the file is copied with its full directory structure preserved.

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix .dat file not appearing in App1 output Fix: Copy .dat files to dependent project outputs Oct 25, 2025
Copilot AI requested a review from Soar360 October 25, 2025 10:44
@Soar360
Copy link
Contributor

Soar360 commented Oct 25, 2025

@copilot 针对多层依赖,这个方案仍然奏效吗?比如 Lib1 被 Lib2 依赖,Lib2 被 Lib3 依赖,App1 依赖 Lib3 这种情况。

Verified that .dat files propagate correctly through transitive dependencies.
All three .dat files (Lib1, Lib2, Lib3) appear in App1's output.

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 25, 2025

@copilot 针对多层依赖,这个方案仍然奏效吗?比如 Lib1 被 Lib2 依赖,Lib2 被 Lib3 依赖,App1 依赖 Lib3 这种情况。

是的,这个方案对多层依赖也有效。我创建了测试场景:Lib1 → Lib2 → Lib3 → App1,验证结果显示所有三个 .dat 文件(Lib1.dat, Lib2.dat, Lib3.dat)都正确出现在 App1 的输出目录中。

MSBuild 的 MSBuildCopyContentTransitively 特性(默认启用)会确保带有 CopyToOutputDirectory 元数据的文件在整个依赖链中传播。

测试结果:

  • Lib1 输出:Lib1.dat
  • Lib2 输出:Lib1.dat, Lib2.dat
  • Lib3 输出:Lib1.dat, Lib2.dat, Lib3.dat
  • App1 输出:Lib1.dat, Lib2.dat, Lib3.dat ✅

Commit: e589e43

Copilot AI changed the title Fix: Copy .dat files to dependent project outputs Fix: Copy .dat files to dependent project outputs (including transitive dependencies) Oct 25, 2025
@Soar360 Soar360 marked this pull request as ready for review October 25, 2025 11:12
@Soar360 Soar360 merged commit 8af63bf into main Oct 25, 2025
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.

生成的 dat 文件应该可以出现在依赖该项目的输出文件中

2 participants