2016-06-17 16:16:09 -07:00
|
|
|
|
// 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;
|
2016-10-29 12:08:52 -07:00
|
|
|
|
using System.Linq;
|
2016-10-31 16:16:39 -07:00
|
|
|
|
using System.Reflection;
|
2016-09-23 10:40:25 -07:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-09-22 19:11:08 -05:00
|
|
|
|
using Microsoft.DotNet.Cli;
|
2016-11-15 11:56:39 -08:00
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
2017-02-14 10:41:58 -08:00
|
|
|
|
using System.Diagnostics;
|
2017-04-18 18:48:53 -07:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-06-17 16:16:09 -07:00
|
|
|
|
|
2016-09-22 19:11:08 -05:00
|
|
|
|
namespace Microsoft.DotNet.Tools.MSBuild
|
2016-06-17 16:16:09 -07:00
|
|
|
|
{
|
|
|
|
|
public class MSBuildForwardingApp
|
|
|
|
|
{
|
2016-10-31 16:16:39 -07:00
|
|
|
|
internal const string TelemetrySessionIdEnvironmentVariableName = "DOTNET_CLI_TELEMETRY_SESSIONID";
|
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
private MSBuildForwardingAppWithoutLogging _forwardingAppWithoutLogging;
|
2016-11-23 23:54:44 -08:00
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
static IEnumerable<string> ConcatTelemetryLogger(IEnumerable<string> argsToForward)
|
2016-06-17 16:16:09 -07:00
|
|
|
|
{
|
2016-10-31 16:16:39 -07:00
|
|
|
|
if (Telemetry.CurrentSessionId != null)
|
|
|
|
|
{
|
2016-11-01 09:29:19 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Type loggerType = typeof(MSBuildLogger);
|
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
return argsToForward
|
2017-01-31 16:47:41 -08:00
|
|
|
|
.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
|
|
|
|
|
}
|
2016-10-31 16:16:39 -07:00
|
|
|
|
}
|
2017-04-18 18:48:53 -07:00
|
|
|
|
return argsToForward;
|
2016-06-17 16:16:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
public MSBuildForwardingApp(IEnumerable<string> argsToForward, string msbuildPath = null)
|
2016-06-17 16:16:09 -07:00
|
|
|
|
{
|
2017-04-18 18:48:53 -07:00
|
|
|
|
_forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(
|
|
|
|
|
ConcatTelemetryLogger(argsToForward),
|
|
|
|
|
msbuildPath);
|
2016-11-23 23:54:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
public ProcessStartInfo GetProcessStartInfo()
|
2016-11-23 23:54:44 -08:00
|
|
|
|
{
|
2017-04-18 18:48:53 -07:00
|
|
|
|
var ret = _forwardingAppWithoutLogging.GetProcessStartInfo();
|
2016-12-01 14:45:55 -08:00
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
ret.Environment[TelemetrySessionIdEnvironmentVariableName] = Telemetry.CurrentSessionId;
|
2016-12-01 14:45:55 -08:00
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
return ret;
|
2016-06-17 16:16:09 -07:00
|
|
|
|
}
|
2016-09-21 15:24:54 -07:00
|
|
|
|
|
2017-04-18 18:48:53 -07:00
|
|
|
|
public int Execute()
|
2016-09-21 15:24:54 -07:00
|
|
|
|
{
|
2017-04-18 18:48:53 -07:00
|
|
|
|
return GetProcessStartInfo().Execute();
|
2016-09-21 15:24:54 -07:00
|
|
|
|
}
|
2016-06-17 16:16:09 -07:00
|
|
|
|
}
|
|
|
|
|
}
|