/// <summary> /// Ensure the the environment variable MSBuildDisableFeaturesFromWave is set to a proper value. /// </summary> /// <returns> String representation of the set change wave. "999.999" if unset or invalid, and clamped if out of bounds. </returns> internal static void ApplyChangeWave() { Version changeWave; // If unset, enable all features. if (DisabledWave.Length == 0 || DisabledWave.Equals(EnableAllFeatures, StringComparison.OrdinalIgnoreCase)) { ConversionState = ChangeWaveConversionState.Valid; DisabledWave = ChangeWaves.EnableAllFeatures; return; } // If the version is of invalid format, log a warning and enable all features. if (!Version.TryParse(DisabledWave, out changeWave)) { ConversionState = ChangeWaveConversionState.InvalidFormat; DisabledWave = ChangeWaves.EnableAllFeatures; return; } // If the version is 999.999, we're done. else if (changeWave == EnableAllFeaturesAsVersion) { ConversionState = ChangeWaveConversionState.Valid; DisabledWave = changeWave.ToString(); return; } // If the version is out of rotation, log a warning and clamp the value. else if (changeWave < LowestWaveAsVersion) { ConversionState = ChangeWaveConversionState.OutOfRotation; DisabledWave = LowestWave; return; } else if (changeWave > HighestWaveAsVersion) { ConversionState = ChangeWaveConversionState.OutOfRotation; DisabledWave = HighestWave; return; } // Ensure it's set to an existing version within the current rotation if (!AllWavesAsVersion.Contains(changeWave)) { foreach (Version wave in AllWavesAsVersion) { if (wave > changeWave) { ConversionState = ChangeWaveConversionState.Valid; DisabledWave = wave.ToString(); return; } } } ConversionState = ChangeWaveConversionState.Valid; DisabledWave = changeWave.ToString(); }
/// <summary> /// Read from environment variable `MSBuildDisableFeaturesFromVersion`, correct it if required, cache it and its ConversionState. /// </summary> internal static void ApplyChangeWave() { // Once set, change wave should not need to be set again. if (!ShouldApplyChangeWave) { return; } string msbuildDisableFeaturesFromVersion = Environment.GetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION"); // Most common case, `MSBuildDisableFeaturesFromVersion` unset if (string.IsNullOrEmpty(msbuildDisableFeaturesFromVersion)) { ConversionState = ChangeWaveConversionState.Valid; _cachedWave = ChangeWaves.EnableAllFeatures; } else if (!Version.TryParse(msbuildDisableFeaturesFromVersion, out _cachedWave)) { ConversionState = ChangeWaveConversionState.InvalidFormat; _cachedWave = ChangeWaves.EnableAllFeatures; } else if (_cachedWave == EnableAllFeatures || AllWaves.Contains(_cachedWave)) { ConversionState = ChangeWaveConversionState.Valid; } else if (_cachedWave < LowestWave) { ConversionState = ChangeWaveConversionState.OutOfRotation; _cachedWave = LowestWave; } else if (_cachedWave > HighestWave) { ConversionState = ChangeWaveConversionState.OutOfRotation; _cachedWave = HighestWave; } // _cachedWave is somewhere between valid waves, find the next valid version. else { _cachedWave = AllWaves.First((x) => x > _cachedWave); ConversionState = ChangeWaveConversionState.Valid; } }
/// <summary> /// Resets the state and value of the currently disabled version. /// Used for testing only. /// </summary> internal static void ResetStateForTests() { _cachedWave = null; _state = ChangeWaveConversionState.NotConvertedYet; }
/// <summary> /// Resets the state and value of the currently disabled version. /// </summary> public static void ResetStateForTests() { DisabledWave = null; _state = ChangeWaveConversionState.NotConvertedYet; }