dotnet-installer/build_projects/shared-build-targets-utils/Utils/EnvVars.cs
2017-03-02 21:04:03 -08:00

47 lines
1.4 KiB
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{
public class EnvVars
{
public static readonly bool Verbose = GetBool("DOTNET_BUILD_VERBOSE");
public static bool GetBool(string name, bool defaultValue = false)
{
var str = Environment.GetEnvironmentVariable(name);
if (string.IsNullOrEmpty(str))
{
return defaultValue;
}
switch (str.ToLowerInvariant())
{
case "true":
case "1":
case "yes":
return true;
case "false":
case "0":
case "no":
return false;
default:
return defaultValue;
}
}
public static string EnsureVariable(string variableName)
{
string value = Environment.GetEnvironmentVariable(variableName);
if (string.IsNullOrEmpty(value))
{
throw new BuildFailureException($"'{variableName}' environment variable was not found.");
}
return value;
}
}
}