Updating the CLi.Utils version that we use in core-sdk to one with a new muxer class that has the proper AppContext handling.
This commit is contained in:
parent
4dc369957e
commit
829bc78ccf
12 changed files with 25 additions and 296 deletions
|
@ -1,30 +0,0 @@
|
|||
// 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.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.DependencyInvoker
|
||||
{
|
||||
public static class AppliedOptionExtensions
|
||||
{
|
||||
public static T ValueOrDefault<T>(this AppliedOption parseResult, string alias)
|
||||
{
|
||||
return parseResult
|
||||
.AppliedOptions
|
||||
.Where(o => o.HasAlias(alias))
|
||||
.Select(o => o.Value<T>())
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
public static string SingleArgumentOrDefault(this AppliedOption parseResult, string alias)
|
||||
{
|
||||
return parseResult
|
||||
.AppliedOptions
|
||||
.Where(o => o.HasAlias(alias))
|
||||
.Select(o => o.Arguments.Single())
|
||||
.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
// 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.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.DependencyInvoker
|
||||
{
|
||||
internal static class DotnetDependencyToolInvokerParser
|
||||
{
|
||||
public static Microsoft.DotNet.Cli.CommandLine.Command DotnetDependencyToolInvoker() =>
|
||||
Create.Command(
|
||||
"dotnet-dependency-tool-invoker",
|
||||
"DotNet Dependency Tool Invoker",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "COMMAND",
|
||||
description: "The command to execute."),
|
||||
false,
|
||||
Create.Option(
|
||||
"-h|--help",
|
||||
"Show help information",
|
||||
Accept.NoArguments()),
|
||||
Create.Option(
|
||||
"-p|--project-path",
|
||||
"Path to Project.json that contains the tool dependency",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "PROJECT_JSON_PATH",
|
||||
defaultValue: () =>
|
||||
PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()))),
|
||||
Create.Option(
|
||||
"-c|--configuration",
|
||||
"Configuration under which to build",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "CONFIGURATION",
|
||||
defaultValue: () => Constants.DefaultConfiguration)),
|
||||
Create.Option(
|
||||
"-o|--output",
|
||||
"Directory in which to find the binaries to be run",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "OUTPUT_DIR")),
|
||||
Create.Option(
|
||||
"-f|--framework",
|
||||
"Looks for test binaries for a specific framework",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "FRAMEWORK")
|
||||
.MaterializeAs(p => NuGetFramework.Parse(p.Arguments.Single()))),
|
||||
Create.Option(
|
||||
"-r|--runtime",
|
||||
"Look for test binaries for a for the specified runtime",
|
||||
Accept.ExactlyOneArgument()
|
||||
.With(name: "RUNTIME_IDENTIFIER")));
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
// 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.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.DependencyInvoker
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
args = new [] { "dotnet-dependency-tool-invoker" }.Concat(args).ToArray();
|
||||
|
||||
var parser = new Parser(
|
||||
options: DotnetDependencyToolInvokerParser.DotnetDependencyToolInvoker());
|
||||
|
||||
var parseResult = parser.Parse(args);
|
||||
var appliedOptions = parseResult["dotnet-dependency-tool-invoker"];
|
||||
|
||||
Console.WriteLine(parseResult.Diagram());
|
||||
|
||||
if (appliedOptions.HasOption("help"))
|
||||
{
|
||||
Console.WriteLine(parseResult.Command().HelpView());
|
||||
return 0;
|
||||
}
|
||||
|
||||
var command = appliedOptions.Arguments.First();
|
||||
var framework = appliedOptions.ValueOrDefault<NuGetFramework>("framework");
|
||||
var configuration = appliedOptions.ValueOrDefault<string>("configuration");
|
||||
if (string.IsNullOrEmpty(configuration))
|
||||
{
|
||||
configuration = Constants.DefaultConfiguration;
|
||||
}
|
||||
|
||||
var output = appliedOptions.SingleArgumentOrDefault("output");
|
||||
var projectPath = appliedOptions.ValueOrDefault<string>("project-path");
|
||||
if (string.IsNullOrEmpty(projectPath))
|
||||
{
|
||||
projectPath = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
var appArguments = parseResult.UnmatchedTokens;
|
||||
|
||||
var commandFactory =
|
||||
new ProjectDependenciesCommandFactory(
|
||||
framework,
|
||||
configuration,
|
||||
output,
|
||||
string.Empty,
|
||||
projectPath);
|
||||
|
||||
var result =
|
||||
InvokeDependencyToolForMSBuild(commandFactory, command, framework, configuration, appArguments);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int InvokeDependencyToolForMSBuild(
|
||||
ProjectDependenciesCommandFactory commandFactory,
|
||||
string command,
|
||||
NuGetFramework framework,
|
||||
string configuration,
|
||||
IEnumerable<string> appArguments)
|
||||
{
|
||||
Console.WriteLine($"Invoking '{command}' for '{framework.GetShortFolderName()}'.");
|
||||
|
||||
return InvokeDependencyTool(commandFactory, command, framework, configuration, appArguments);
|
||||
}
|
||||
|
||||
private static int InvokeDependencyTool(
|
||||
ProjectDependenciesCommandFactory commandFactory,
|
||||
string command,
|
||||
NuGetFramework framework,
|
||||
string configuration,
|
||||
IEnumerable<string> appArguments)
|
||||
{
|
||||
try
|
||||
{
|
||||
var exitCode = commandFactory.Create(
|
||||
$"dotnet-{command}",
|
||||
appArguments,
|
||||
framework,
|
||||
configuration)
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.Execute()
|
||||
.ExitCode;
|
||||
|
||||
Console.WriteLine($"Command returned {exitCode}");
|
||||
}
|
||||
catch (CommandUnknownException)
|
||||
{
|
||||
Console.WriteLine($"Command not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<Project>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
|
||||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.0.0-rc</VersionPrefix>
|
||||
<TargetFramework>$(CliTargetFramework)</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<VersionSuffix></VersionSuffix>
|
||||
<RuntimeFrameworkVersion>$(MicrosoftNETCoreAppPackageVersion)</RuntimeFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NuGet.Frameworks" Version="$(NuGetFrameworksPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.DotNet.Cli.Utils" Version="$(MicrosoftDotNetCliUtilsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="$(MicrosoftDotNetCliCommandLinePackageVersion)" />
|
||||
<PackageReference Include="System.Linq" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
|
||||
</Project>
|
|
@ -1,15 +0,0 @@
|
|||
// 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;
|
||||
|
||||
namespace MSBuildTestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>$(CliTargetFramework)</TargetFramework>
|
||||
<RestoreAdditionalProjectSources Condition="'$(TEST_PACKAGES)' != ''">$(TEST_PACKAGES)</RestoreAdditionalProjectSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dotnet-portable" Version="1.0.0" >
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="dotnet-dependency-tool-invoker" Version="1.0.0-*" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,7 +1,7 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<NuGetFrameworksPackageVersion>4.8.0-rtm.5348</NuGetFrameworksPackageVersion>
|
||||
<MicrosoftDotNetCliUtilsPackageVersion>3.0.100-alpha1-20180711-1</MicrosoftDotNetCliUtilsPackageVersion>
|
||||
<NuGetFrameworksPackageVersion>5.0.0-preview1.5663</NuGetFrameworksPackageVersion>
|
||||
<MicrosoftDotNetCliUtilsPackageVersion>3.0.100-preview.18580.6</MicrosoftDotNetCliUtilsPackageVersion>
|
||||
<MicrosoftDotNetCliCommandLinePackageVersion>0.1.1</MicrosoftDotNetCliCommandLinePackageVersion>
|
||||
<MicrosoftNETTestSdkPackageVersion>15.8.0</MicrosoftNETTestSdkPackageVersion>
|
||||
<MicrosoftDotNetPlatformAbstractionsPackageVersion>3.0.0-preview-27205-02</MicrosoftDotNetPlatformAbstractionsPackageVersion>
|
||||
|
|
|
@ -20,16 +20,6 @@
|
|||
|
||||
<Target Name="SetupTestPackageProjectBaseData">
|
||||
<ItemGroup>
|
||||
<BaseTestPackageProject Include="TestAssets/TestPackages/dotnet-dependency-tool-invoker">
|
||||
<Name>dotnet-dependency-tool-invoker</Name>
|
||||
<ProjectName>dotnet-dependency-tool-invoker.csproj</ProjectName>
|
||||
<IsTool>True</IsTool>
|
||||
<IsApplicable>True</IsApplicable>
|
||||
<VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
|
||||
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
|
||||
<ReleaseSuffix>$(ReleaseSuffix)</ReleaseSuffix>
|
||||
<Clean>True</Clean>
|
||||
</BaseTestPackageProject>
|
||||
<BaseTestPackageProject Include="TestAssets/TestPackages/dotnet-portable">
|
||||
<Name>dotnet-portable</Name>
|
||||
<ProjectName>dotnet-portable.csproj</ProjectName>
|
||||
|
|
|
@ -95,33 +95,5 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("Hello I prefer the cli runtime World!");;
|
||||
}
|
||||
|
||||
[Fact(Skip="https://github.com/dotnet/cli/issues/9688")]
|
||||
public void ItCanRunAToolThatInvokesADependencyToolInACSProj()
|
||||
{
|
||||
var repoDirectoriesProvider = new RepoDirectoriesProvider();
|
||||
|
||||
var testInstance = TestAssets.Get("TestAppWithProjDepTool")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.WithRestoreFiles();
|
||||
|
||||
var configuration = "Debug";
|
||||
|
||||
var testProjectDirectory = testInstance.Root;
|
||||
|
||||
new BuildCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute($"-c {configuration} ")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
new DotnetCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.ExecuteWithCapturedOutput(
|
||||
$"-d dependency-tool-invoker -c {configuration} -f netcoreapp3.0 portable")
|
||||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("Hello Portable World!");;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<Description>Microsoft.DotNet.TestFramework Class Library</Description>
|
||||
<VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -251,7 +252,7 @@ namespace Microsoft.DotNet.TestFramework
|
|||
|
||||
Console.WriteLine($"TestAsset Build '{TestAssetInfo.AssetName}'");
|
||||
|
||||
var commandResult = Command.Create(TestAssetInfo.DotnetExeFile.FullName, args)
|
||||
var commandResult = CreateCommand(TestAssetInfo.DotnetExeFile.FullName, args)
|
||||
.WorkingDirectory(Root.FullName)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
|
@ -280,7 +281,7 @@ namespace Microsoft.DotNet.TestFramework
|
|||
{
|
||||
var restoreArgs = new string[] { "restore", projectFile.FullName };
|
||||
|
||||
var commandResult = Command.Create(TestAssetInfo.DotnetExeFile.FullName, restoreArgs)
|
||||
var commandResult = CreateCommand(TestAssetInfo.DotnetExeFile.FullName, restoreArgs)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
|
@ -308,5 +309,23 @@ namespace Microsoft.DotNet.TestFramework
|
|||
Restore(projFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static Command CreateCommand(string path, IEnumerable<string> args)
|
||||
{
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = path,
|
||||
Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args),
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
|
||||
var _process = new Process
|
||||
{
|
||||
StartInfo = psi
|
||||
};
|
||||
|
||||
return new Command(_process);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft.DotNet.Tools.Tests.Utilities Class Library</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AssemblyName>Microsoft.DotNet.Tools.Tests.Utilities</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
|
|
Loading…
Reference in a new issue