|
| 1 | +# NuGet Reference Example |
| 2 | + |
| 3 | +This example demonstrates how to use LuYao.ResourcePacker.MSBuild via NuGet package reference. |
| 4 | + |
| 5 | +**Note**: This example is intended to show the expected project structure when using the NuGet package. To test it, you need to: |
| 6 | +1. Pack the NuGet package locally: `dotnet pack LuYao.ResourcePacker.MSBuild/LuYao.ResourcePacker.MSBuild.csproj -o /tmp/local-nuget` |
| 7 | +2. Create a `nuget.config` file pointing to your local package source |
| 8 | +3. Build this project |
| 9 | + |
| 10 | +Alternatively, use the published NuGet package version once available. |
| 11 | + |
| 12 | +## Project Structure |
| 13 | + |
| 14 | +``` |
| 15 | +NuGetReferenceExample/ |
| 16 | +├── NuGetReferenceExample.csproj # Project file with NuGet package reference |
| 17 | +├── Program.cs # Application code |
| 18 | +├── Resources/ |
| 19 | +│ ├── config.res.json # Resource file (JSON) |
| 20 | +│ └── message.res.txt # Resource file (text) |
| 21 | +└── README.md |
| 22 | +``` |
| 23 | + |
| 24 | +## Key Points |
| 25 | + |
| 26 | +1. **NuGet Package References**: The project references both: |
| 27 | + - `LuYao.ResourcePacker`: Core library for reading packed resources at runtime |
| 28 | + - `LuYao.ResourcePacker.MSBuild`: Build-time MSBuild tasks for packing resources |
| 29 | + |
| 30 | +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. |
| 31 | + |
| 32 | +3. **Resource Naming Convention**: Files matching the pattern `*.res.*` are automatically packed into a `.dat` file during build. |
| 33 | + |
| 34 | +4. **Configuration**: You can customize the behavior using MSBuild properties: |
| 35 | + - `ResourcePackerEnabled`: Enable/disable resource packing (default: `true`) |
| 36 | + - `ResourcePackerPattern`: File pattern for resources (default: `*.res.*`) |
| 37 | + - `ResourcePackerOutputFileName`: Output filename (default: `$(AssemblyName).dat`) |
| 38 | + |
| 39 | +## Building (with local NuGet package) |
| 40 | + |
| 41 | +1. Create a `nuget.config` in this directory: |
| 42 | +```xml |
| 43 | +<?xml version="1.0" encoding="utf-8"?> |
| 44 | +<configuration> |
| 45 | + <packageSources> |
| 46 | + <clear /> |
| 47 | + <add key="local" value="/tmp/local-nuget" /> |
| 48 | + <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> |
| 49 | + </packageSources> |
| 50 | +</configuration> |
| 51 | +``` |
| 52 | + |
| 53 | +2. Build: |
| 54 | +```bash |
| 55 | +dotnet build |
| 56 | +``` |
| 57 | + |
| 58 | +After building, the `NuGetReferenceExample.dat` file will be automatically generated in the output directory. |
| 59 | + |
| 60 | +## Running |
| 61 | + |
| 62 | +```bash |
| 63 | +dotnet run |
| 64 | +``` |
| 65 | + |
| 66 | +The application will read and display the contents of the packed resources. |
| 67 | + |
| 68 | +## What Makes This Different from ExampleProject? |
| 69 | + |
| 70 | +The main `ExampleProject` uses **project references** to LuYao.ResourcePacker.MSBuild, which is useful for development. This example uses **NuGet package reference**, which is how external users would consume the library. |
| 71 | + |
| 72 | +When using NuGet packages, the MSBuild props and targets files must be named exactly as `<PackageId>.props` and `<PackageId>.targets` to be automatically imported. This example validates that the naming is correct. |
| 73 | + |
| 74 | +For more information about NuGet MSBuild conventions, see the [official documentation on creating MSBuild props/targets packages](https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package#include-msbuild-props-and-targets-in-a-package). |
| 75 | + |
0 commit comments