33

Let's say you want to temporarily exclude a .config file from being applied as a patch by Sitecore. Normally, you would either:

  • Delete the file;
  • Or rename it to have an extension different from .config.

Is there any other way of disabling a .config file? I don't want to change the file name or its contents (due to deployment process intricacies).

  • Can you just not have the file get deployed? Alternatively, can you deploy it to a different target outside of the App_Config/Include folder? – George Chang Oct 13 '16 at 12:53
  • @GeorgeChang I want to keep the file deployed. I don't want to change the deployment process to not include the file. I just want Sitecore to ignore the file for now. – Dmytro Shevchenko Oct 13 '16 at 12:54
  • What are you using to deploy? OctupusDeploy? Or Gulp Scripts or Nant scripts? – Anicho Oct 13 '16 at 13:05
  • @Anicho OctopusDeploy, although it's not really relevant to the question. – Dmytro Shevchenko Oct 13 '16 at 13:05
  • Ahh okay, was going to write some powershell script to make the file hidden just in case you dont have access to the server. So it could be a step which can be turned on and off or run individually. – Anicho Oct 13 '16 at 13:12
73

You can set the "Hidden" file attribute. Sitecore will not patch in any hidden files, even if they have the .config extension. The same is also true for folders, setting the "Hidden" attribute will mean the folder is not processed and the files contained within will not be loaded either.

Hidden property

You can find the exact code in LoadAutoIncludeFiles() method in Sitecore.Configuration.ConfigReader class:

protected virtual void LoadAutoIncludeFiles(ConfigPatcher patcher, string folder)
{
    if (!Directory.Exists(folder))
      return;
    foreach (string file in Directory.GetFiles(folder, "*.config"))
    {
        if ((File.GetAttributes(file) & FileAttributes.Hidden) == (FileAttributes) 0)
          patcher.ApplyPatch(file);
    }
    foreach (string directory in Directory.GetDirectories(folder))
    {
        if ((File.GetAttributes(directory) & FileAttributes.Hidden) == (FileAttributes) 0)
          this.LoadAutoIncludeFiles(patcher, directory);
    }
}

NOTE: The above is decompiled code and I have modified it for berevity.

  • 1
    That's very cool. Learn something new every day. – George Chang Oct 13 '16 at 12:58
  • I did not know this! Thanks @jammykam! – Jason St-Cyr Oct 13 '16 at 13:46
  • Good one @jammykam! – Varun Shringarpure Oct 13 '16 at 13:52
  • uCommerce configuration works similar to Sitecore one with one difference. A folder name ending with ".disabled" isn't processed. Sitecore could add this behavior to its logic. – jflheureux Oct 13 '16 at 14:09
  • Nice, learned something new today! – Srikanth Kondapally Oct 13 '16 at 14:23
10

You can make your configuration file hidden, which will cause Sitecore to NOT read that configuration file.

But, don't know how to set the hidden attribute automatically from the deployment process.

One option would be, you manually set the file properties to hidden on the server/instance and then stop the already existing file deployment to that certain folder. (But, this will also introduce a problem in case you change any configuration on those files)

  • As mentioned, I don't want to change the deployment process. I just want to make Sitecore ignore the file for the time being. Which is perfectly achieved by making the file hidden (as yours and jammykam's answers suggest). – Dmytro Shevchenko Oct 13 '16 at 13:00
8

Wrap the context in comment tags. Or you could drop another patch file in below it to overwrite that patch. Maybe those are obvious, but figured I would throw them out anyways.

  • Along the same lines, I have used slow cheetah to add different versions of config files, including blank nodes. This way the file exists in the project, and source control, and transforms it's way out of deployment. – MikeD Oct 14 '16 at 0:14
7

Hoping this answer will help someone in the future, Sitecore 9 now has this feature. You can disable any config file or folder by Adding the patch file to a section and add the mode="Off" attribute. for example:

1 <add path="Sitecore.Analytics.Config" type="File" mode="Off" /> 

2 <add path="zCustom" type="Folder" mode="Off" />

for more information you can check https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/customizing_server_configuration/disable_a_patch_file#_Disable_a_single

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.