Merge branch 'feature/msbuild' of https://github.com/dotnet/cli.git
This commit is contained in:
commit
cec5bacaad
17 changed files with 493 additions and 24 deletions
107
src/dotnet/commands/dotnet-build3/ForwardingApp.cs
Normal file
107
src/dotnet/commands/dotnet-build3/ForwardingApp.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
// 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 Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
/// <summary>
|
||||
/// A class which encapsulates logic needed to forward arguments from the current process to another process
|
||||
/// invoked with the dotnet.exe host.
|
||||
/// </summary>
|
||||
public class ForwardingApp
|
||||
{
|
||||
private const string s_hostExe = "dotnet";
|
||||
|
||||
private readonly string _forwardApplicationPath;
|
||||
private readonly string[] _argsToForward;
|
||||
private readonly string _depsFile;
|
||||
private readonly string _runtimeConfig;
|
||||
private readonly string _additionalProbingPath;
|
||||
private readonly Dictionary<string, string> _environmentVariables;
|
||||
|
||||
private readonly string[] _allArgs;
|
||||
|
||||
public ForwardingApp(
|
||||
string forwardApplicationPath,
|
||||
string[] argsToForward,
|
||||
string depsFile = null,
|
||||
string runtimeConfig = null,
|
||||
string additionalProbingPath = null,
|
||||
Dictionary<string, string> environmentVariables = null)
|
||||
{
|
||||
_forwardApplicationPath = forwardApplicationPath;
|
||||
_argsToForward = argsToForward;
|
||||
_depsFile = depsFile;
|
||||
_runtimeConfig = runtimeConfig;
|
||||
_additionalProbingPath = additionalProbingPath;
|
||||
_environmentVariables = environmentVariables;
|
||||
|
||||
var allArgs = new List<string>();
|
||||
allArgs.Add("exec");
|
||||
|
||||
if (_depsFile != null)
|
||||
{
|
||||
allArgs.Add("--depsfile");
|
||||
allArgs.Add(_depsFile);
|
||||
}
|
||||
|
||||
if (_runtimeConfig != null)
|
||||
{
|
||||
allArgs.Add("--runtimeconfig");
|
||||
allArgs.Add(_runtimeConfig);
|
||||
}
|
||||
|
||||
if (_additionalProbingPath != null)
|
||||
{
|
||||
allArgs.Add("--additionalprobingpath");
|
||||
allArgs.Add(_additionalProbingPath);
|
||||
}
|
||||
|
||||
allArgs.Add(_forwardApplicationPath);
|
||||
allArgs.AddRange(_argsToForward);
|
||||
|
||||
_allArgs = allArgs.ToArray();
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
{
|
||||
var processInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = GetHostExeName(),
|
||||
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_allArgs),
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
if (_environmentVariables != null)
|
||||
{
|
||||
foreach (var entry in _environmentVariables)
|
||||
{
|
||||
processInfo.Environment[entry.Key] = entry.Value;
|
||||
}
|
||||
}
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = processInfo
|
||||
};
|
||||
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
private string GetHostExeName()
|
||||
{
|
||||
return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}";
|
||||
}
|
||||
}
|
||||
}
|
80
src/dotnet/commands/dotnet-build3/MSBuildForwardingApp.cs
Normal file
80
src/dotnet/commands/dotnet-build3/MSBuildForwardingApp.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
// 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 Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
public class MSBuildForwardingApp
|
||||
{
|
||||
private const string s_msbuildExeName = "MSBuild.exe";
|
||||
private readonly ForwardingApp _forwardingApp;
|
||||
|
||||
public MSBuildForwardingApp(string[] argsToForward)
|
||||
{
|
||||
_forwardingApp = new ForwardingApp(
|
||||
GetMSBuildExePath(),
|
||||
argsToForward,
|
||||
depsFile: GetDepsFile(),
|
||||
runtimeConfig: GetRuntimeConfig(),
|
||||
environmentVariables: GetEnvironmentVariables());
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
{
|
||||
return _forwardingApp.Execute();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> GetEnvironmentVariables()
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ "MSBuildExtensionsPath", AppContext.BaseDirectory },
|
||||
{ "DotnetHostPath", GetHostPath() },
|
||||
{ "BaseNuGetRuntimeIdentifier", GetCurrentBaseRid() },
|
||||
{ "Platform", GetCurrentArchitecture() },
|
||||
{ "PlatformTarget", GetCurrentArchitecture() }
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetCurrentBaseRid()
|
||||
{
|
||||
return RuntimeEnvironment.GetRuntimeIdentifier()
|
||||
.Replace("-" + RuntimeEnvironment.RuntimeArchitecture, "");
|
||||
}
|
||||
|
||||
private static string GetHostPath()
|
||||
{
|
||||
return new Muxer().MuxerPath;
|
||||
}
|
||||
|
||||
private static string GetRuntimeConfig()
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "dotnet.runtimeconfig.json");
|
||||
}
|
||||
|
||||
private static string GetDepsFile()
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "dotnet.deps.json");
|
||||
}
|
||||
|
||||
private static string GetMSBuildExePath()
|
||||
{
|
||||
return Path.Combine(
|
||||
AppContext.BaseDirectory,
|
||||
"runtimes", "any", "native",
|
||||
s_msbuildExeName);
|
||||
}
|
||||
|
||||
private static string GetCurrentArchitecture()
|
||||
{
|
||||
return RuntimeEnvironment.RuntimeArchitecture;
|
||||
}
|
||||
}
|
||||
}
|
20
src/dotnet/commands/dotnet-build3/Program.cs
Normal file
20
src/dotnet/commands/dotnet-build3/Program.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// 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 Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
public class Build3Command
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
return new MSBuildForwardingApp(args).Execute();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
// 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 Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -19,6 +19,7 @@ using NuGet.Frameworks;
|
|||
using NuGet.Packaging.Core;
|
||||
using NuGet.Versioning;
|
||||
using PackageBuilder = NuGet.PackageBuilder;
|
||||
using NuGetConstants = NuGet.Constants;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler
|
||||
{
|
||||
|
@ -58,7 +59,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
var packageOutputPath = Path.Combine(
|
||||
ArtifactPathsCalculator.PackageOutputPath,
|
||||
GetPackageName() + NuGet.Constants.PackageExtension);
|
||||
GetPackageName() + NuGetConstants.PackageExtension);
|
||||
|
||||
if (GeneratePackage(packageOutputPath, packDiagnostics))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue