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
2 changes: 1 addition & 1 deletion LuYao.ResourcePacker.MSBuild/ResourcePackerTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ResourcePackerTask : Task
[Required]
public string AssemblyName { get; set; }

public string ResourceDirectory { get; set; } = "Resources";
public string ResourceDirectory { get; set; } = "Attachments";

public string OutputFileName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ResourcePackerEnabled Condition="'$(ResourcePackerEnabled)' == ''">true</ResourcePackerEnabled>
<ResourcePackerDirectory Condition="'$(ResourcePackerDirectory)' == ''">Resources</ResourcePackerDirectory>
<ResourcePackerDirectory Condition="'$(ResourcePackerDirectory)' == ''">Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static void Execute(SourceProductionContext context, Compilation compila
System.Collections.Immutable.ImmutableArray<AdditionalText> resourceFiles,
AnalyzerConfigOptionsProvider configOptions)
{
// Get the resource directory from analyzer config (default to "Resources")
// Get the resource directory from analyzer config (default to "Attachments")
var resourceDirectory = GetResourceDirectory(configOptions);

// Filter additional files to only include those in the resource directory
Expand Down Expand Up @@ -108,8 +108,8 @@ private static string GetResourceDirectory(AnalyzerConfigOptionsProvider configO
}
}

// Default to "Resources"
return "Resources";
// Default to "Attachments"
return "Attachments";
}

private static bool IsInResourceDirectory(string filePath, string resourceDirectory)
Expand All @@ -124,7 +124,7 @@ private static bool IsInResourceDirectory(string filePath, string resourceDirect
var normalizedDir = resourceDirectory.Replace('\\', '/');

// Check if the file path contains the resource directory
// Handle both "Resources" and "Resources/" formats
// Handle both with and without trailing slash (e.g., "Attachments" and "Attachments/")
return normalizedPath.Contains($"/{normalizedDir}/") ||
normalizedPath.EndsWith($"/{normalizedDir}");
}
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LuYao.ResourcePacker is a .NET library for packaging and accessing resource file

- Pack multiple resource files into a single .dat file during build
- **Intelligent tiered compression with GZip** - automatic compression with sampling for optimal space/performance
- Directory-based resource scanning (default: Resources directory)
- Directory-based resource scanning (default: Attachments directory)
- MSBuild integration
- Simple runtime API for resource access
- Async support
Expand All @@ -35,16 +35,18 @@ dotnet add package LuYao.ResourcePacker

### 1. Basic Setup

Place your resource files in the `Resources` directory:
Place your resource files in the `Attachments` directory:
```
Resources/
Attachments/
├── message.json
├── config.txt
└── template.html
```

The resources will be automatically packed into a .dat file during build.

> **Note**: The default directory was changed from `Resources` to `Attachments` to avoid conflicts with C# .resx files, which typically use the `Resources` directory. If you prefer to use `Resources` or any other directory name, you can configure it in your .csproj file (see Configuration section below).

### 2. Runtime Access - Original API

Access resources at runtime using the `ResourcePackageReader`:
Expand Down Expand Up @@ -106,8 +108,8 @@ In your .csproj file:
<!-- Enable/disable resource packing -->
<ResourcePackerEnabled>true</ResourcePackerEnabled>

<!-- Custom resource directory (default: Resources) -->
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<!-- Custom resource directory (default: Attachments) -->
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>

<!-- Custom output filename -->
<ResourcePackerOutputFileName>$(AssemblyName).dat</ResourcePackerOutputFileName>
Expand Down
6 changes: 3 additions & 3 deletions examples/ExampleProject/ExampleProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
<ResourcePackerOutputFileName>$(AssemblyName).dat</ResourcePackerOutputFileName>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!--
Expand Down Expand Up @@ -57,7 +57,7 @@

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="true" />
<AdditionalFiles Include="Attachments\**\*" Visible="true" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions examples/ExampleProject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a console application demonstrating how to use the LuYao.ResourcePacker

## What This Example Demonstrates

1. **Resource File Setup**: Place resource files in a `Resources` folder with the `.res.` pattern in the filename (e.g., `message.res.json`, `config.res.json`, `template.res.html`)
1. **Resource File Setup**: Place resource files in an `Attachments` folder (e.g., `message.json`, `config.json`, `template.html`)

2. **Automatic Build-Time Packing**: During build, all `.res.*` files are automatically packed into a single `.dat` file

Expand All @@ -18,10 +18,10 @@ This is a console application demonstrating how to use the LuYao.ResourcePacker
ExampleProject/
├── ExampleProject.csproj # Project configuration with ResourcePacker integration
├── Program.cs # Main application demonstrating resource access
├── Resources/ # Directory containing resource files
│ ├── message.res.json # JSON resource with greeting and features
│ ├── config.res.json # JSON resource with configuration
│ └── template.res.html # HTML template resource
├── Attachments/ # Directory containing resource files
│ ├── message.json # JSON resource with greeting and features
│ ├── config.json # JSON resource with configuration
│ └── template.html # HTML template resource
└── README.md # This file
```

Expand All @@ -44,8 +44,8 @@ ExampleProject/

## What Happens During Build

1. The MSBuild integration scans for files matching the pattern `*.res.*`
2. All matching files are packed into `ExampleProject.dat`
1. The MSBuild integration scans for files in the `Attachments` directory
2. All files are packed into `ExampleProject.dat`
3. The `.dat` file is copied to the output directory
4. At runtime, the application reads resources from the `.dat` file

Expand Down Expand Up @@ -101,7 +101,7 @@ If you're creating your own project using LuYao.ResourcePacker, follow these ste
dotnet add package LuYao.ResourcePacker
```

2. Add resource files with the `.res.` pattern to your project
2. Add resource files to the `Attachments` directory in your project

3. The MSBuild integration will automatically pack your resources during build

Expand All @@ -119,7 +119,7 @@ The example project uses the following MSBuild properties in `ExampleProject.csp
```

You can also customize:
- `ResourcePackerPattern` - Custom file pattern (default: `*.res.*`)
- `ResourcePackerDirectory` - Custom resource directory (default: `Attachments`)
- `ResourcePackerOutputFileName` - Custom output filename (default: `$(AssemblyName).dat`)

## Learn More
Expand Down
6 changes: 3 additions & 3 deletions examples/Lib1.Ns2.Ns3/Lib1.Ns2.Ns3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,12 +18,12 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="true" />
<AdditionalFiles Include="Attachments\**\*" Visible="true" />
</ItemGroup>

<!-- For development with project references, manually import and override assembly path -->
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/Lib1/Lib1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,12 +18,12 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="true" />
<AdditionalFiles Include="Attachments\**\*" Visible="true" />
</ItemGroup>

<!-- For development with project references, manually import and override assembly path -->
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/Lib2/Lib2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,12 +19,12 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="true" />
<AdditionalFiles Include="Attachments\**\*" Visible="true" />
</ItemGroup>

<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/Lib3/Lib3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,12 +19,12 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="false" />
<AdditionalFiles Include="Attachments\**\*" Visible="false" />
</ItemGroup>

<UsingTask TaskName="LuYao.ResourcePacker.MSBuild.ResourcePackerTask"
Expand Down
6 changes: 3 additions & 3 deletions examples/NuGetReferenceExample/NuGetReferenceExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
<ResourcePackerOutputFileName>$(AssemblyName).dat</ResourcePackerOutputFileName>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!--
Expand Down Expand Up @@ -57,7 +57,7 @@

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="false" />
<AdditionalFiles Include="Attachments\**\*" Visible="false" />
</ItemGroup>

</Project>
9 changes: 4 additions & 5 deletions examples/NuGetReferenceExample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Alternatively, use the published NuGet package version once available.
NuGetReferenceExample/
├── NuGetReferenceExample.csproj # Project file with NuGet package reference
├── Program.cs # Application code
├── Resources/
│ ├── config.res.json # Resource file (JSON)
│ └── message.res.txt # Resource file (text)
├── Attachments/
│ └── config.json # Resource file (JSON)
└── README.md
```

Expand All @@ -29,11 +28,11 @@ NuGetReferenceExample/

2. **Automatic Build Integration**: The MSBuild targets and props files are automatically imported by NuGet, so you don't need to manually configure any build tasks.

3. **Resource Naming Convention**: Files matching the pattern `*.res.*` are automatically packed into a `.dat` file during build.
3. **Resource Directory**: Files in the `Attachments` directory are automatically packed into a `.dat` file during build.

4. **Configuration**: You can customize the behavior using MSBuild properties:
- `ResourcePackerEnabled`: Enable/disable resource packing (default: `true`)
- `ResourcePackerPattern`: File pattern for resources (default: `*.res.*`)
- `ResourcePackerDirectory`: Resource directory name (default: `Attachments`)
- `ResourcePackerOutputFileName`: Output filename (default: `$(AssemblyName).dat`)

## Building (with local NuGet package)
Expand Down
2 changes: 1 addition & 1 deletion examples/RootNamespaceTest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ When a project sets `<RootNamespace>Popcorn.Toolkit</RootNamespace>` in its .csp
The project is configured with:
- **AssemblyName**: RootNamespaceTest
- **RootNamespace**: Popcorn.Toolkit
- **Resources**: Contains sample.txt and config.json
- **Attachments**: Contains sample.txt and config.json

## Expected Behavior

Expand Down
6 changes: 3 additions & 3 deletions examples/RootNamespaceTest/RootNamespaceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<IsPackable>false</IsPackable>
<RootNamespace>Popcorn.Toolkit</RootNamespace>
<ResourcePackerEnabled>true</ResourcePackerEnabled>
<ResourcePackerDirectory>Resources</ResourcePackerDirectory>
<ResourcePackerDirectory>Attachments</ResourcePackerDirectory>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,12 +20,12 @@
</ItemGroup>

<ItemGroup>
<None Include="Resources\**\*" CopyToOutputDirectory="Never" />
<None Include="Attachments\**\*" CopyToOutputDirectory="Never" />
</ItemGroup>

<!-- Add resource files as AdditionalFiles for source generator -->
<ItemGroup>
<AdditionalFiles Include="Resources\**\*" Visible="false" />
<AdditionalFiles Include="Attachments\**\*" Visible="false" />
</ItemGroup>

<!-- For development with project references, manually import and override assembly path -->
Expand Down