public virtual async Task SaveLaunchSettings()
        {
            ILaunchSettingsProvider provider = GetDebugProfileProvider();

            if (EnvironmentVariables != null && EnvironmentVariables.Count > 0 && SelectedDebugProfile != null)
            {
                SelectedDebugProfile.EnvironmentVariables.Clear();
                foreach (NameValuePair kvp in EnvironmentVariables)
                {
                    SelectedDebugProfile.EnvironmentVariables.Add(kvp.Name, kvp.Value);
                }
            }
            else if (SelectedDebugProfile != null)
            {
                SelectedDebugProfile.EnvironmentVariables.Clear();
            }

            await provider.UpdateAndSaveSettingsAsync(CurrentLaunchSettings.ToLaunchSettings());
        }
        /// <summary>
        /// Functions which actually does the save of the settings. Persists the changes to the launch settings
        /// file and configures IIS if needed.
        /// </summary>
        public async virtual System.Threading.Tasks.Task SaveLaunchSettings()
        {
            ILaunchSettingsProvider provider = GetDebugProfileProvider();

            if (EnvironmentVariables != null && EnvironmentVariables.Count > 0 && SelectedDebugProfile != null)
            {
                SelectedDebugProfile.EnvironmentVariables.Clear();
                foreach (var kvp in EnvironmentVariables)
                {
                    SelectedDebugProfile.EnvironmentVariables.Add(kvp.Name, kvp.Value);
                }
            }
            else if (SelectedDebugProfile != null)
            {
                SelectedDebugProfile.EnvironmentVariables.Clear();
            }

            await provider.UpdateAndSaveSettingsAsync(CurrentLaunchSettings.ToLaunchSettings()).ConfigureAwait(false);
        }
        internal virtual void InitializeDebugTargetsCore(ILaunchSettings profiles)
        {
            IWritableLaunchSettings newSettings = profiles.ToWritableLaunchSettings();

            // Since this get's reentered if the user saves or the user switches active profiles.
            if (CurrentLaunchSettings != null && !CurrentLaunchSettings.SettingsDiffer(newSettings))
            {
                return;
            }

            try
            {
                // This should never change the dirty state when loading the dialog
                PushIgnoreEvents();

                // Remember the current selection
                string curProfileName = SelectedDebugProfile?.Name;

                // Update the set of settings and generate a property change so the list of profiles gets updated. Note that we always
                // clear the active profile on the CurrentLaunchSettings so that when we do set one and property changed event is set
                CurrentLaunchSettings = newSettings;
                CurrentLaunchSettings.ActiveProfile = null;

                // Reload the launch profiles collection
                LaunchProfiles.Clear();
                foreach (IWritableLaunchProfile profile in CurrentLaunchSettings.Profiles)
                {
                    LaunchProfiles.Add(profile);
                }

                // When loading new profiles we need to clear the launch type. This is so the external changes cause the current
                // active provider to be refreshed
                _selectedLaunchType = null;
                NotifyProfileCollectionChanged();

                // If we have a selection, we want to leave it as is
                if (curProfileName == null || newSettings.Profiles.Find(p => LaunchProfile.IsSameProfileName(p.Name, curProfileName)) == null)
                {
                    // Note that we have to be careful since the collection can be empty.
                    if (profiles.ActiveProfile != null && !string.IsNullOrEmpty(profiles.ActiveProfile.Name))
                    {
                        SelectedDebugProfile = LaunchProfiles.Single(p => LaunchProfile.IsSameProfileName(p.Name, profiles.ActiveProfile.Name));
                    }
                    else
                    {
                        if (LaunchProfiles.Count > 0)
                        {
                            SelectedDebugProfile = LaunchProfiles[0];
                        }
                        else
                        {
                            SetEnvironmentGrid(null);
                        }
                    }
                }
                else
                {
                    SelectedDebugProfile = LaunchProfiles.Single(p => LaunchProfile.IsSameProfileName(p.Name, curProfileName));
                }
            }
            finally
            {
                PopIgnoreEvents();
                _firstSnapshotCompleteSource?.TrySetResult();
                _debugTargetsCoreInitialized = true;
            }
        }