Configure your environment

You can create an environment configuration file that allows you to define and control environment settings for all your environments (for example, development and production) in one place. You do this by creating a new application setting that's specific to the current environment, and overrides other environment configurations.

To create an environment-specific configuration:

  1. Create a web.config.xdt transformation file that includes a new app setting, for example, setting the environment name to DEV:

    RequestResponse
    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
        <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(key)" key="customenvironment:define" value="DEV" />
      </appSettings>
    </configuration>
  2. Include the web config file in the Platform project:

    RequestResponse
    <ItemGroup>
        <Content Include="xdts\Web.config.xdt">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
     </ItemGroup>
  3. In the build configuration file (xmcloud.build.json), create a mapping for the xdt file:

    RequestResponse
    "transforms": [
          {
            "xdtPath": "/xdts/web.config.xdt",
            "targetPath": "/web.config"
          }  
        ]
    XM Cloud is now SitecoreAI

    Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

  4. Create an environment variable named SITECORE_APPSETTINGS_customenvironment__define. This overrides the customenvironment app setting. Enter a meaningful value for the variable: in this example, in step 1, the default name is set to DEV, and you can use this variable to change it to PROD.

  5. Create an environment-specific configuration in the settings attribute and include it in the project. This example shows how you use the new app setting to drive other configurations:

    RequestResponse
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:customenvironment="http://www.sitecore.net/xmlconfig/pskenvironment/">
      <sitecore>
        <settings>
          <setting name="Xdt.Test" value="None">
            <patch:attribute name="value" value="DEV" customenvironment:require="DEV" />
            <patch:attribute name="value" value="QA" customenvironment:require="QA" />
          </setting>
        </settings>
      </sitecore>
    </configuration>
  6. Create a build and deploy it. This is required for the changes to take effect.

Do you have some feedback for us?

If you have suggestions for improving this article,