|
1 | | -# Dataverse Wrapper Generator |
| 1 | +# Dataverse Plugin Wrapper Generator |
2 | 2 |
|
3 | | -A C# console application that generates strongly typed entity classes and option set enums from a Dataverse solution zip (`customizations.xml`). |
| 3 | +Generate strongly typed C# wrappers and option set enums from a Dataverse solution zip (`customizations.xml`). |
4 | 4 |
|
5 | | -## Features |
| 5 | +This tool reads Dataverse metadata and writes: |
| 6 | +- `OptionSets/OptionValueSets.cs` with global option set enums and state enums |
| 7 | +- `Entities/*.cs` wrapper classes with CRUD helpers (`Create`, `Retrieve`, `Update`, `Delete`) |
6 | 8 |
|
7 | | -- Parses `customizations.xml` from a Dataverse solution zip. |
8 | | -- Generates option set enums in `OptionSets/OptionValueSets.cs`. |
9 | | -- Generates entity wrapper classes with `Create`, `Retrieve`, `Update`, and `Delete` methods. |
10 | | -- Supports overwrite prompts (or `--yes` to skip prompts). |
11 | | -- Supports entity filtering with `--filter`. |
| 9 | +## What This Project Is |
12 | 10 |
|
13 | | -## Getting Started |
| 11 | +- A .NET console app (`DataversePluginWrapper`) that parses Dataverse solution metadata. |
| 12 | +- A code generator only. It does not deploy to Dataverse. |
| 13 | +- Supports both: |
| 14 | + - CLI mode (arguments) |
| 15 | + - Interactive mode (no arguments) |
14 | 16 |
|
15 | | -### 1. Clone and build |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- .NET 6 SDK or later installed |
| 20 | +- A Dataverse solution zip containing `customizations.xml` |
| 21 | + |
| 22 | +Check SDK: |
| 23 | + |
| 24 | +```sh |
| 25 | +dotnet --version |
| 26 | +``` |
| 27 | + |
| 28 | +## Build |
16 | 29 |
|
17 | 30 | ```sh |
18 | | -git clone https://github.com/EricLott/DataversePluginWrapper.git |
19 | | -cd DataversePluginWrapper |
| 31 | +dotnet restore |
20 | 32 | dotnet build |
21 | 33 | ``` |
22 | 34 |
|
23 | | -### 2. Run |
| 35 | +## Run |
| 36 | + |
| 37 | +### Interactive mode (recommended for first-time use) |
| 38 | + |
| 39 | +Run with no arguments: |
24 | 40 |
|
25 | 41 | ```sh |
26 | | -dotnet run -- -z path/to/your/solution.zip -o ./Generated |
| 42 | +dotnet run -- |
27 | 43 | ``` |
28 | 44 |
|
29 | | -## Usage |
| 45 | +You will be prompted for: |
| 46 | +- solution zip path |
| 47 | +- output directory |
| 48 | +- optional entity-name filter |
| 49 | +- verbose logging toggle |
| 50 | +- overwrite behavior |
| 51 | +- final confirmation |
30 | 52 |
|
31 | | -```text |
32 | | -DataverseWrapper -z <path_to_solution_zip> [options] |
33 | | -DataverseWrapper (interactive mode) |
| 53 | +### CLI mode |
34 | 54 |
|
35 | | -Options: |
36 | | - -z, --zip <path> Path to Dataverse solution zip (required) |
37 | | - -o, --out <dir> Output directory (default: ./GeneratedClasses_{timestamp}) |
38 | | - -f, --filter <text> Only generate for entities whose display name contains text |
39 | | - -v, --verbose Verbose logging |
40 | | - -y, --yes Overwrite existing files without prompt |
41 | | - -h, --help Show help |
| 55 | +```sh |
| 56 | +dotnet run -- -z <path_to_solution_zip> [options] |
42 | 57 | ``` |
43 | 58 |
|
44 | | -If you run the executable with no arguments, it starts a guided interactive flow and prompts for zip path, output folder, optional filter, and overwrite behavior. |
| 59 | +Options: |
| 60 | + |
| 61 | +- `-z, --zip <path>`: path to Dataverse solution zip (required) |
| 62 | +- `-o, --out <dir>`: output directory (default: `./GeneratedClasses_{timestamp}`) |
| 63 | +- `-f, --filter <text>`: generate only entities whose display name contains text |
| 64 | +- `-v, --verbose`: verbose logging |
| 65 | +- `-y, --yes`: overwrite existing files without prompt |
| 66 | +- `-h, --help`: show help |
45 | 67 |
|
46 | | -### Examples |
| 68 | +### CLI examples |
47 | 69 |
|
48 | | -Generate all: |
| 70 | +Generate everything: |
49 | 71 |
|
50 | 72 | ```sh |
51 | 73 | dotnet run -- -z ./MySolution.zip |
52 | 74 | ``` |
53 | 75 |
|
54 | | -Generate entities containing "Contact": |
| 76 | +Generate only entities containing `Contact`: |
55 | 77 |
|
56 | 78 | ```sh |
57 | 79 | dotnet run -- -z ./MySolution.zip -f Contact |
58 | 80 | ``` |
59 | 81 |
|
60 | | -Overwrite without prompts: |
| 82 | +Write to a fixed folder and overwrite existing files: |
61 | 83 |
|
62 | 84 | ```sh |
63 | | -dotnet run -- -z ./MySolution.zip -o ./OutDir -y |
| 85 | +dotnet run -- -z ./MySolution.zip -o ./Generated -y |
64 | 86 | ``` |
65 | 87 |
|
66 | | -## Output Structure |
| 88 | +## Publish an EXE |
| 89 | + |
| 90 | +Windows x64 example: |
| 91 | + |
| 92 | +```sh |
| 93 | +dotnet publish -c Release -r win-x64 --self-contained false |
| 94 | +``` |
| 95 | + |
| 96 | +Output executable will be under: |
| 97 | + |
| 98 | +`bin/Release/net6.0/win-x64/publish/` |
| 99 | + |
| 100 | +Run the EXE directly: |
| 101 | +- no args -> interactive mode |
| 102 | +- with args -> CLI mode |
| 103 | + |
| 104 | +## Output Layout |
67 | 105 |
|
68 | 106 | ```text |
69 | | -GeneratedClasses_20250919/ |
| 107 | +GeneratedClasses_20260221_153000/ |
70 | 108 | |-- OptionSets/ |
71 | 109 | | `-- OptionValueSets.cs |
72 | 110 | `-- Entities/ |
73 | 111 | |-- Account.cs |
74 | 112 | |-- Contact.cs |
75 | 113 | `-- ... |
76 | 114 | ``` |
| 115 | + |
| 116 | +## Generated Code Notes |
| 117 | + |
| 118 | +- Generated entity wrappers use Dataverse SDK types (`IOrganizationService`, `Entity`, `EntityReference`, `OptionSetValue`, etc.). |
| 119 | +- Option set/state values are mapped to enums where possible. |
| 120 | +- Status reason is generated as numeric backing (`int?`) with enum helper behavior. |
| 121 | +- Lookups/owners/customers are generated as `EntityReference`. |
| 122 | + |
| 123 | +## Consuming Generated Files |
| 124 | + |
| 125 | +In the project where you use generated files, ensure Dataverse SDK references are available (for example, `Microsoft.Xrm.Sdk`). |
| 126 | + |
| 127 | +If your consuming project does not reference SDK assemblies, generated files will not compile. |
| 128 | + |
| 129 | +## Exit Codes |
| 130 | + |
| 131 | +- `0`: success |
| 132 | +- `1`: unexpected error |
| 133 | +- `2`: argument/path error |
| 134 | +- `3`: XML parsing error |
| 135 | +- `4`: invalid data shape |
| 136 | +- `130`: user canceled (Ctrl+C or interactive cancel) |
| 137 | + |
| 138 | +## Troubleshooting |
| 139 | + |
| 140 | +### "customizations.xml not found in zip" |
| 141 | + |
| 142 | +- Ensure the zip is a Dataverse solution export. |
| 143 | +- Verify the archive includes `customizations.xml`. |
| 144 | + |
| 145 | +### No entities generated |
| 146 | + |
| 147 | +- Check whether `--filter` excluded all entities. |
| 148 | +- Run without filter to validate metadata extraction. |
| 149 | + |
| 150 | +### Existing files are skipped |
| 151 | + |
| 152 | +- Use `-y`/`--yes`, or answer `y` at overwrite prompts. |
| 153 | + |
| 154 | +### Build succeeds but generated code fails in another project |
| 155 | + |
| 156 | +- Add Dataverse SDK references to the consuming project. |
| 157 | +- Validate that generated namespace/import placement matches your project conventions. |
| 158 | + |
| 159 | +## Development |
| 160 | + |
| 161 | +Local project files: |
| 162 | +- `Program.cs`: generator implementation |
| 163 | +- `DataversePluginWrapper.csproj`: project configuration |
| 164 | + |
| 165 | +Build locally before committing: |
| 166 | + |
| 167 | +```sh |
| 168 | +dotnet build |
| 169 | +``` |
0 commit comments