Skip to content

Commit 8af63bf

Browse files
authored
Merge pull request #12 from coderbusy/copilot/fix-dat-file-output-in-app1
Fix: Copy .dat files to dependent project outputs (including transitive dependencies)
2 parents 87c21c5 + e589e43 commit 8af63bf

File tree

13 files changed

+139
-13
lines changed

13 files changed

+139
-13
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
44
AssemblyFile="$(MSBuildThisFileDirectory)..\tasks\netstandard2.0\LuYao.ResourcePacker.MSBuild.dll" />
55

6-
<Target Name="PackResources" BeforeTargets="CopyFilesToOutputDirectory" Condition="'$(ResourcePackerEnabled)' == 'true'">
6+
<Target Name="PackResources" BeforeTargets="AssignTargetPaths" Condition="'$(ResourcePackerEnabled)' == 'true'">
77
<PropertyGroup>
88
<ResourcePackerOutputFileName Condition="'$(ResourcePackerOutputFileName)' == ''">$(AssemblyName).dat</ResourcePackerOutputFileName>
99
</PropertyGroup>
@@ -13,5 +13,13 @@
1313
AssemblyName="$(AssemblyName)"
1414
ResourcePattern="$(ResourcePackerPattern)"
1515
OutputFileName="$(ResourcePackerOutputFileName)" />
16+
17+
<!-- Add .dat file to None so it gets copied to referencing projects -->
18+
<ItemGroup>
19+
<None Include="$(OutputPath)$(ResourcePackerOutputFileName)">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
<Link>$(ResourcePackerOutputFileName)</Link>
22+
</None>
23+
</ItemGroup>
1624
</Target>
1725
</Project>

examples/App1/App1.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Lib3\Lib3.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

examples/App1/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using Lib1;
2+
3+
var lib = new LibraryClass();
4+
Console.WriteLine(lib.GetMessage());

examples/ExampleProject/ExampleProject.csproj

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@
2323
<!--
2424
NOTE: This example uses project references to demonstrate the library from source.
2525
For external projects consuming the NuGet package, the MSBuild targets are automatically
26-
imported and you don't need the UsingTask and Target declarations below.
26+
imported and you don't need the UsingTask and Target import below.
2727
See the main README.md for instructions on using the NuGet package.
2828
-->
2929
<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
30-
AssemblyFile="$(MSBuildThisFileDirectory)..\..\LuYao.ResourcePacker.MSBuild\bin\$(Configuration)\netstandard2.0\LuYao.ResourcePacker.MSBuild.dll" />
30+
AssemblyFile="..\..\LuYao.ResourcePacker.MSBuild\bin\$(Configuration)\netstandard2.0\LuYao.ResourcePacker.MSBuild.dll" />
31+
32+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.props" />
33+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.targets" />
3134

32-
<Target Name="PackResources" BeforeTargets="CopyFilesToOutputDirectory" Condition="'$(ResourcePackerEnabled)' == 'true'">
33-
<ResourcePackerTask
34-
ProjectDir="$(ProjectDir)"
35-
OutputPath="$(OutputPath)"
36-
AssemblyName="$(AssemblyName)"
37-
ResourcePattern="$(ResourcePackerPattern)"
38-
OutputFileName="$(ResourcePackerOutputFileName)" />
39-
</Target>
40-
41-
</Project>
35+
</Project>

examples/Lib1/Lib1.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<ResourcePackerEnabled>true</ResourcePackerEnabled>
9+
<ResourcePackerPattern>*.res.*</ResourcePackerPattern>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\LuYao.ResourcePacker\LuYao.ResourcePacker.csproj" />
14+
<ProjectReference Include="..\..\LuYao.ResourcePacker.MSBuild\LuYao.ResourcePacker.MSBuild.csproj" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<None Include="Resources\**\*.res.*" CopyToOutputDirectory="Never" />
19+
</ItemGroup>
20+
21+
<!-- For development with project references, manually import and override assembly path -->
22+
<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
23+
AssemblyFile="..\..\LuYao.ResourcePacker.MSBuild\bin\$(Configuration)\netstandard2.0\LuYao.ResourcePacker.MSBuild.dll" />
24+
25+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.props" />
26+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.targets" />
27+
28+
</Project>

examples/Lib1/LibraryClass.cs

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

examples/Lib2/Lib2.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<ResourcePackerEnabled>true</ResourcePackerEnabled>
9+
<ResourcePackerPattern>*.res.*</ResourcePackerPattern>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\Lib1\Lib1.csproj" />
14+
<ProjectReference Include="..\..\LuYao.ResourcePacker\LuYao.ResourcePacker.csproj" />
15+
<ProjectReference Include="..\..\LuYao.ResourcePacker.MSBuild\LuYao.ResourcePacker.MSBuild.csproj" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Include="Resources\**\*.res.*" CopyToOutputDirectory="Never" />
20+
</ItemGroup>
21+
22+
<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
23+
AssemblyFile="..\..\LuYao.ResourcePacker.MSBuild\bin\$(Configuration)\netstandard2.0\LuYao.ResourcePacker.MSBuild.dll" />
24+
25+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.props" />
26+
<Import Project="..\..\LuYao.ResourcePacker.MSBuild\build\LuYao.ResourcePacker.MSBuild.targets" />
27+
28+
</Project>

examples/Lib2/Library2Class.cs

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

0 commit comments

Comments
 (0)