Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

MSBuild tasks and Source Generators were being transitively imported when a project referenced a library using LuYao.ResourcePacker.MSBuild. Projects depending on such libraries should only get the runtime library, not build-time functionality.

Changes

Package structure

  • Removed buildTransitive/ folder to prevent transitive import of MSBuild tasks/analyzers
  • Set PrivateAssets="none" on runtime library reference to allow transitive dependency flow
  • Kept PrivateAssets="all" on Source Generator to block transitive flow
  • Added MSBuild.dll to tasks folder in package

Build property initialization

  • Removed ResourcePackerOutputFileName from .props (was evaluated before AssemblyName initialized, causing .dat filename)
  • Moved to .targets using MSBuild::ValueOrDefault('$(AssemblyName)', '$(MSBuildProjectName)') for proper fallback

Behavior

LibA (references LuYao.ResourcePacker.MSBuild)
  ✓ MSBuild tasks execute, generates LibA.dat
  
LibB (references LibA)  
  ✗ No MSBuild tasks (non-transitive)
  ✓ Gets LuYao.ResourcePacker runtime library (transitive)
  ✓ Gets LibA.dat in output (via CopyToOutputDirectory)
  
App2 (references LibB)
  ✗ No MSBuild tasks
  ✓ Gets runtime library  
  ✓ Gets LibA.dat in output

Test scenario

  • Added test-scenario/ demonstrating LibA → LibB → App2 chain with expected behavior
Original prompt

This section details on the original issue you should resolve

<issue_title>msbuild和sg项目不应该传递依赖。</issue_title>
<issue_description>如果类库A引用了 MSBuild 项目,那么 MSBuild 应该仅限于 A 项目。依赖 A 的项目不应该默认引用 MSBuild 和 SG 项目,需要单独引用。</issue_description>

<agent_instructions>请创建两个类库一个控制台项目,形成链式依赖。并在依赖的顶层引用 LuYao.ResourcePacker.MSBuild 项目(通过 NuGet 的形式)。
假设分别是 LibA、LibB 和 App2 。其中 LibA 通过 NuGet 引用了 LuYao.ResourcePacker.MSBuild 并添加了需要生成 dat 的文件。那么,LibB、App2 中如果需要同样的功能,就需要单独再次引用 LuYao.ResourcePacker.MSBuild ,而不是直接将依赖传递。

这个能实现吗?是否会导致 LibA 生成的 dat 文件无法出现在 App2 的生成目录中?</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.

Copilot AI and others added 2 commits October 26, 2025 10:40
- Modified LuYao.ResourcePacker.MSBuild.csproj to mark runtime dependency as transitive while keeping MSBuild assets private
- Removed buildTransitive folder to prevent transitive import of build targets
- Fixed ResourcePackerOutputFileName to use MSBuildProjectName when AssemblyName is not yet set
- Added MSBuild task DLL to package
- Created test scenario with LibA, LibB, and App2 to verify behavior
- Verified that MSBuild targets only apply to projects that directly reference the package
- Verified that .dat files are correctly copied to consuming projects

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
- Changed BuildAction from Content to None for MSBuild task assemblies
- Simplified property assignment using MSBuild ValueOrDefault function
- Removed redundant CopyToOutputDirectory setting from test scenario
- Added README to test-scenario explaining the feature

Co-authored-by: Soar360 <15421284+Soar360@users.noreply.github.com>
Copilot AI changed the title [WIP] Update dependency management for MSBuild and SG projects Prevent transitive import of MSBuild tasks and Source Generator Oct 26, 2025
Copilot AI requested a review from Soar360 October 26, 2025 10:49
@Soar360 Soar360 marked this pull request as ready for review October 26, 2025 10:53
@Soar360 Soar360 merged commit 71edde8 into main Oct 26, 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.

msbuild和sg项目不应该传递依赖。

2 participants