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-09-23 10:40:25 -07:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-09-22 19:11:08 -05:00
|
|
|
|
using Microsoft.DotNet.Cli;
|
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-19 12:43:21 -07:00
|
|
|
|
private const string s_msbuildExeName = "MSBuild.dll";
|
2016-10-29 12:08:52 -07:00
|
|
|
|
|
2016-06-17 16:16:09 -07:00
|
|
|
|
private readonly ForwardingApp _forwardingApp;
|
|
|
|
|
|
2016-10-29 12:08:52 -07:00
|
|
|
|
private readonly Dictionary<string, string> _msbuildRequiredEnvironmentVariables =
|
|
|
|
|
new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "MSBuildExtensionsPath", AppContext.BaseDirectory },
|
|
|
|
|
{ "CscToolExe", GetRunCscPath() }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly IEnumerable<string> _msbuildRequiredParameters =
|
|
|
|
|
new List<string> { "/m" };
|
|
|
|
|
|
2016-08-10 23:45:30 -07:00
|
|
|
|
public MSBuildForwardingApp(IEnumerable<string> argsToForward)
|
2016-06-17 16:16:09 -07:00
|
|
|
|
{
|
|
|
|
|
_forwardingApp = new ForwardingApp(
|
|
|
|
|
GetMSBuildExePath(),
|
2016-10-29 12:08:52 -07:00
|
|
|
|
_msbuildRequiredParameters.Concat(argsToForward),
|
|
|
|
|
environmentVariables: _msbuildRequiredEnvironmentVariables);
|
2016-06-17 16:16:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Execute()
|
|
|
|
|
{
|
|
|
|
|
return _forwardingApp.Execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetMSBuildExePath()
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(
|
|
|
|
|
AppContext.BaseDirectory,
|
|
|
|
|
s_msbuildExeName);
|
|
|
|
|
}
|
2016-09-21 15:24:54 -07:00
|
|
|
|
|
|
|
|
|
private static string GetRunCscPath()
|
|
|
|
|
{
|
2016-09-23 10:40:25 -07:00
|
|
|
|
var scriptExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".cmd" : ".sh";
|
2016-09-21 15:24:54 -07:00
|
|
|
|
return Path.Combine(AppContext.BaseDirectory, $"RunCsc{scriptExtension}");
|
|
|
|
|
}
|
2016-06-17 16:16:09 -07:00
|
|
|
|
}
|
|
|
|
|
}
|