This commit is contained in:
Piotr Puszkiewicz 2017-01-25 17:14:07 -08:00
parent c25abfb7c7
commit 94e74d846a
2 changed files with 56 additions and 14 deletions

View file

@ -1,6 +1,7 @@
// 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;
using Microsoft.Build.Framework;
@ -14,26 +15,38 @@ namespace Microsoft.DotNet.Cli.Build
{
public DotNetTool()
{
Log.LogMessage(MessageImportance.High, "STARTING ");
EnvironmentVariables = new EnvironmentFilter()
.GetEnvironmentVariableNamesToRemove()
.Select(e => $"{e}=")
.ToArray();
Log.LogMessage(MessageImportance.High, "OVERRIDING ");
// var ev2r = new EnvironmentFilter()
// .GetEnvironmentVariableNamesToRemove();
foreach (var ev in EnvironmentVariables)
{
Log.LogMessage(MessageImportance.High, $"{ev}");
}
// foreach (var ev in ev2r)
// {
// Console.WriteLine($"EV {ev}");
// }
throw new Exception($"{EnvironmentVariables.Count()}");
// EnvironmentVariables = ev2r
// .Select(e => $"{e}=")
// .ToArray();
// foreach (var ev in EnvironmentVariables)
// {
// Console.WriteLine($"EV {ev}");
// }
}
protected abstract string Command { get; }
protected abstract string Args { get; }
protected override Dictionary<string, string> EnvironmentOverride
{
get
{
return new EnvironmentFilter()
.GetEnvironmentVariableNamesToRemove()
.ToDictionary(e => e, e => (string)null);
}
}
public string WorkingDirectory { get; set; }
protected override string ToolName
@ -63,6 +76,14 @@ Log.LogMessage(MessageImportance.High, "OVERRIDING ");
protected override string GetWorkingDirectory()
{
Log.LogMessage(MessageImportance.High, "OVERRIDING ");
foreach (var ev in EnvironmentVariables)
{
Log.LogMessage(MessageImportance.High, $"{ev}");
}
return WorkingDirectory ?? base.GetWorkingDirectory();
}

View file

@ -27,7 +27,8 @@ namespace Microsoft.DotNet.Cli.Build
private IEnumerable<string> _environmentVariablesToKeep = new string []
{
"DOTNET_CLI_TELEMETRY_SESSIONID"
"DOTNET_CLI_TELEMETRY_SESSIONID",
"NUGET_PACKAGES"
};
public IEnumerable<string> GetEnvironmentVariableNamesToRemove()
@ -36,19 +37,39 @@ namespace Microsoft.DotNet.Cli.Build
.GetEnvironmentVariables()
.Keys
.Cast<string>();
foreach (var envVar in allEnvironmentVariableNames)
{
Console.WriteLine($"ev: {envVar}");
}
var environmentVariablesToRemoveByPrefix = allEnvironmentVariableNames
.Where(e => _prefixesOfEnvironmentVariablesToRemove.Any(p => e.StartsWith(p)));
foreach (var envVar in environmentVariablesToRemoveByPrefix)
{
Console.WriteLine($"evp: {envVar}");
}
var environmentVariablesToRemoveByName = allEnvironmentVariableNames
.Where(e => _environmentVariablesToRemove.Contains(e));
foreach (var envVar in environmentVariablesToRemoveByName)
{
Console.WriteLine($"evn: {envVar}");
}
var environmentVariablesToRemove = environmentVariablesToRemoveByName
.Concat(environmentVariablesToRemoveByPrefix)
.Distinct()
.Except(_environmentVariablesToKeep);
foreach (var envVar in environmentVariablesToRemove)
{
Console.WriteLine($"evr: {envVar}");
}
return environmentVariablesToRemoveByName;
return environmentVariablesToRemove;
}
}
}