Skip to content

Commit b9e5c2d

Browse files
CopilotSoar360
andcommitted
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 <[email protected]>
1 parent 25f7e2c commit b9e5c2d

File tree

11 files changed

+84
-4
lines changed

11 files changed

+84
-4
lines changed

LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Description>MSBuild tasks for LuYao.ResourcePacker - enables automatic resource file packaging during build</Description>
77
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
8+
<IncludeBuildOutput>false</IncludeBuildOutput>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -13,7 +14,9 @@
1314
</ItemGroup>
1415

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

@@ -23,6 +26,12 @@
2326

2427
<Target Name="PackTaskDependencies" BeforeTargets="GenerateNuspec">
2528
<ItemGroup>
29+
<!-- Include the MSBuild task DLL itself -->
30+
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.MSBuild.dll">
31+
<PackagePath>tasks/$(TargetFramework)</PackagePath>
32+
<Visible>false</Visible>
33+
<BuildAction>Content</BuildAction>
34+
</_PackageFiles>
2635
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.dll">
2736
<PackagePath>tasks/$(TargetFramework)</PackagePath>
2837
<Visible>false</Visible>

LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<ResourcePackerEnabled Condition="'$(ResourcePackerEnabled)' == ''">true</ResourcePackerEnabled>
55
<ResourcePackerPattern Condition="'$(ResourcePackerPattern)' == ''">*.res.*</ResourcePackerPattern>
66
<ResourcePackerAccessibility Condition="'$(ResourcePackerAccessibility)' == ''">internal</ResourcePackerAccessibility>
7-
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
87
</PropertyGroup>
98

109
<ItemGroup>

LuYao.ResourcePacker.MSBuild/build/LuYao.ResourcePacker.MSBuild.targets

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
<Target Name="PackResources" BeforeTargets="AssignTargetPaths" Condition="'$(ResourcePackerEnabled)' == 'true'">
77
<PropertyGroup>
8-
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
8+
<!-- Use MSBuildProjectName if AssemblyName is not set -->
9+
<_AssemblyNameForPacker Condition="'$(AssemblyName)' != ''">$(AssemblyName)</_AssemblyNameForPacker>
10+
<_AssemblyNameForPacker Condition="'$(AssemblyName)' == ''">$(MSBuildProjectName)</_AssemblyNameForPacker>
11+
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(_AssemblyNameForPacker).dat</ResourcePackerOutputFileName>
912
</PropertyGroup>
1013
<ResourcePackerTask
1114
ProjectDir="$(ProjectDir)"
1215
OutputPath="$(OutputPath)"
13-
AssemblyName="$(AssemblyName)"
16+
AssemblyName="$(_AssemblyNameForPacker)"
1417
ResourcePattern="$(ResourcePackerPattern)"
1518
OutputFileName="$(ResourcePackerOutputFileName)" />
1619

test-scenario/App2/App2.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\LibB\LibB.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

test-scenario/App2/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using LibB;
2+
3+
Console.WriteLine(new LibBClass().GetMessage());
4+
Console.WriteLine("App2 is running");

test-scenario/LibA/LibA.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="LuYao.ResourcePacker.MSBuild" Version="1.0.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Include="Resources\**\*.res.*" CopyToOutputDirectory="Never" />
15+
</ItemGroup>
16+
17+
</Project>

test-scenario/LibA/LibAClass.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace LibA;
2+
3+
public class LibAClass
4+
{
5+
public string GetMessage() => "Hello from LibA";
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test resource from LibA

test-scenario/LibB/LibB.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\LibA\LibA.csproj" />
11+
</ItemGroup>
12+
13+
</Project>

test-scenario/LibB/LibBClass.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace LibB;
2+
3+
public class LibBClass
4+
{
5+
public string GetMessage() => "Hello from LibB";
6+
}

0 commit comments

Comments
 (0)