Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>MSBuild tasks for LuYao.ResourcePacker - enables automatic resource file packaging during build</Description>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,7 +14,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LuYao.ResourcePacker\LuYao.ResourcePacker.csproj" PrivateAssets="all" />
<!-- Reference to runtime library - will be added as a NuGet dependency -->
<ProjectReference Include="..\LuYao.ResourcePacker\LuYao.ResourcePacker.csproj" PrivateAssets="none" />
<!-- MSBuild task and Source Generator are not exposed to consumers -->
<ProjectReference Include="..\LuYao.ResourcePacker.SourceGenerator\LuYao.ResourcePacker.SourceGenerator.csproj" PrivateAssets="all" />
</ItemGroup>

Expand All @@ -23,15 +26,21 @@

<Target Name="PackTaskDependencies" BeforeTargets="GenerateNuspec">
<ItemGroup>
<!-- Include the MSBuild task DLL itself -->
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.MSBuild.dll">
<PackagePath>tasks/$(TargetFramework)</PackagePath>
<Visible>false</Visible>
<BuildAction>None</BuildAction>
</_PackageFiles>
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.dll">
<PackagePath>tasks/$(TargetFramework)</PackagePath>
<Visible>false</Visible>
<BuildAction>Content</BuildAction>
<BuildAction>None</BuildAction>
</_PackageFiles>
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.SourceGenerator.dll">
<PackagePath>analyzers/dotnet/cs</PackagePath>
<Visible>false</Visible>
<BuildAction>Content</BuildAction>
<BuildAction>None</BuildAction>
</_PackageFiles>
</ItemGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<ResourcePackerEnabled Condition="'$(ResourcePackerEnabled)' == ''">true</ResourcePackerEnabled>
<ResourcePackerPattern Condition="'$(ResourcePackerPattern)' == ''">*.res.*</ResourcePackerPattern>
<ResourcePackerAccessibility Condition="'$(ResourcePackerAccessibility)' == ''">internal</ResourcePackerAccessibility>
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

<Target Name="PackResources" BeforeTargets="AssignTargetPaths" Condition="'$(ResourcePackerEnabled)' == 'true'">
<PropertyGroup>
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
<!-- Use MSBuildProjectName if AssemblyName is not set -->
<_AssemblyNameForPacker>$([MSBuild]::ValueOrDefault('$(AssemblyName)', '$(MSBuildProjectName)'))</_AssemblyNameForPacker>
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(_AssemblyNameForPacker).dat</ResourcePackerOutputFileName>
</PropertyGroup>
<ResourcePackerTask
ProjectDir="$(ProjectDir)"
OutputPath="$(OutputPath)"
AssemblyName="$(AssemblyName)"
AssemblyName="$(_AssemblyNameForPacker)"
ResourcePattern="$(ResourcePackerPattern)"
OutputFileName="$(ResourcePackerOutputFileName)" />

Expand Down
14 changes: 14 additions & 0 deletions test-scenario/App2/App2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LibB\LibB.csproj" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions test-scenario/App2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using LibB;

Console.WriteLine(new LibBClass().GetMessage());
Console.WriteLine("App2 is running");
17 changes: 17 additions & 0 deletions test-scenario/LibA/LibA.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LuYao.ResourcePacker.MSBuild" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*.res.*" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions test-scenario/LibA/LibAClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LibA;

public class LibAClass
{
public string GetMessage() => "Hello from LibA";
}
1 change: 1 addition & 0 deletions test-scenario/LibA/Resources/test.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test resource from LibA
13 changes: 13 additions & 0 deletions test-scenario/LibB/LibB.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LibA\LibA.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions test-scenario/LibB/LibBClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LibB;

public class LibBClass
{
public string GetMessage() => "Hello from LibB";
}
8 changes: 8 additions & 0 deletions test-scenario/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="local" value="/tmp/nuget-test" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
49 changes: 49 additions & 0 deletions test-scenario/README.md
Original file line number Diff line number Diff line change
@@ -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