From 94e74d846a7e30772957b43dbab9091ebe6a8da0 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Wed, 25 Jan 2017 17:14:07 -0800 Subject: [PATCH] WiP --- build_projects/dotnet-cli-build/DotNetTool.cs | 45 ++++++++++++++----- .../EnvironmentVariableFilter.cs | 25 ++++++++++- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/build_projects/dotnet-cli-build/DotNetTool.cs b/build_projects/dotnet-cli-build/DotNetTool.cs index 7a12d0355..d433c526a 100644 --- a/build_projects/dotnet-cli-build/DotNetTool.cs +++ b/build_projects/dotnet-cli-build/DotNetTool.cs @@ -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 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(); } diff --git a/build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs b/build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs index 54f5272f7..183ad58d6 100644 --- a/build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs +++ b/build_projects/dotnet-cli-build/EnvironmentVariableFilter.cs @@ -27,7 +27,8 @@ namespace Microsoft.DotNet.Cli.Build private IEnumerable _environmentVariablesToKeep = new string [] { - "DOTNET_CLI_TELEMETRY_SESSIONID" + "DOTNET_CLI_TELEMETRY_SESSIONID", + "NUGET_PACKAGES" }; public IEnumerable GetEnvironmentVariableNamesToRemove() @@ -36,19 +37,39 @@ namespace Microsoft.DotNet.Cli.Build .GetEnvironmentVariables() .Keys .Cast(); + + 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; } } }