Skip to content

Commit 71edde8

Browse files
authored
Merge pull request #28 from coderbusy/copilot/implement-chained-dependencies
Prevent transitive import of MSBuild tasks and Source Generator
2 parents 790ae39 + 69977fa commit 71edde8

File tree

12 files changed

+134
-6
lines changed

12 files changed

+134
-6
lines changed

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

Lines changed: 12 additions & 3 deletions
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,15 +26,21 @@
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>None</BuildAction>
34+
</_PackageFiles>
2635
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.dll">
2736
<PackagePath>tasks/$(TargetFramework)</PackagePath>
2837
<Visible>false</Visible>
29-
<BuildAction>Content</BuildAction>
38+
<BuildAction>None</BuildAction>
3039
</_PackageFiles>
3140
<_PackageFiles Include="$(OutputPath)LuYao.ResourcePacker.SourceGenerator.dll">
3241
<PackagePath>analyzers/dotnet/cs</PackagePath>
3342
<Visible>false</Visible>
34-
<BuildAction>Content</BuildAction>
43+
<BuildAction>None</BuildAction>
3544
</_PackageFiles>
3645
</ItemGroup>
3746
</Target>

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
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>$([MSBuild]::ValueOrDefault('$(AssemblyName)', '$(MSBuildProjectName)'))</_AssemblyNameForPacker>
10+
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(_AssemblyNameForPacker).dat</ResourcePackerOutputFileName>
911
</PropertyGroup>
1012
<ResourcePackerTask
1113
ProjectDir="$(ProjectDir)"
1214
OutputPath="$(OutputPath)"
13-
AssemblyName="$(AssemblyName)"
15+
AssemblyName="$(_AssemblyNameForPacker)"
1416
ResourcePattern="$(ResourcePackerPattern)"
1517
OutputFileName="$(ResourcePackerOutputFileName)" />
1618

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.*" />
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)