WiP
This commit is contained in:
parent
45727ab4e3
commit
19ed5a558b
2 changed files with 59 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
// 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.Linq;
|
||||
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
@ -12,6 +13,10 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
{
|
||||
public DotNetTool()
|
||||
{
|
||||
EnvironmentVariables = new EnvironmentFilter()
|
||||
.GetEnvironmentVariableNamesToRemove()
|
||||
.Select(e => $"{e}=")
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
protected abstract string Command { get; }
|
||||
|
|
54
build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs
Normal file
54
build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
// 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class EnvironmentFilter
|
||||
{
|
||||
private const string _MSBuildEnvironmentVariablePrefix = "MSBuild";
|
||||
private const string _DotNetEnvironmentVariablePrefix = "DOTNET";
|
||||
private const string _NugetEnvironmentVariablePrefix = "NUGET";
|
||||
|
||||
private IEnumerable<string> _prefixesOfEnvironmentVariablesToRemove = new string []
|
||||
{
|
||||
_MSBuildEnvironmentVariablePrefix,
|
||||
_DotNetEnvironmentVariablePrefix,
|
||||
_NugetEnvironmentVariablePrefix
|
||||
};
|
||||
|
||||
private IEnumerable<string> _environmentVariablesToRemove = new string []
|
||||
{
|
||||
"CscToolExe"
|
||||
};
|
||||
|
||||
private IEnumerable<string> _environmentVariablesToKeep = new string []
|
||||
{
|
||||
"DOTNET_CLI_TELEMETRY_SESSIONID"
|
||||
};
|
||||
|
||||
public IEnumerable<string> GetEnvironmentVariableNamesToRemove()
|
||||
{
|
||||
var allEnvironmentVariableNames = (IEnumerable<string>)Environment
|
||||
.GetEnvironmentVariables()
|
||||
.Keys
|
||||
.Cast<string>();
|
||||
|
||||
var environmentVariablesToRemoveByPrefix = allEnvironmentVariableNames
|
||||
.Where(e => _prefixesOfEnvironmentVariablesToRemove.Any(p => e.StartsWith(p)));
|
||||
|
||||
var environmentVariablesToRemoveByName = allEnvironmentVariableNames
|
||||
.Where(e => _environmentVariablesToRemove.Contains(e));
|
||||
|
||||
var environmentVariablesToRemove = environmentVariablesToRemoveByName
|
||||
.Concat(environmentVariablesToRemoveByPrefix)
|
||||
.Distinct()
|
||||
.Except(_environmentVariablesToKeep);
|
||||
|
||||
return environmentVariablesToRemoveByName;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue