Add test assets
This commit is contained in:
parent
60bd88d261
commit
a3db242b9b
8 changed files with 311 additions and 0 deletions
|
@ -0,0 +1,117 @@
|
|||
// 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.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
using static System.Int32;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.DependencyInvoker
|
||||
{
|
||||
public class DotnetBaseParams
|
||||
{
|
||||
private readonly CommandLineApplication _app;
|
||||
|
||||
private CommandOption _outputOption;
|
||||
private CommandOption _buildBasePath;
|
||||
private CommandOption _frameworkOption;
|
||||
private CommandOption _runtimeOption;
|
||||
private CommandOption _configurationOption;
|
||||
private CommandOption _projectPath;
|
||||
private CommandArgument _command;
|
||||
|
||||
public string Runtime { get; set; }
|
||||
|
||||
public string Config { get; set; }
|
||||
|
||||
public string BuildBasePath { get; set; }
|
||||
|
||||
public string Output { get; set; }
|
||||
|
||||
public string ProjectPath { get; set; }
|
||||
|
||||
public NuGetFramework Framework { get; set; }
|
||||
|
||||
public string Command {get; set; }
|
||||
|
||||
public List<string> RemainingArguments { get; set; }
|
||||
|
||||
public DotnetBaseParams(string name, string fullName, string description)
|
||||
{
|
||||
_app = new CommandLineApplication(false)
|
||||
{
|
||||
Name = name,
|
||||
FullName = fullName,
|
||||
Description = description
|
||||
};
|
||||
|
||||
AddDotnetBaseParameters();
|
||||
}
|
||||
|
||||
public void Parse(string[] args)
|
||||
{
|
||||
_app.OnExecute(() =>
|
||||
{
|
||||
// Locate the project and get the name and full path
|
||||
ProjectPath = _projectPath.Value();
|
||||
Output = _outputOption.Value();
|
||||
BuildBasePath = _buildBasePath.Value();
|
||||
Config = _configurationOption.Value() ?? Constants.DefaultConfiguration;
|
||||
Runtime = _runtimeOption.Value();
|
||||
if (_frameworkOption.HasValue())
|
||||
{
|
||||
Framework = NuGetFramework.Parse(_frameworkOption.Value());
|
||||
}
|
||||
Command = _command.Value;
|
||||
RemainingArguments = _app.RemainingArguments;
|
||||
|
||||
if (string.IsNullOrEmpty(ProjectPath))
|
||||
{
|
||||
ProjectPath = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
_app.Execute(args);
|
||||
}
|
||||
|
||||
private void AddDotnetBaseParameters()
|
||||
{
|
||||
_app.HelpOption("-?|-h|--help");
|
||||
|
||||
_configurationOption = _app.Option(
|
||||
"-c|--configuration <CONFIGURATION>",
|
||||
"Configuration under which to build",
|
||||
CommandOptionType.SingleValue);
|
||||
_outputOption = _app.Option(
|
||||
"-o|--output <OUTPUT_DIR>",
|
||||
"Directory in which to find the binaries to be run",
|
||||
CommandOptionType.SingleValue);
|
||||
_buildBasePath = _app.Option(
|
||||
"-b|--build-base-path <OUTPUT_DIR>",
|
||||
"Directory in which to find temporary outputs",
|
||||
CommandOptionType.SingleValue);
|
||||
_frameworkOption = _app.Option(
|
||||
"-f|--framework <FRAMEWORK>",
|
||||
"Looks for test binaries for a specific framework",
|
||||
CommandOptionType.SingleValue);
|
||||
_runtimeOption = _app.Option(
|
||||
"-r|--runtime <RUNTIME_IDENTIFIER>",
|
||||
"Look for test binaries for a for the specified runtime",
|
||||
CommandOptionType.SingleValue);
|
||||
_projectPath = _app.Option(
|
||||
"-p|--project-path <PROJECT_JSON_PATH>",
|
||||
"Path to Project.json that contains the tool dependency",
|
||||
CommandOptionType.SingleValue);
|
||||
_command = _app.Argument(
|
||||
"<COMMAND>",
|
||||
"The command to execute.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||
<clear />
|
||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.DependencyInvoker
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var dotnetParams = new DotnetBaseParams("dotnet-dependency-tool-invoker", "DotNet Dependency Tool Invoker", "Invokes tools declared as NuGet dependencies of a project");
|
||||
|
||||
dotnetParams.Parse(args);
|
||||
|
||||
if (string.IsNullOrEmpty(dotnetParams.Command))
|
||||
{
|
||||
Console.WriteLine("A command name must be provided");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var projectContexts =
|
||||
CreateProjectContexts(dotnetParams.ProjectPath)
|
||||
.Where(p => dotnetParams.Framework == null ||
|
||||
dotnetParams.Framework.GetShortFolderName()
|
||||
.Equals(p.TargetFramework.GetShortFolderName()));
|
||||
|
||||
var commandFactory =
|
||||
new ProjectDependenciesCommandFactory(
|
||||
dotnetParams.Framework,
|
||||
dotnetParams.Config,
|
||||
dotnetParams.Output,
|
||||
dotnetParams.BuildBasePath,
|
||||
projectContexts.First().ProjectDirectory);
|
||||
|
||||
foreach (var projectContext in projectContexts)
|
||||
{
|
||||
Console.WriteLine($"Invoking '{dotnetParams.Command}' for '{projectContext.TargetFramework}'.");
|
||||
|
||||
try
|
||||
{
|
||||
var exitCode = commandFactory.Create(
|
||||
$"dotnet-{dotnetParams.Command}",
|
||||
Enumerable.Empty<string>(),
|
||||
projectContext.TargetFramework,
|
||||
dotnetParams.Config)
|
||||
.ForwardStdErr()
|
||||
.ForwardStdOut()
|
||||
.Execute()
|
||||
.ExitCode;
|
||||
|
||||
Console.WriteLine($"Command returned {exitCode}");
|
||||
}
|
||||
catch (CommandUnknownException)
|
||||
{
|
||||
Console.WriteLine($"Command not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<ProjectContext> CreateProjectContexts(string projectPath = null)
|
||||
{
|
||||
projectPath = projectPath ?? Directory.GetCurrentDirectory();
|
||||
|
||||
if (!projectPath.EndsWith(Project.FileName))
|
||||
{
|
||||
projectPath = Path.Combine(projectPath, Project.FileName);
|
||||
}
|
||||
|
||||
if (!File.Exists(projectPath))
|
||||
{
|
||||
throw new InvalidOperationException($"{projectPath} does not exist.");
|
||||
}
|
||||
|
||||
return ProjectContext.CreateContextForEachFramework(projectPath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>c26a48bb-193f-450c-ab09-4d3324c78188</ProjectGuid>
|
||||
<RootNamespace>dotnet-dependency-tool-invoker</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc2-23925"
|
||||
},
|
||||
"Microsoft.DotNet.Cli.Utils":"1.0.0-*",
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||
"Microsoft.DotNet.Compiler.Common": "1.0.0-*",
|
||||
"Microsoft.Extensions.CommandLineUtils.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-rc2-16453"
|
||||
},
|
||||
"Microsoft.Dnx.Runtime.CommandParsing.Sources": {
|
||||
"version": "1.0.0-rc2-16453",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.Dnx.Runtime.Sources": {
|
||||
"version": "1.0.0-rc2-16453",
|
||||
"type": "build"
|
||||
},
|
||||
"System.CommandLine": "0.1.0-e160323-1"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"imports": [
|
||||
"portable-net45+win8",
|
||||
"dnxcore50"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||
<clear />
|
||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#if NET451
|
||||
Console.WriteLine("Hello From .NETFramework,Version=v4.5.1");
|
||||
#elif NETSTANDARD1_5
|
||||
Console.WriteLine("Hello From .NETStandardApp,Version=v1.5");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc2-23925"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"portable-net45+win8",
|
||||
"dnxcore50"
|
||||
]
|
||||
},
|
||||
"net451": {}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue