From 25f7e2c5e84fe0db4c4fb6a59c61eca5a12b8d3a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 10:25:58 +0000 Subject: [PATCH 1/3] Initial plan From b9e5c2d2fdd27041580535e079619265af055c8c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 10:40:44 +0000 Subject: [PATCH 2/3] Implement non-transitive MSBuild and SourceGenerator dependencies - 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> --- .../LuYao.ResourcePacker.MSBuild.csproj | 11 ++++++++++- .../build/LuYao.ResourcePacker.MSBuild.props | 1 - .../build/LuYao.ResourcePacker.MSBuild.targets | 7 +++++-- test-scenario/App2/App2.csproj | 14 ++++++++++++++ test-scenario/App2/Program.cs | 4 ++++ test-scenario/LibA/LibA.csproj | 17 +++++++++++++++++ test-scenario/LibA/LibAClass.cs | 6 ++++++ test-scenario/LibA/Resources/test.res.txt | 1 + test-scenario/LibB/LibB.csproj | 13 +++++++++++++ test-scenario/LibB/LibBClass.cs | 6 ++++++ test-scenario/NuGet.config | 8 ++++++++ 11 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 test-scenario/App2/App2.csproj create mode 100644 test-scenario/App2/Program.cs create mode 100644 test-scenario/LibA/LibA.csproj create mode 100644 test-scenario/LibA/LibAClass.cs create mode 100644 test-scenario/LibA/Resources/test.res.txt create mode 100644 test-scenario/LibB/LibB.csproj create mode 100644 test-scenario/LibB/LibBClass.cs create mode 100644 test-scenario/NuGet.config diff --git a/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj b/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj index 0f6e40f..3f063bd 100644 --- a/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj +++ b/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj @@ -5,6 +5,7 @@ true MSBuild tasks for LuYao.ResourcePacker - enables automatic resource file packaging during build tasks + false @@ -13,7 +14,9 @@ - + + + @@ -23,6 +26,12 @@ + + <_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.MSBuild.dll"> + tasks/$(TargetFramework) + false + Content + <_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.dll"> tasks/$(TargetFramework) false diff --git a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.props b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.props index ddeb67f..8410253 100644 --- a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.props +++ b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.props @@ -4,7 +4,6 @@ true *.res.* internal - $(AssemblyName).dat diff --git a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets index 1c16a6a..11b6106 100644 --- a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets +++ b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets @@ -5,12 +5,15 @@ - $(AssemblyName).dat + + <_AssemblyNameForPacker Condition="'$(AssemblyName)' != ''">$(AssemblyName) + <_AssemblyNameForPacker Condition="'$(AssemblyName)' == ''">$(MSBuildProjectName) + $(_AssemblyNameForPacker).dat diff --git a/test-scenario/App2/App2.csproj b/test-scenario/App2/App2.csproj new file mode 100644 index 0000000..affa2f9 --- /dev/null +++ b/test-scenario/App2/App2.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/test-scenario/App2/Program.cs b/test-scenario/App2/Program.cs new file mode 100644 index 0000000..2a8c750 --- /dev/null +++ b/test-scenario/App2/Program.cs @@ -0,0 +1,4 @@ +using LibB; + +Console.WriteLine(new LibBClass().GetMessage()); +Console.WriteLine("App2 is running"); diff --git a/test-scenario/LibA/LibA.csproj b/test-scenario/LibA/LibA.csproj new file mode 100644 index 0000000..f93b987 --- /dev/null +++ b/test-scenario/LibA/LibA.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/test-scenario/LibA/LibAClass.cs b/test-scenario/LibA/LibAClass.cs new file mode 100644 index 0000000..7e965ab --- /dev/null +++ b/test-scenario/LibA/LibAClass.cs @@ -0,0 +1,6 @@ +namespace LibA; + +public class LibAClass +{ + public string GetMessage() => "Hello from LibA"; +} diff --git a/test-scenario/LibA/Resources/test.res.txt b/test-scenario/LibA/Resources/test.res.txt new file mode 100644 index 0000000..5143624 --- /dev/null +++ b/test-scenario/LibA/Resources/test.res.txt @@ -0,0 +1 @@ +This is a test resource from LibA diff --git a/test-scenario/LibB/LibB.csproj b/test-scenario/LibB/LibB.csproj new file mode 100644 index 0000000..9476e5f --- /dev/null +++ b/test-scenario/LibB/LibB.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/test-scenario/LibB/LibBClass.cs b/test-scenario/LibB/LibBClass.cs new file mode 100644 index 0000000..93b95ef --- /dev/null +++ b/test-scenario/LibB/LibBClass.cs @@ -0,0 +1,6 @@ +namespace LibB; + +public class LibBClass +{ + public string GetMessage() => "Hello from LibB"; +} diff --git a/test-scenario/NuGet.config b/test-scenario/NuGet.config new file mode 100644 index 0000000..17c5948 --- /dev/null +++ b/test-scenario/NuGet.config @@ -0,0 +1,8 @@ + + + + + + + + From 69977fa7ae18616f62416ff1848e4efc37ac6314 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 10:44:32 +0000 Subject: [PATCH 3/3] Address code review feedback - 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> --- .../LuYao.ResourcePacker.MSBuild.csproj | 6 +-- .../LuYao.ResourcePacker.MSBuild.targets | 3 +- test-scenario/LibA/LibA.csproj | 2 +- test-scenario/README.md | 49 +++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test-scenario/README.md diff --git a/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj b/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj index 3f063bd..a533bd3 100644 --- a/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj +++ b/LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj @@ -30,17 +30,17 @@ <_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.MSBuild.dll"> tasks/$(TargetFramework) false - Content + None <_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.dll"> tasks/$(TargetFramework) false - Content + None <_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.SourceGenerator.dll"> analyzers/dotnet/cs false - Content + None diff --git a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets index 11b6106..b34d26e 100644 --- a/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets +++ b/LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets @@ -6,8 +6,7 @@ - <_AssemblyNameForPacker Condition="'$(AssemblyName)' != ''">$(AssemblyName) - <_AssemblyNameForPacker Condition="'$(AssemblyName)' == ''">$(MSBuildProjectName) + <_AssemblyNameForPacker>$([MSBuild]::ValueOrDefault('$(AssemblyName)', '$(MSBuildProjectName)')) $(_AssemblyNameForPacker).dat - + diff --git a/test-scenario/README.md b/test-scenario/README.md new file mode 100644 index 0000000..d4a97c2 --- /dev/null +++ b/test-scenario/README.md @@ -0,0 +1,49 @@ +# Test Scenario: Non-Transitive Dependency + +This test scenario demonstrates that the MSBuild and Source Generator components of LuYao.ResourcePacker.MSBuild are NOT transitively referenced. + +## Project Structure + +``` +LibA (references LuYao.ResourcePacker.MSBuild via NuGet) + └── Contains test.res.txt resource file + └── Generates LibA.dat during build + +LibB (references LibA) + └── Does NOT get MSBuild/SG functionality + └── Does receive LibA.dat in output + +App2 (references LibB) + └── Does NOT get MSBuild/SG functionality + └── Does receive LibA.dat in output +``` + +## Expected Behavior + +1. **LibA**: MSBuild targets execute, generates `LibA.dat` +2. **LibB**: MSBuild targets do NOT execute (no transitive import), but `LibA.dat` is copied to output +3. **App2**: MSBuild targets do NOT execute (no transitive import), but `LibA.dat` is copied to output + +## Testing + +```bash +# Build the entire chain +cd test-scenario +dotnet build App2/App2.csproj + +# Verify LibA has LibA.dat +ls LibA/bin/Debug/net8.0/LibA.dat + +# Verify LibB has LibA.dat but NOT LibB.dat +ls LibB/bin/Debug/net8.0/LibA.dat +ls LibB/bin/Debug/net8.0/LibB.dat # Should not exist + +# Verify App2 has LibA.dat +ls App2/bin/Debug/net8.0/LibA.dat +``` + +## Key Points + +- The `LuYao.ResourcePacker.MSBuild` package only imports build assets for **direct** references +- The runtime dependency (`LuYao.ResourcePacker`) **IS** transitively passed +- Generated `.dat` files are copied to all consuming projects via the `CopyToOutputDirectory` setting