Merge pull request #341 from piotrpMSFT/piotrpMSFT/issue226/NuGetCommands
Enable commands to be shipped in packages
This commit is contained in:
commit
11b43a37d6
10 changed files with 127 additions and 27 deletions
|
@ -8,6 +8,9 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
@ -43,19 +46,26 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
};
|
||||
}
|
||||
|
||||
public static Command Create(string executable, IEnumerable<string> args)
|
||||
public static Command Create(string executable, IEnumerable<string> args, NuGetFramework framework = null)
|
||||
{
|
||||
return Create(executable, string.Join(" ", args));
|
||||
return Create(executable, string.Join(" ", args), framework);
|
||||
}
|
||||
|
||||
public static Command Create(string executable, string args)
|
||||
public static Command Create(string executable, string args, NuGetFramework framework = null)
|
||||
{
|
||||
ResolveExecutablePath(ref executable, ref args);
|
||||
ResolveExecutablePath(ref executable, ref args, framework);
|
||||
|
||||
return new Command(executable, args);
|
||||
}
|
||||
|
||||
private static void ResolveExecutablePath(ref string executable, ref string args)
|
||||
private static void ResolveExecutablePath(ref string executable, ref string args, NuGetFramework framework = null)
|
||||
{
|
||||
executable =
|
||||
ResolveExecutablePathFromProject(executable, framework) ??
|
||||
ResolveExecutableFromPath(executable, ref args);
|
||||
}
|
||||
|
||||
private static string ResolveExecutableFromPath(string executable, ref string args)
|
||||
{
|
||||
foreach (string suffix in Constants.RunnableSuffixes)
|
||||
{
|
||||
|
@ -88,6 +98,43 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
args = $"/C \"{executable}\"";
|
||||
executable = comSpec;
|
||||
}
|
||||
|
||||
return executable;
|
||||
}
|
||||
|
||||
private static string ResolveExecutablePathFromProject(string executable, NuGetFramework framework)
|
||||
{
|
||||
if (framework == null) return null;
|
||||
|
||||
var projectRootPath = Directory.GetCurrentDirectory();
|
||||
|
||||
if (!File.Exists(Path.Combine(projectRootPath, Project.FileName))) return null;
|
||||
|
||||
var commandName = Path.GetFileNameWithoutExtension(executable);
|
||||
|
||||
var projectContext = ProjectContext.Create(projectRootPath, framework);
|
||||
|
||||
var commandPackage = projectContext.LibraryManager.GetLibraries()
|
||||
.Where(l => l.GetType() == typeof (PackageDescription))
|
||||
.Select(l => l as PackageDescription)
|
||||
.FirstOrDefault(p =>
|
||||
{
|
||||
var fileNames = p.Library.Files
|
||||
.Select(Path.GetFileName)
|
||||
.Where(n => Path.GetFileNameWithoutExtension(n) == commandName)
|
||||
.ToList();
|
||||
|
||||
return fileNames.Contains(commandName + FileNameSuffixes.DotNet.Exe) &&
|
||||
fileNames.Contains(commandName + FileNameSuffixes.DotNet.DynamicLib) &&
|
||||
fileNames.Contains(commandName + FileNameSuffixes.DotNet.Deps);
|
||||
});
|
||||
|
||||
if (commandPackage == null) return null;
|
||||
|
||||
var commandPath = commandPackage.Library.Files
|
||||
.First(f => Path.GetFileName(f) == commandName + FileNameSuffixes.DotNet.Exe);
|
||||
|
||||
return Path.Combine(projectContext.PackagesDirectory, commandPackage.Path, commandPath);
|
||||
}
|
||||
|
||||
private static bool ShouldUseCmd(string executable)
|
||||
|
|
|
@ -28,6 +28,9 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
public static readonly string DynamicLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" :
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so";
|
||||
|
||||
public static readonly string RuntimeIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win7-x64" :
|
||||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx.10.10-x64" : "ubuntu.14.04-x64";
|
||||
|
||||
public static readonly string StaticLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".lib" : ".a" ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
// 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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Common
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
"shared": "**/*.cs",
|
||||
|
||||
"dependencies": {
|
||||
"System.AppContext": "4.0.0",
|
||||
"System.Console": "4.0.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
"System.Threading": "4.0.11-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-beta-23504",
|
||||
|
||||
"Microsoft.DotNet.ProjectModel": { "target": "project" }
|
||||
"System.AppContext": "4.0.0",
|
||||
"System.Console": "4.0.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
"System.Threading": "4.0.11-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-beta-23504",
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
|
|
|
@ -3,12 +3,9 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
|
@ -31,6 +28,8 @@ Common Commands:
|
|||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
// CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.
|
||||
var verbose = false;
|
||||
var success = true;
|
||||
|
@ -71,7 +70,7 @@ Common Commands:
|
|||
return RunHelpCommand(appArgs);
|
||||
}
|
||||
|
||||
return Command.Create("dotnet-" + command, appArgs)
|
||||
return Command.Create("dotnet-" + command, appArgs, new NuGetFramework("DNXCore", Version.Parse("5.0")))
|
||||
.EnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString())
|
||||
.EnvironmentVariable(CommandContext.Variables.AnsiPassThru, bool.TrueString)
|
||||
.ForwardStdErr()
|
||||
|
|
9
src/Microsoft.DotNet.ProjectModel/DirectoryNames.cs
Normal file
9
src/Microsoft.DotNet.ProjectModel/DirectoryNames.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
public static class DirectoryNames
|
||||
{
|
||||
public const string Bin = "bin";
|
||||
|
||||
public const string Obj = "obj";
|
||||
}
|
||||
}
|
47
src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs
Normal file
47
src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
public static class FileNameSuffixes
|
||||
{
|
||||
public static PlatformFileNameSuffixes DotNet { get; } = new PlatformFileNameSuffixes
|
||||
{
|
||||
DynamicLib = ".dll",
|
||||
Exe = ".exe",
|
||||
ProgramDatabase = ".pdb",
|
||||
StaticLib = ".lib",
|
||||
Deps = ".deps",
|
||||
};
|
||||
|
||||
public static PlatformFileNameSuffixes Windows { get; } = new PlatformFileNameSuffixes
|
||||
{
|
||||
DynamicLib = ".dll",
|
||||
Exe = ".exe",
|
||||
ProgramDatabase = ".pdb",
|
||||
StaticLib = ".lib",
|
||||
Deps = ".deps",
|
||||
};
|
||||
|
||||
public static PlatformFileNameSuffixes OSX { get; } = new PlatformFileNameSuffixes
|
||||
{
|
||||
DynamicLib = ".dylib",
|
||||
Exe = "",
|
||||
ProgramDatabase = ".pdb",
|
||||
StaticLib = ".a",
|
||||
Deps = ".deps"
|
||||
};
|
||||
|
||||
public struct PlatformFileNameSuffixes
|
||||
{
|
||||
public string DynamicLib { get; set; }
|
||||
|
||||
public string Exe { get; set; }
|
||||
|
||||
public string ProgramDatabase { get; set; }
|
||||
|
||||
public string StaticLib { get; set; }
|
||||
|
||||
public string Deps { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,17 +4,15 @@
|
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>303677d5-7312-4c3f-baee-beb1a9bd9fe6</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Extensions.ProjectModel</RootNamespace>
|
||||
<RootNamespace>Microsoft.DotNet.ProjectModel</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>
|
||||
</Project>
|
|
@ -2,17 +2,16 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Microsoft.Extensions.ProjectModel")]
|
||||
[assembly: AssemblyTitle("Microsoft.DotNet.ProjectModel")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.Extensions.ProjectModel")]
|
||||
[assembly: AssemblyProduct("Microsoft.DotNet.ProjectModel")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
|
Loading…
Add table
Reference in a new issue