I am trying to build a provisioning process for standard classic team sites that have the Publishing feature enabled (modern is not well-enough baked yet for our needs). When I get to the step of activating the publishing site collection feature using:
I have to wait while the site collection feature is activated. To do this, I have a loop that (re)loads the site and site features and checks to see if the publishing feature is in the site.Features collection yet. Once the feature is activated, I can then activate the Web-level publishing feature and finish provisioning my corporate branding.
This code works with the Publishing, Project, and Community templates. However, when I try to use it on a classic Team site template, the publishing feature never appears in the list of activated features. I've tried reloading all of my objects (site, site Features, etc.) except for the context itself to no avail. If I go to the site through the UI, I can see that the site feature has been activated and is ready for use.
Do I have to load a new context in order to get an accurate list of activated features for my site collection?