X++ 代码开发与部署
erp-xpp
面向 Finance and Operations 的 X++ 代码开发生命周期——搭建模型、编写类、自定义服务/API 和数据实体,安装匹配的 SDK,编译可部署包、部署包、同步数据库,并验证已部署的工件。当用户明确要求创建、构建、编译、打包、部署 X++ 自定义项、同步数据库或进行验证,或进行端到端的 ERP 代码变更时使用。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 258
- Forks
- 65
01 前言 Front Matter
- name
- erp-xpp
- description
- X++ code development lifecycle for Finance and Operations — scaffold models, author classes, custom services/APIs, and data entities, install matching SDKs, compile deployable packages, deploy packages, synchronize databases, and verify deployed artifacts. Use when the user explicitly requests creating, building, compiling, packaging, deploying, DB-syncing, or verifying X++ customizations, or an end-to-end ERP code change.
02 资源文件 4
- 参考文档references/authoring.md16.4 KB
- 参考文档references/commands.md5.2 KB
- 参考文档references/validation.md15.5 KB
- 参考文档references/workflows.md8.7 KB
03 SKILL.md 正文
Skill: Finance and Operations X++ Development
Critical safety rules — read first
- Windows only.
pac tool xpp installandpac package compile --package-type erprequire Windows. Do not invent a Linux/macOS or SDK-based fallback.- Confirm the target before any deploy or DB sync. Show the Dataverse environment URL, obtain explicit confirmation, then run
pac org who --environment <url>and verify both the Dataverse URL and linked ERP URL/version.- Never assume Full DB sync. Although standalone
pac package db-syncdefaults toFull, require the user to chooseFull,Module, orIncrementalwhen the request is ambiguous.- Do not call deployment successful until PAC reaches a successful terminal state. Preserve and report the async operation ID on failure.
- Do not overwrite existing models or source files. Inspect
.erp/xpp.json, descriptors, and target metadata paths before scaffolding or editing.- Pin every runtime surface before ERP verification. PAC and the Dataverse CLI have separate active profiles. Before any
dataverse ... --target erpcheck, requiredataverse auth whoanddataverse org who --jsonto match the confirmed Dataverse and linked ERP URLs. Validate ERP MCP according to its transport: direct HTTP must target<erp-url>/mcp; an stdio proxy must receive the base<erp-url>and route effectively to/mcp. Profile selection does not retarget an existing MCP connection.- Treat runtime verification as possible data mutation. After the separate post-deployment opt-in, inspect the X++ implementation, disclose exact test inputs and expected mutations, and obtain confirmation for those inputs and effects. Do not apply a generic test matrix to non-idempotent operations.
- All additional validation after an ERP X++ package deployment is opt-in. After
pac package deploy --package-type erp, capture PAC's terminal result, then ask whether the user wants any further validation and which checks to run. Do not query the async operation, execute an X++ artifact, query its ERP entity, or test its security unless selected. For runtime validation, confirm exact inputs, success criteria, and failure criteria; never invent values or execute an unapproved failure path. This rule is scoped to ERP X++ package deployment, not Dataverse solution ALM.
PAC CLI is the managed surface for the X++ lifecycle. Do not replace these commands with raw Dataverse APIs, direct calls to the ERP sidecar, LCS upload automation, or hand-written compiler invocations.
For a planning-only X++ request, loading skills and reading local references is allowed; do not make environment calls or write local files.
Intent routing
| User intent | Action |
|---|---|
| Create an ERP package/model | pac package init --package-type erp |
| Install compiler metadata for an environment | pac tool xpp install |
| Check/remove local SDKs | pac tool xpp list / pac tool xpp uninstall |
| Compile or build X++ | pac package compile --package-type erp |
| Deploy one prebuilt ZIP | pac package deploy --package-type erp --package <zip> |
| Deploy all models in a repo | pac package deploy --package-type erp --solution-root <root> |
| Run DB sync only | pac package db-sync |
| Create an ERP custom service | Author its X++ class/contracts plus AxService and AxServiceGroup metadata, then compile and deploy |
Create an ERP ICustomAPI action |
Author an ICustomAPI class, action menu item, and privilege/duty/role security, then compile, deploy, DB-sync when required, and verify through ERP MCP |
| Author, compile, deploy, and verify | Follow End-to-end workflow |
There is no pac package build or top-level pac xpp command. For ERP, pac package compile --package-type erp compiles labels and X++, runs best-practice checks, and builds deployable managed ZIPs.
Skill boundaries
| Need | Use instead |
|---|---|
| Connect/authenticate, install or update PAC CLI | dv-connect |
| Read or analyze ERP business data | dv-query |
| Explicit direct developer-database SQL access or temporary SQL credentials | erp-sql |
| Create/update/delete ERP business records or import DMF data | dv-data |
| List/cancel ERP batch jobs | dv-admin |
| Dataverse solution ALM | dv-solution |
| ERP UI personalization, workflow editing, or environment lifecycle | Finance and Operations UI / Power Platform admin tooling; not covered |
Preflight
- Confirm Windows.
- Run
pacand inspect its banner;pac --versionis invalid. These commands require the PAC CLI .NET tool version 2.11.1 or later. - Run
pac package helpandpac tool xpp help. Ifcompile,db-sync, ortool xppis absent, load dv-connect and update to the latest .NET tool installation before continuing. - For environment operations, run:
pac auth list
pac org who --environment <dataverse-url>
The output must identify the confirmed Dataverse environment and include a linked ERP URL/version. Do not substitute the ERP URL for --environment; PAC accepts the Dataverse URL and resolves ERP linkage.
- Before runtime verification through the Dataverse CLI or ERP MCP, run:
dataverse auth who
dataverse org who --json \
--context "app=dataverse-skills/<ver>;skill=erp-xpp;agent=<agent>"
Require the selected CLI profile's environment URL and returned erpUrl to match the PAC target confirmed above. If they do not, run dataverse auth select --name <profile-name>, then repeat both checks. Pass --environment <dataverse-url> on commands that support it, but never treat that option as a substitute for selecting the correct profile; some ERP data commands have no environment override.
For ERP MCP verification, inspect the active server configuration. Require direct HTTP to use the confirmed <erp-url>/mcp, or require an stdio proxy such as dataverse mcp to receive the confirmed base <erp-url> and use its effective /mcp endpoint. If it differs, stop and reconnect or reinitialize the matching ERP MCP server before discovery or invocation.
Before every MCP runtime invocation, establish a fresh transport-specific session and verify its caller through an MCP-originated identity/current-session check. dataverse auth who proves only the CLI identity. If MCP cannot prove its caller, do not invoke through that session. For security acceptance, the proven caller must be the intended non-administrator test user.
- Before a first SDK install, explain that it downloads roughly 4 GB and expands to roughly 16 GB under
%LOCALAPPDATA%\Microsoft\Dynamics365\<version>\PackagesLocalDirectory.
Command quick reference
# Scaffold one or more models
pac package init --outputDirectory <root> --package-type erp \
--model <ModelA,ModelB> --publisher <publisher> --layer ISV
# SDK lifecycle
pac tool xpp install --environment <dataverse-url>
pac tool xpp list
pac tool xpp uninstall --version <four-part-version>
# Compile/build all configured models
pac package compile --solution-root <root> --package-type erp \
--app-version <four-part-version> --language en-US
# Compile one model during the edit loop
pac package compile --solution-root <root> --package-type erp \
--model <ModelName> --app-version <four-part-version> \
--language en-US --incremental
# Deploy one compiled package, without DB sync
pac package deploy --environment <dataverse-url> --package-type erp \
--package <root>/bin/<Model>_<version>_managed.zip \
--build-type Full --release-type Dev --db-sync None \
--logConsole --logFile <deployment-log-path>
# Deploy every model in .erp/xpp.json in dependency order
pac package deploy --environment <dataverse-url> --package-type erp \
--solution-root <root> --build-type Full --release-type Dev \
--db-sync None --logConsole --logFile <deployment-log-path>
Use explicit values rather than relying on defaults in automation. Full argument tables and DB-sync rules are in references/commands.md.
Authoring X++ source
The repo root contains .erp/xpp.json; source defaults to src/. Each model has a descriptor and metadata under:
<root>/
.erp/xpp.json
src/<Model>/Descriptor/<Model>.xml
src/<Model>/<Model>/AxClass/<Class>.xml
Run pac package init instead of hand-writing the descriptor/config. Add metadata files surgically after inspecting existing paths. PAC compiles and packages authored metadata; it does not scaffold custom services, ICustomAPI actions, or data entities. For runnable classes, labels, custom services, ICustomAPI actions, public OData data entities, and artifact-specific verification, use references/authoring.md.
Compile/build rules
- A normal compile runs labels -> X++ -> best-practice checks -> deployable ZIP.
- Use
--incrementalonly for the edit loop. Run a non-incremental compile before a final deployment. - Do not use
--skip-bpunless the user explicitly requests it and understands the reduced validation. - If multiple SDKs are installed, pass
--app-version; otherwise PAC may reject ambiguous selection. - Treat
Compile summary: ... failedor any nonzero exit as failure even if a ZIP already exists from an earlier run. - Verify the output ZIP was produced by the current run under
<root>/bin/. - If label compilation reports
XPPLC2010and PAC fails despite exit code 0 from LabelC, add a valid label resource; do not delete logs or bypass the stage.
Deploy and DB-sync rules
- Deploy-only means
--db-sync None. --build-typecontrols how the server applies the package:Full,Incremental, orDelete; it is not a local build command.--release-type Devis the normal test/development choice.Releaseforces Full DB sync server-side when a sync is requested.Deleteignores DB-sync settings.- Single-package deployment uses
--package <zip>. Solution-mode deployment omits--package, reads.erp/xpp.json, topologically orders models, deploys them, then runs one requested DB sync. - PAC injects
fnomoduledefinition.jsoninto the ZIP at deploy time. Copy the artifact first if an immutable checksum must be retained. - Standalone DB sync and deploy-with-sync are separate supported workflows; never redeploy merely to satisfy a DB-sync-only request.
See references/workflows.md for compile-only, deploy-only, DB-sync-only, multi-model, and full lifecycle sequences. Apply the success gates, diagnostics flow, and error mappings in references/validation.md to every compile, deployment, DB sync, and runtime verification.
End-to-end workflow
For “make this X++ change and deploy it”:
- Inspect the repo and preserve existing work.
- Confirm model/class names, publisher, and layer before scaffolding a new model.
- Run
pac package init --package-type erponly when the model does not exist. - Add or edit the requested X++ metadata, such as classes, contracts, custom services, service groups,
ICustomAPIactions and security, public data entities, and required labels. - Confirm/authenticate the target environment and verify ERP linkage/version.
- Install or reuse the matching SDK.
- Compile non-incrementally and require zero compile errors. Address best-practice warnings unless the user accepts them.
- Deploy with explicit build/release/DB-sync modes.
- Capture PAC's exit code, async operation ID, terminal state, and DB-sync result as part of the deployment command. Do not run additional validation automatically.
- Ask whether the user wants post-deployment validation and which checks they authorize: async-operation re-query, API/action discovery, runtime behavior, data-entity query, multiple-case testing, and/or security acceptance. Earlier deployment approval and selection of one check do not authorize another.
- If all validation is declined, report the PAC deployment result and state that no additional validation was performed. If runtime validation is selected, inspect only the deployed custom artifact and its contract, then ask for each required input plus the expected success and failure criteria. Repeat exact values or criteria already in the prompt for confirmation; never invent or broaden them.
- For selected runtime checks, pin the Dataverse CLI profile and transport-specific ERP MCP target to the confirmed environment, then verify only the approved artifact:
- Runnable class: open
https://<erp-host>/?mi=SysClassRunner&cls=<ClassName>. - Custom service: inspect the X++ implementation for side effects before invoking
erp:<ServiceGroup>/<Service>/<Operation>withdataverse api invoke --target erp --context "app=dataverse-skills/<ver>;skill=erp-xpp;agent=<agent>"; uselist/describeonly for discovery. ICustomAPIaction: if discovery was selected, use ERP MCPapi_find_actionsto validate its action menu item and contract. If execution was selected, invoke only approved inputs using the confirmed source contract or approved discovery result, then compare every returned property and expected mutation with the observed result.- Public OData data entity: if discovery was selected, inspect it with
dataverse data describe --target erp. If query execution was selected, query the confirmed entity set withdataverse data query --target erp. Add--context "app=dataverse-skills/<ver>;skill=erp-xpp;agent=<agent>"to each command that runs. - Security acceptance: only when runtime execution and security acceptance were both selected, invoke the approved case as a non-administrator test user assigned the intended custom role. Administrator execution is diagnostic only and does not validate the privilege/duty/role chain.
- Report the package path, environment, async operation ID, terminal status, DB-sync mode, the validation checks accepted or declined, and results only for checks actually performed.
Common mistakes — do not use these
| Wrong | Correct |
|---|---|
pac xpp install |
pac tool xpp install |
pac xpp compile |
pac package compile --package-type erp |
pac package build |
pac package compile --package-type erp |
pac package deploy --package-type xpp |
--package-type erp |
Passing the ERP URL to --environment |
Pass the linked Dataverse URL |
Omitting --package for one ZIP |
Add --package <zip> |
Adding --package for repo-wide deployment |
Omit it and use --solution-root |
pac package db-sync --db-sync None |
None is deploy-only; standalone modes are Full, Module, Incremental |
Module sync without --modules |
Add --modules ModelA,ModelB |
Incremental sync without --argument-file |
Add a valid IncrementalSyncParameters JSON file |
04 同仓库更多 Skills
erp-sql
Temporary Finance and Operations SQL access and bounded physical-table reads for unified development environments (UDEs) only, requiring the environment System administrator (sysAdmin) role. Use when the user explicitly requests direct ERP SQL access, a temporary SQL password, a sqlcmd connection, or a table read in an established ERP SQL workflow.
Dataverse 解决方案部署管理
dv-solution
Dataverse 解决方案生命周期——创建、导出、导入、跨环境提升以及验证部署。当用户想要打包自定义配置、部署到其他环境,或在开发/测试/生产环境之间迁移工作成果时使用。
Dataverse 安全权限管理
dv-security
Dataverse 环境中的安全角色分配、用户访问、应用程序用户、业务单元以及管理员自我提权。当用户想要授予某人访问权限、授予角色、成为管理员或添加服务主体时使用。
Dataverse 数据查询分析
dv-query
对 Dataverse 数据进行批量读取、多页迭代和分析。当用户想要读取、列出、筛选、聚合、分组、联接或分析记录时使用——包括 pandas DataFrame 工作流和 notebook 探索。还涵盖 ERP(Finance and Operations / F&O)业务数据读取,以及运行时实体、架构或操作发现;请先加载 dv-overview,再加载本技能。
Dataverse/Power Platform 总览
dv-overview
Dataverse / Power Platform 工作的基础性跨领域上下文——包括范围与技能图谱、工具能力参考、安全规则以及安全变更生命周期。当用户提及 Dataverse、Dynamics 365、Power Platform、CRM 或 ERP 时使用;应首先加载此技能以进行定位。专家技能通过其自身的 frontmatter 触发器自行路由。财务与运营(Finance and Operations / F&O)业务数据请求也需要先加载此技能,然后再使用 dv-query 进行读取。
Dataverse 数据模型设计与查看
dv-metadata
Dataverse 架构编写与检查——表、列、关系、表单和视图。当用户希望定义、演进或检查数据模型时使用——添加列、创建表、设置查找(lookup)、自定义表单、构建视图,或列出现有的列和关系。