dotnet-installer/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs

67 lines
2.1 KiB
C#
Raw Normal View History

// 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.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
2016-09-22 19:11:08 -05:00
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using System.Diagnostics;
using Microsoft.DotNet.Cli.Utils;
2016-09-22 19:11:08 -05:00
namespace Microsoft.DotNet.Tools.MSBuild
{
public class MSBuildForwardingApp
{
internal const string TelemetrySessionIdEnvironmentVariableName = "DOTNET_CLI_TELEMETRY_SESSIONID";
private MSBuildForwardingAppWithoutLogging _forwardingAppWithoutLogging;
static IEnumerable<string> ConcatTelemetryLogger(IEnumerable<string> argsToForward)
{
if (Telemetry.CurrentSessionId != null)
{
2016-11-01 09:29:19 -07:00
try
{
Type loggerType = typeof(MSBuildLogger);
return argsToForward
.Concat(new[]
{
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
});
2016-11-01 09:29:19 -07:00
}
catch (Exception)
{
// Exceptions during telemetry shouldn't cause anything else to fail
}
}
return argsToForward;
}
public MSBuildForwardingApp(IEnumerable<string> argsToForward, string msbuildPath = null)
{
_forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(
ConcatTelemetryLogger(argsToForward),
msbuildPath);
}
public ProcessStartInfo GetProcessStartInfo()
{
var ret = _forwardingAppWithoutLogging.GetProcessStartInfo();
ret.Environment[TelemetrySessionIdEnvironmentVariableName] = Telemetry.CurrentSessionId;
return ret;
}
public int Execute()
{
return GetProcessStartInfo().Execute();
}
}
}