internal virtual Task ProcessExtensionsProject()

in src/WebJobs.Script/BindingExtensions/ExtensionsManager.cs [125:207]


        internal virtual Task ProcessExtensionsProject(string projectFolder)
        {
            string dotnetPath = DotNetMuxer.MuxerPathOrDefault();
            var logBuilder = new StringBuilder();

            var tcs = new TaskCompletionSource<object>();

            _logger.ExtensionsManagerRestoring();

            try
            {
                var startInfo = new ProcessStartInfo
                {
                    FileName = dotnetPath,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    ErrorDialog = false,
                    WorkingDirectory = projectFolder,
                    Arguments = $"build \"{ExtensionsProjectFileName}\" -o bin --force --no-incremental"
                };

                string nugetPath = Path.Combine(Path.GetDirectoryName(DefaultExtensionsProjectPath), "nuget.config");
                if (File.Exists(nugetPath))
                {
                    startInfo.Arguments += $" --configfile \"{nugetPath}\"";
                }

                if (ScriptSettingsManager.Instance.IsAppServiceEnvironment)
                {
                    string nugetCacheLocation = Path.Combine(ScriptSettingsManager.Instance.GetSetting(EnvironmentSettingNames.AzureWebsiteHomePath), ".nuget");
                    startInfo.Arguments += $" --packages \"{nugetCacheLocation}\"";
                }

                SetupProcessEnvironment(startInfo);
                ApplyNugetFallbackFolderConfiguration(startInfo);

                var process = new Process { StartInfo = startInfo };
                process.ErrorDataReceived += (s, e) => logBuilder.Append(e.Data);
                process.OutputDataReceived += (s, e) => logBuilder.Append(e.Data);
                process.EnableRaisingEvents = true;

                process.Exited += (s, e) =>
                {
                    int exitCode = process.ExitCode;
                    process.Close();

                    if (exitCode != 0)
                    {
                        tcs.SetException(CreateRestoreException(logBuilder));
                    }
                    else
                    {
                        ProcessResults(projectFolder)
                            .ContinueWith(t =>
                            {
                                if (t.IsFaulted)
                                {
                                    tcs.SetException(CreateRestoreException(logBuilder, t.Exception));
                                }
                                else
                                {
                                    tcs.SetResult(null);
                                    _logger.ExtensionsManagerRestoreSucceeded();
                                }
                            });
                    }
                };

                process.Start();

                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
            }
            catch (Exception exc)
            {
                // Trace errors...
                tcs.SetException(CreateRestoreException(logBuilder, exc));
            }

            return tcs.Task;
        }