private async Task GetDurableMajorVersionAsync()

in src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs [569:623]


        private async Task<string> GetDurableMajorVersionAsync(JObject hostJson, ScriptJobHostOptions hostOptions)
        {
            string metadataFilePath;
            bool isUsingBundles = hostJson != null && hostJson.TryGetValue("extensionBundle", StringComparison.OrdinalIgnoreCase, out _);
            // This feature flag controls whether to opt out of the SyncTrigger metadata fix for OOProc DF apps from https://github.com/Azure/azure-functions-host/pull/9331
            if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableLegacyDurableVersionCheck))
            {
                // using legacy behavior, which concludes that out of process DF apps (including .NET isolated) are using DF Extension V1.x
                // as a result, the SyncTriggers payload for these apps will be missing some metadata like "taskHubName"
                if (isUsingBundles)
                {
                    return "1";
                }

                string binPath = binPath = Path.Combine(hostOptions.RootScriptPath, "bin");
                metadataFilePath = Path.Combine(binPath, ScriptConstants.ExtensionsMetadataFileName);
                if (!FileUtility.FileExists(metadataFilePath))
                {
                    return null;
                }
            }
            else
            {
                if (isUsingBundles)
                {
                    // From Functions runtime V4 onwards, only bundles >= V2.x is supported, which implies the app should be using DF V2 or greater.
                    return "2";
                }

                // If the app is not using bundles, we look for extensions.json
                if (!Utility.TryResolveExtensionsMetadataPath(hostOptions.RootScriptPath, out string metadataDirectoryPath, out _))
                {
                    return null;
                }
                metadataFilePath = Path.Combine(metadataDirectoryPath, ScriptConstants.ExtensionsMetadataFileName);
            }

            var extensionMetadata = JObject.Parse(await FileUtility.ReadAsync(metadataFilePath));
            var extensionItems = extensionMetadata["extensions"]?.ToObject<List<ExtensionReference>>();

            var durableExtension = extensionItems?.FirstOrDefault(ext => string.Equals(ext.Name, "DurableTask", StringComparison.OrdinalIgnoreCase));
            if (durableExtension == null)
            {
                return null;
            }

            var versionMatch = versionRegex.Match(durableExtension.TypeName);
            if (!versionMatch.Success)
            {
                return null;
            }

            // Grab the captured group.
            return versionMatch.Groups["majorversion"].Captures[0].Value;
        }