🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
ContinuousIntegration
This page was created by Hans.karlsen on 2025-09-29. Last edited by Wikiadmin on 2026-07-29.

You can automate model code generation, solution rebuild, packaging, and upload to MDrivenServer from a CI runner by starting Visual Studio 2022 with the MDrivenFramework extension and model-automation settings.

What this automation does

Continuous integration (CI) automates the build, evolve, and deployment path so that each approved model change can be prepared consistently. MDriven model automation starts Visual Studio with both a solution and an .ecomdl model file. The MDrivenFramework extension then generates code, rebuilds the solution, and either uploads the resulting package to MDrivenServer or writes the package for a separate upload step.

Use this when you need to verify that generated code matches the model before deploying it. For example, a CI job can generate code from MDrivenModel.ecomdl, rebuild MySolution.sln, and submit the resulting model-and-code package to the MDrivenServer used by a Turnkey application.

Additional data changes needed after an evolve can be handled by ScriptAfterEvolve. Keep those changes separate from the build/package/upload automation described on this page.

Prerequisites

Before running the automation, ensure that the CI machine has:

  • Visual Studio 2022 installed. The automation starts devenv.exe.
  • The MDrivenFramework extension for Visual Studio 2022 installed. Obtain the VSIX from the MDriven download page.
  • A local checkout containing the solution file (.sln) and model file (.ecomdl).
  • A reachable MDrivenServer when using direct upload or when submitting a package manually.
  • An MDrivenServer account that is allowed to upload a model.

The CI account must also be able to read the source checkout and write the selected output directory or output files.

Choose an automation workflow

Workflow When to use it Result
Direct upload The CI job can contact MDrivenServer and you want Visual Studio automation to submit the package. Automation generates code, rebuilds, uploads to MDrivenServer, and MDrivenServer starts evolve.
Package only Packaging and upload are separate CI stages, or a different tool performs the HTTP upload. Automation produces a ZIP package and an automation-result log. A later step posts the ZIP to MDrivenServer.

Configure the automation

Set the following environment variables before starting Visual Studio. Environment variables apply to the process that starts Visual Studio; set them in the same command file or CI job step.

Variable Required Purpose
MODELAUTOMATION_URL Yes for direct upload URL of the target MDrivenServer.
MODELAUTOMATION_USER Yes for direct upload MDrivenServer account used by automation.
MODELAUTOMATION_PWD Yes for direct upload Password for the MDrivenServer account.
MODELAUTOMATION_OUTPUTDIRECTORY No Directory in which automation writes its log and package output.
MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME No Full path and file name for the log. This overrides MODELAUTOMATION_OUTPUTDIRECTORY for the log.
MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME No Full path and file name for the ZIP package. This overrides MODELAUTOMATION_OUTPUTDIRECTORY for the ZIP.
MODELAUTOMATION_PACKAGEONLY No Set to true to create a package without direct upload.
MODELAUTOMATION_PACKAGETAG No Tag appended to the default package name. It is ignored when MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME is set.

Do not put production credentials directly in a committed command file. Configure MODELAUTOMATION_USER and MODELAUTOMATION_PWD from your CI system's protected environment-variable or secret mechanism.

Run generation, rebuild, and direct upload

  1. Set the MDrivenServer URL, account, and password as environment variables.
  2. Set an output directory, or set explicit paths for the log and package.
  3. Start devenv.exe with the solution file followed by MODELAUTOMATION="<model-file>".
  4. Wait for Visual Studio to finish and quit.
  5. Read the automation log and fail the CI job if it reports an unsuccessful run.

The following Windows command-file example uses explicit output paths. Replace each placeholder with paths and server details for your environment.

@echo off
setlocal

rem Prevent a Visual Studio sign-in prompt from stopping the CI job.
set "VSSuppressUserAuthentication=true"

rem MDrivenServer connection used for direct upload.
set "MODELAUTOMATION_URL=https://YourMDrivenServerUrl"
set "MODELAUTOMATION_USER=TheAccountForMDrivenServer"
set "MODELAUTOMATION_PWD=ThePasswordForMDrivenServer"

rem Automation output.
set "MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME=C:\CI\output\MDRIVENAUTOMATIONRESULT.log"
set "MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME=C:\CI\output\ModelAndCodeForMDrivenServer.zip"

rem Source checkout and Visual Studio installation.
set "MODELFILE=C:\CI\source\MDrivenModel.ecomdl"
set "SLNFILE=C:\CI\source\MySolution.sln"
set "DEVENV=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe"

if exist "%MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME%" del "%MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME%"

"%DEVENV%" "%SLNFILE%" MODELAUTOMATION="%MODELFILE%"

if exist "%MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME%" (
  type "%MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME%"
) else (
  echo Automation log was not produced.
)

endlocal

The solution argument and the MODELAUTOMATION argument are both required: the solution supplies the projects to rebuild, and the model argument identifies the model to automate.

Create a package without uploading

Use package-only mode when the CI pipeline should retain the ZIP as an artifact or upload it in a later stage.

  1. Set MODELAUTOMATION_PACKAGEONLY=true before starting Visual Studio.
  2. Set MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME to control the ZIP location, or set MODELAUTOMATION_OUTPUTDIRECTORY to use the default output location.
  3. Optionally set MODELAUTOMATION_PACKAGETAG when using the default ZIP name.
  4. Start Visual Studio with the solution and MODELAUTOMATION arguments as shown above.
  5. Publish the generated ZIP as a CI artifact or submit it in the next stage.

When no explicit ZIP path is set, package-only mode produces ModelAndCodeForMDrivenServer<MODELAUTOMATION_PACKAGETAG>.zip together with MDRIVENAUTOMATIONRESULT.log. An explicit MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME takes precedence over the output directory and package tag.

Submit a package to MDrivenServer

Submit the package to this endpoint:

<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/SubmitNewModelCI

Send an HTTP POST with multipart byte-array content and HTTP Basic authentication. The authorization header contains Basic followed by the Base64 value of username:password. After MDrivenServer receives the model, it makes the model the current version and starts evolve.

This PowerShell example submits a package created by package-only automation:

$serverUrl = "https://YourMDrivenServerUrl"
$username  = "your-username"
$password  = "your-password"
$modelZip  = "C:\CI\output\ModelAndCodeForMDrivenServer.zip"

$pair    = "$username`:$password"
$bytes   = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64  = [System.Convert]::ToBase64String($bytes)
$headers = @{ Authorization = "Basic $base64" }

$response = Invoke-RestMethod -Uri "$serverUrl/api/ServiceAdmin_WebApi/SubmitNewModelCI" `
  -Method Post `
  -Headers $headers `
  -Form @{ file = Get-Item $modelZip }

$response

Poll evolve status

After submitting a model, query the CI status endpoint with the same HTTP Basic authentication:

<YourMDrivenServerUrl>/api/ServiceAdmin_WebApi/CurrentStatusCI

$status = Invoke-RestMethod -Uri "$serverUrl/api/ServiceAdmin_WebApi/CurrentStatusCI" `
  -Method Get `
  -Headers $headers

$status

For a CI pipeline, poll this endpoint after upload and use the returned status to decide whether the deployment stage succeeded. Preserve the automation log and package ZIP as job artifacts when diagnosing failures.

Troubleshooting

Symptom Check
Visual Studio waits for user input Set VSSuppressUserAuthentication=true before starting Visual Studio. Confirm that the MDrivenFramework extension is installed in that Visual Studio 2022 installation.
No log file appears Confirm that the CI account can write to the selected output location. If you expect a custom log file, set MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME; defining an unrelated LOGFILE variable does not configure automation output.
Package name or location is unexpected Check output precedence. The explicit log and ZIP path variables override MODELAUTOMATION_OUTPUTDIRECTORY; an explicit ZIP path also causes MODELAUTOMATION_PACKAGETAG to be ignored.
Upload is rejected or cannot connect Verify MODELAUTOMATION_URL, the server account credentials, and that the account is allowed to upload a model. For a separate upload step, verify the POST URL and Basic authentication header.
Upload completed but evolve has not finished Query CurrentStatusCI rather than treating a successful HTTP upload as completion of evolve.

See also

Automate code generation, rebuild, and upload

Automate code generation, rebuild, and upload

MDriven continuous integration can automate the steps needed to prepare and upload a model to MDrivenServer:

  1. Generate all code to ensure that code maps to the model.
  2. Rebuild all before upload for use with CodeDress.
  3. Upload to MDrivenServer to initiate evolve and database changes.

These automation features are provided through the MDrivenFramework extension for Visual Studio 2022. Start Visual Studio with both the solution and model paths:

"%DEVENV%" "%SLNFILE%" MODELAUTOMATION="%MODELFILE%"

Before starting Visual Studio, set the required MDrivenServer connection environment variables:

  • MODELAUTOMATION_URL
  • MODELAUTOMATION_USER
  • MODELAUTOMATION_PWD

The following output settings are also documented:

  • MODELAUTOMATION_OUTPUTDIRECTORY — optional output directory for log and package output.
  • MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME — overrides MODELAUTOMATION_OUTPUTDIRECTORY for the log output.
  • MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME — overrides MODELAUTOMATION_OUTPUTDIRECTORY for the ZIP output.

Visual Studio automation produces an MDRIVENAUTOMATIONRESULT.log file unless a full log path is supplied with MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME.

Keep MDrivenServer credentials outside source control and provide them through the CI system's protected secret or environment-variable mechanism.

See also

Continuous Integration Automation

MDriven supports automation of key build and deployment steps through the MDrivenFramework extension for Visual Studio 2022.

Automate model generation, build, and upload

The documented CI sequence is:

  1. Generate all code to ensure that generated code maps to the model.
  2. Rebuild all projects to ensure that assemblies are built before upload for CodeDress.
  3. Upload to MDrivenServer to initiate database evolve.

Start Visual Studio with the solution path and the model automation argument:

devenv.exe "<solution path>" MODELAUTOMATION="<model path>"

The documented example starts Visual Studio with a solution file as the first argument and an .ecomdl model file supplied through MODELAUTOMATION.

Required environment variables

Before starting Visual Studio automation, set these MDrivenServer connection variables:

  • MODELAUTOMATION_URL
  • MODELAUTOMATION_USER
  • MODELAUTOMATION_PWD

Optional output variables are:

  • MODELAUTOMATION_OUTPUTDIRECTORY
  • MODELAUTOMATION_OUTPUTLOGPATHANDFULLNAME
  • MODELAUTOMATION_OUTPUTZIPPATHANDFULLNAME

The full-path log and zip variables override MODELAUTOMATION_OUTPUTDIRECTORY. When no alternate log path is configured, the automation produces MDRIVENAUTOMATIONRESULT.log.

Example

The CI documentation provides an example command script in the MDrivenComponents repository:

supportMDriven\MDrivenComponents\MDrivenTurnkeyComponents\Samples\Automation\LaunchVSWithModelCodeGenFullBuildAllAndUploadToMDrivenServer.cmd

Configure the solution path, model path, Visual Studio executable path, MDrivenServer URL, user name, password, and output locations for your environment.

Source-code license note

The MDriven source-code license provides source files for debugging the MDriven product. The license terms state that the source files may not be modified, merged with other software, disclosed, distributed, transferred, or otherwise used except as expressly authorized.