merge master

This commit is contained in:
jonsequitur 2017-03-19 17:09:05 -07:00
parent 3ce1b9f0b7
commit c85492bd48
21 changed files with 412 additions and 93 deletions

View file

@ -6,4 +6,4 @@ See [Contributing](https://github.com/dotnet/corefx/blob/master/Documentation/pr
Developers Developers
========== ==========
See the [Developer Guide](Documentation/developer-guide.md) for details about developing in this repo. See the [Developer Guide](Documentation/project-docs/developer-guide.md) for details about developing in this repo.

View file

@ -3,8 +3,8 @@ Documents Index
## Overview and general information ## Overview and general information
- [Intro to .NET Core CLI](intro-to-cli.md) - [Intro to .NET Core CLI](general/intro-to-cli.md)
- [CLI UX Guidelines](cli-ux-guidelines.md) - [CLI UX Guidelines](general/cli-ux-guidelines.md)
- [.NET Core native pre-requisities document](https://github.com/dotnet/core/blob/master/Documentation/prereqs.md) - [.NET Core native pre-requisities document](https://github.com/dotnet/core/blob/master/Documentation/prereqs.md)
- [Roadmap and OS support](https://github.com/dotnet/core/blob/master/roadmap.md) - [Roadmap and OS support](https://github.com/dotnet/core/blob/master/roadmap.md)
- [Comprehensive CLI documentation](https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/) - [Comprehensive CLI documentation](https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/)
@ -12,7 +12,7 @@ Documents Index
## Working with the CLI repo ## Working with the CLI repo
- [Developer Guide](project-docs/developer-guide.md) - [Developer Guide](project-docs/developer-guide.md)
- [How to file issues](project-docs/issue-filing.guide.md) - [How to file issues](project-docs/issue-filing-guide.md)
## Troubleshooting and issues reporting ## Troubleshooting and issues reporting

View file

@ -10,5 +10,6 @@
<add key="xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" /> <add key="xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="AspNetCurrent" value="https://dotnet.myget.org/F/aspnet-feb2017-patch/api/v3/index.json" /> <add key="AspNetCurrent" value="https://dotnet.myget.org/F/aspnet-feb2017-patch/api/v3/index.json" />
<add key="vstest" value="https://dotnet.myget.org/F/vstest/api/v3/index.json" />
</packageSources> </packageSources>
</configuration> </configuration>

View file

@ -3,5 +3,5 @@
REM Copyright (c) .NET Foundation and contributors. All rights reserved. REM Copyright (c) .NET Foundation and contributors. All rights reserved.
REM Licensed under the MIT license. See LICENSE file in the project root for full license information. REM Licensed under the MIT license. See LICENSE file in the project root for full license information.
powershell -NoProfile -NoLogo -Command "& \"%~dp0run-build.ps1\" %*; exit $LastExitCode;" powershell -ExecutionPolicy Bypass -NoProfile -NoLogo -Command "& \"%~dp0run-build.ps1\" %*; exit $LastExitCode;"
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<CLI_SharedFrameworkVersion>2.0.0-beta-001728-00</CLI_SharedFrameworkVersion> <CLI_SharedFrameworkVersion>2.0.0-beta-001791-00</CLI_SharedFrameworkVersion>
<CLI_MSBuild_Version>15.2.0-preview-000047-02</CLI_MSBuild_Version> <CLI_MSBuild_Version>15.2.0-preview-000047-02</CLI_MSBuild_Version>
<CLI_Roslyn_Version>2.0.0-rc4-61325-08</CLI_Roslyn_Version> <CLI_Roslyn_Version>2.0.0-rc4-61325-08</CLI_Roslyn_Version>
<CLI_NETSDK_Version>1.1.0-alpha-20170306-2</CLI_NETSDK_Version> <CLI_NETSDK_Version>1.1.0-alpha-20170306-2</CLI_NETSDK_Version>
<CLI_NuGet_Version>4.3.0-beta1-2342</CLI_NuGet_Version> <CLI_NuGet_Version>4.3.0-beta1-2342</CLI_NuGet_Version>
<CLI_WEBSDK_Version>1.0.0-alpha-20170130-3-281</CLI_WEBSDK_Version> <CLI_WEBSDK_Version>1.0.0-alpha-20170130-3-281</CLI_WEBSDK_Version>
<CLI_TestPlatform_Version>15.0.0</CLI_TestPlatform_Version> <CLI_TestPlatform_Version>15.1.0-preview-20170316-05</CLI_TestPlatform_Version>
<SharedFrameworkVersion>$(CLI_SharedFrameworkVersion)</SharedFrameworkVersion> <SharedFrameworkVersion>$(CLI_SharedFrameworkVersion)</SharedFrameworkVersion>
<SharedHostVersion>$(CLI_SharedFrameworkVersion)</SharedHostVersion> <SharedHostVersion>$(CLI_SharedFrameworkVersion)</SharedHostVersion>
<HostFxrVersion>$(CLI_SharedFrameworkVersion)</HostFxrVersion> <HostFxrVersion>$(CLI_SharedFrameworkVersion)</HostFxrVersion>

View file

@ -29,7 +29,9 @@ if($Help)
$env:CONFIGURATION = $Configuration; $env:CONFIGURATION = $Configuration;
$RepoRoot = "$PSScriptRoot" $RepoRoot = "$PSScriptRoot"
if(!$env:NUGET_PACKAGES){
$env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" $env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages"
}
if($NoPackage) if($NoPackage)
{ {
@ -71,6 +73,10 @@ $env:VSTEST_TRACE_BUILD=1
# set the base tools directory # set the base tools directory
$toolsLocalPath = Join-Path $PSScriptRoot "build_tools" $toolsLocalPath = Join-Path $PSScriptRoot "build_tools"
if($env:BOOTSTRAP_INSTALL_DIR)
{
$toolsLocalPath = $env:BOOTSTRAP_INSTALL_DIR
}
$bootStrapperPath = Join-Path $toolsLocalPath "bootstrap.ps1" $bootStrapperPath = Join-Path $toolsLocalPath "bootstrap.ps1"
# if the boot-strapper script doesn't exist then download it # if the boot-strapper script doesn't exist then download it
if ((Test-Path $bootStrapperPath) -eq 0) if ((Test-Path $bootStrapperPath) -eq 0)

View file

@ -59,7 +59,7 @@ LINUX_PORTABLE_INSTALL_ARGS=
CUSTOM_BUILD_ARGS= CUSTOM_BUILD_ARGS=
# Set nuget package cache under the repo # Set nuget package cache under the repo
export NUGET_PACKAGES="$REPOROOT/.nuget/packages" [ -z $NUGET_PACKAGES ] && export NUGET_PACKAGES="$REPOROOT/.nuget/packages"
args=( "$@" ) args=( "$@" )
@ -147,6 +147,9 @@ export VSTEST_TRACE_BUILD=1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
toolsLocalPath="$REPOROOT/build_tools" toolsLocalPath="$REPOROOT/build_tools"
if [ ! -z $BOOTSTRAP_INSTALL_DIR]; then
toolsLocalPath = $BOOTSTRAP_INSTALL_DIR
fi
bootStrapperPath="$toolsLocalPath/bootstrap.sh" bootStrapperPath="$toolsLocalPath/bootstrap.sh"
dotnetInstallPath="$toolsLocalPath/dotnet-install.sh" dotnetInstallPath="$toolsLocalPath/dotnet-install.sh"
if [ ! -f $bootStrapperPath ]; then if [ ! -f $bootStrapperPath ]; then

View file

@ -56,21 +56,11 @@ say_verbose() {
fi fi
} }
get_current_os_name() { get_os_download_name_from_platform() {
eval $invocation eval $invocation
local uname=$(uname) platform="$1"
if [ "$linux_portable" = true ]; then case "$platform" in
echo "linux"
return 0
elif [ "$uname" = "Darwin" ]; then
echo "osx"
return 0
else
if [ -e /etc/os-release ]; then
. /etc/os-release
case "$ID.$VERSION_ID" in
"centos.7") "centos.7")
echo "centos" echo "centos"
return 0 return 0
@ -116,6 +106,30 @@ get_current_os_name() {
return 0 return 0
;; ;;
esac esac
return 1
}
get_current_os_name() {
eval $invocation
local uname=$(uname)
if [ "$linux_portable" = true ]; then
echo "linux"
return 0
elif [ "$uname" = "Darwin" ]; then
echo "osx"
return 0
elif [ -n "$runtime_id" ]; then
echo $(get_os_download_name_from_platform "${runtime_id%-*}" || echo "${runtime_id%-*}")
return 0
else
if [ -e /etc/os-release ]; then
. /etc/os-release
os=$(get_os_download_name_from_platform "$ID.$VERSION_ID" || echo "")
if [ -n "$os" ]; then
echo "$os"
return 0
fi
fi fi
fi fi
@ -400,7 +414,7 @@ construct_download_link() {
return 0 return 0
} }
get_user_share_path() { get_user_install_path() {
eval $invocation eval $invocation
if [ ! -z "${DOTNET_INSTALL_DIR:-}" ]; then if [ ! -z "${DOTNET_INSTALL_DIR:-}" ]; then
@ -418,9 +432,9 @@ resolve_installation_path() {
local install_dir=$1 local install_dir=$1
if [ "$install_dir" = "<auto>" ]; then if [ "$install_dir" = "<auto>" ]; then
local user_share_path=$(get_user_share_path) local user_install_path=$(get_user_install_path)
say_verbose "resolve_installation_path: share_path=$user_share_path" say_verbose "resolve_installation_path: user_install_path=$user_install_path"
echo "$user_share_path" echo "$user_install_path"
return 0 return 0
fi fi
@ -588,6 +602,7 @@ uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet"
verbose=false verbose=false
shared_runtime=false shared_runtime=false
linux_portable=false linux_portable=false
runtime_id=""
while [ $# -ne 0 ] while [ $# -ne 0 ]
do do
@ -631,6 +646,10 @@ do
--linux-portable|-[Ll]inux[Pp]ortable) --linux-portable|-[Ll]inux[Pp]ortable)
linux_portable=true linux_portable=true
;; ;;
--runtime-id|-[Rr]untime[Ii]d)
shift
runtime_id="$1"
;;
-?|--?|-h|--help|-[Hh]elp) -?|--?|-h|--help|-[Hh]elp)
script_name="$(basename $0)" script_name="$(basename $0)"
echo ".NET Tools Installer" echo ".NET Tools Installer"
@ -657,13 +676,15 @@ do
echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed" echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed"
echo " --linux-portable Installs the Linux portable .NET Tools instead of a distro-specific version." echo " --linux-portable Installs the Linux portable .NET Tools instead of a distro-specific version."
echo " -LinuxPortable" echo " -LinuxPortable"
echo " --runtime-id Installs the .NET Tools for the given platform (such as linux-x64)."
echo " -RuntimeId"
echo " -?,--?,-h,--help,-Help Shows this help message" echo " -?,--?,-h,--help,-Help Shows this help message"
echo "" echo ""
echo "Install Location:" echo "Install Location:"
echo " Location is chosen in following order:" echo " Location is chosen in following order:"
echo " - --install-dir option" echo " - --install-dir option"
echo " - Environmental variable DOTNET_INSTALL_DIR" echo " - Environmental variable DOTNET_INSTALL_DIR"
echo " - /usr/local/share/dotnet" echo " - $HOME/.dotnet"
exit 0 exit 0
;; ;;
*) *)

View file

@ -0,0 +1,10 @@
using System;
namespace Microsoft.DotNet.Cli
{
public class BuiltInCommandMetadata
{
public Func<string[], int> Command { get; set; }
public string DocLink { get; set; }
}
}

View file

@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using Microsoft.DotNet.Tools.Add;
using Microsoft.DotNet.Tools.Build;
using Microsoft.DotNet.Tools.Clean;
using Microsoft.DotNet.Tools.Help;
using Microsoft.DotNet.Tools.List;
using Microsoft.DotNet.Tools.Migrate;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.New;
using Microsoft.DotNet.Tools.NuGet;
using Microsoft.DotNet.Tools.Pack;
using Microsoft.DotNet.Tools.Publish;
using Microsoft.DotNet.Tools.Remove;
using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Tools.Run;
using Microsoft.DotNet.Tools.Sln;
using Microsoft.DotNet.Tools.Test;
using Microsoft.DotNet.Tools.VSTest;
using Microsoft.DotNet.Tools.Cache;
namespace Microsoft.DotNet.Cli
{
public static class BuiltInCommandsCatalog
{
public static Dictionary<string, BuiltInCommandMetadata> Commands = new Dictionary<string, BuiltInCommandMetadata>
{
["add"] = new BuiltInCommandMetadata
{
Command = AddCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-add-reference
DocLink = "https://aka.ms/dotnet-add"
},
["build"] = new BuiltInCommandMetadata
{
Command = BuildCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-build
DocLink = "https://aka.ms/dotnet-build"
},
["cache"] = new BuiltInCommandMetadata
{
Command = CacheCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-cache
DocLink = "https://aka.ms/dotnet-cache"
},
["clean"] = new BuiltInCommandMetadata
{
Command = CleanCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-clean
DocLink = "https://aka.ms/dotnet-clean"
},
["help"] = new BuiltInCommandMetadata
{
Command = HelpCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-help
DocLink = "https://aka.ms/dotnet-help"
},
["list"] = new BuiltInCommandMetadata
{
Command = ListCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-list-reference
DocLink = "https://aka.ms/dotnet-list"
},
["migrate"] = new BuiltInCommandMetadata
{
Command = MigrateCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-migrate
DocLink = "http://aka.ms/dotnet-migrate"
},
["msbuild"] = new BuiltInCommandMetadata
{
Command = MSBuildCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-msbuild
DocLink = "https://aka.ms/dotnet-msbuild"
},
["new"] = new BuiltInCommandMetadata
{
Command = NewCommandShim.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-new
DocLink = "https://aka.ms/dotnet-new"
},
["nuget"] = new BuiltInCommandMetadata
{
Command = NuGetCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-nuget-locals
DocLink = "https://aka.ms/dotnet-nuget"
},
["pack"] = new BuiltInCommandMetadata
{
Command = PackCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-pack
DocLink = "https://aka.ms/dotnet-pack"
},
["publish"] = new BuiltInCommandMetadata
{
Command = PublishCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-publish
DocLink = "https://aka.ms/dotnet-publish"
},
["remove"] = new BuiltInCommandMetadata
{
Command = RemoveCommand.Run,
// aka.ms link: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-remove-reference
DocLink = "https://aka.ms/dotnet-remove"
},
["restore"] = new BuiltInCommandMetadata
{
Command = RestoreCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-restore
DocLink = "https://aka.ms/dotnet-restore"
},
["run"] = new BuiltInCommandMetadata
{
Command = RunCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-run
DocLink = "https://aka.ms/dotnet-run"
},
["sln"] = new BuiltInCommandMetadata
{
Command = SlnCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-sln
DocLink = "https://aka.ms/dotnet-sln"
},
["test"] = new BuiltInCommandMetadata
{
Command = TestCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-test
DocLink = "https://aka.ms/dotnet-test"
},
["vstest"] = new BuiltInCommandMetadata
{
Command = VSTestCommand.Run,
// aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-vstest
DocLink = "https://aka.ms/dotnet-vstest"
}
};
}
}

View file

@ -24,13 +24,13 @@ namespace Microsoft.DotNet.Cli
NuGetFramework framework = null, NuGetFramework framework = null,
string configuration = Constants.DefaultConfiguration) string configuration = Constants.DefaultConfiguration)
{ {
Func<string[], int> builtInCommand; BuiltInCommandMetadata builtInCommand;
if (!_alwaysRunOutOfProc && Program.TryGetBuiltInCommand(commandName, out builtInCommand)) if (!_alwaysRunOutOfProc && Program.TryGetBuiltInCommand(commandName, out builtInCommand))
{ {
Debug.Assert(framework == null, "BuiltInCommand doesn't support the 'framework' argument."); Debug.Assert(framework == null, "BuiltInCommand doesn't support the 'framework' argument.");
Debug.Assert(configuration == Constants.DefaultConfiguration, "BuiltInCommand doesn't support the 'configuration' argument."); Debug.Assert(configuration == Constants.DefaultConfiguration, "BuiltInCommand doesn't support the 'configuration' argument.");
return new BuiltInCommand(commandName, args, builtInCommand); return new BuiltInCommand(commandName, args, builtInCommand.Command);
} }
return Command.CreateDotNet(commandName, args, framework, configuration); return Command.CreateDotNet(commandName, args, framework, configuration);

View file

@ -34,6 +34,7 @@ namespace Microsoft.DotNet.Cli
{ {
public class Program public class Program
{ {
private static Dictionary<string, Func<string[], int>> s_builtIns = new Dictionary<string, Func<string[], int>> private static Dictionary<string, Func<string[], int>> s_builtIns = new Dictionary<string, Func<string[], int>>
{ {
["add"] = AddCommand.Run, ["add"] = AddCommand.Run,
@ -58,6 +59,7 @@ namespace Microsoft.DotNet.Cli
["parse"] = ParseCommand.Run ["parse"] = ParseCommand.Run
}; };
public static int Main(string[] args) public static int Main(string[] args)
{ {
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
@ -188,10 +190,10 @@ namespace Microsoft.DotNet.Cli
telemetryClient.TrackEvent(command, null, null); telemetryClient.TrackEvent(command, null, null);
int exitCode; int exitCode;
Func<string[], int> builtIn; BuiltInCommandMetadata builtIn;
if (s_builtIns.TryGetValue(command, out builtIn)) if (BuiltInCommandsCatalog.Commands.TryGetValue(command, out builtIn))
{ {
exitCode = builtIn(appArgs.ToArray()); exitCode = builtIn.Command(appArgs.ToArray());
} }
else else
{ {
@ -234,9 +236,9 @@ namespace Microsoft.DotNet.Cli
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
} }
internal static bool TryGetBuiltInCommand(string commandName, out Func<string[], int> builtInCommand) internal static bool TryGetBuiltInCommand(string commandName, out BuiltInCommandMetadata builtInCommand)
{ {
return s_builtIns.TryGetValue(commandName, out builtInCommand); return BuiltInCommandsCatalog.Commands.TryGetValue(commandName, out builtInCommand);
} }
private static void PrintVersion() private static void PrintVersion()

View file

@ -74,7 +74,7 @@ Runs a portable app named `myapp.dll`.
## ENVIRONMENT ## ENVIRONMENT
`DOTNET_PACKAGES` `NUGET_PACKAGES`
The primary package cache. If not set, it defaults to $HOME/.nuget/packages on Unix or %HOME%\NuGet\Packages on Windows. The primary package cache. If not set, it defaults to $HOME/.nuget/packages on Unix or %HOME%\NuGet\Packages on Windows.

View file

@ -9,21 +9,21 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
public const string AppDescription = "Command to add package reference"; public const string AppDescription = "Command to add package reference";
public const string CmdPackageDescription = "Package reference to add"; public const string CmdPackageDescription = "The package reference to add.";
public const string SpecifyExactlyOnePackageReference = "Please specify one package reference to add."; public const string SpecifyExactlyOnePackageReference = "Please specify one package reference to add.";
public const string CmdFrameworkDescription = "Add reference only when targeting a specific framework"; public const string CmdFrameworkDescription = "Adds reference only when targeting a specific framework.";
public const string CmdNoRestoreDescription = "Add reference without performing restore preview and compatibility check."; public const string CmdNoRestoreDescription = "Adds reference without performing restore preview and compatibility check.";
public const string CmdSourceDescription = "Use specific NuGet package sources to use during the restore."; public const string CmdSourceDescription = "Specifies NuGet package sources to use during the restore.";
public const string CmdPackageDirectoryDescription = "Restore the packages to this Directory ."; public const string CmdPackageDirectoryDescription = "Restores the packages to the specified directory.";
public const string CmdVersionDescription = "Version for the package to be added."; public const string CmdVersionDescription = "Version for the package to be added.";
public const string CmdDGFileException = "Unable to Create Dependency graph file for project '{0}'. Cannot add package reference."; public const string CmdDGFileException = "Unable to create dependency graph file for project '{0}'. Cannot add package reference.";
public const string CmdPackage = "PACKAGE_NAME"; public const string CmdPackage = "PACKAGE_NAME";

View file

@ -35,7 +35,7 @@
</trans-unit> </trans-unit>
<trans-unit id="CmdSourceDescription"> <trans-unit id="CmdSourceDescription">
<source>Use specific NuGet package sources to use during the restore.</source> <source>Use specific NuGet package sources to use during the restore.</source>
<target state="translated">복원 중 사용할 특정 NuGet 패키지 소스를 사용합니다.</target> <target state="translated">복원 중 사용할 특정 NuGet 패키지 원본을 사용합니다.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="CmdPackageDirectoryDescription"> <trans-unit id="CmdPackageDirectoryDescription">

View file

@ -1,8 +1,13 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli;
namespace Microsoft.DotNet.Tools.Help namespace Microsoft.DotNet.Tools.Help
{ {
@ -49,6 +54,32 @@ Project modification commands:
public static int Run(string[] args) public static int Run(string[] args)
{ {
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "dotnet help";
app.FullName = LocalizableStrings.AppFullName;
app.Description = LocalizableStrings.AppDescription;
CommandArgument commandNameArgument = app.Argument($"<{LocalizableStrings.CommandArgumentName}>", LocalizableStrings.CommandArgumentDescription);
app.OnExecute(() =>
{
BuiltInCommandMetadata builtIn;
if (BuiltInCommandsCatalog.Commands.TryGetValue(commandNameArgument.Value, out builtIn))
{
var process = ConfigureProcess(builtIn.DocLink);
process.Start();
process.WaitForExit();
}
else
{
Reporter.Error.WriteLine(String.Format(LocalizableStrings.CommandDoesNotExist, commandNameArgument.Value));
Reporter.Output.WriteLine(UsageText);
return 1;
}
return 0;
});
if (args.Length == 0) if (args.Length == 0)
{ {
PrintHelp(); PrintHelp();
@ -56,7 +87,7 @@ Project modification commands:
} }
else else
{ {
return Cli.Program.Main(new[] { args[0], "--help" }); return app.Execute(args);
} }
} }
@ -73,5 +104,39 @@ Project modification commands:
$" ({Product.Version})"; $" ({Product.Version})";
Reporter.Output.WriteLine(Product.LongName + versionString); Reporter.Output.WriteLine(Product.LongName + versionString);
} }
public static Process ConfigureProcess(string docUrl)
{
ProcessStartInfo psInfo;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
psInfo = new ProcessStartInfo
{
FileName = "cmd",
Arguments = $"/c start {docUrl}"
};
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
psInfo = new ProcessStartInfo
{
FileName = "open",
Arguments = docUrl
};
}
else
{
psInfo = new ProcessStartInfo
{
FileName = "xdg-open",
Arguments = docUrl
};
}
return new Process
{
StartInfo = psInfo
};
}
} }
} }

View file

@ -66,5 +66,18 @@ namespace Microsoft.DotNet.Tools.Help
public const string CleanDefinition = "Clean build output(s)."; public const string CleanDefinition = "Clean build output(s).";
public const string SlnDefinition = "Modify solution (SLN) files."; public const string SlnDefinition = "Modify solution (SLN) files.";
public const string CommandDoesNotExist = "Specified command '{0}' is not a valid CLI command. Please specify a valid CLI commands. For more information, run dotnet help.";
public const string AppFullName = ".NET CLI help utility";
public const string AppDescription = "Utility to get more detailed help about each of the CLI commands.";
public const string CommandArgumentName = "COMMAND_NAME";
public const string CommandArgumentDescription = "CLI command for which to view more detailed help.";
} }
} }

View file

@ -153,18 +153,6 @@
<Target Name="CrossgenPublishDir" <Target Name="CrossgenPublishDir"
Condition=" '$(DISABLE_CROSSGEN)' == '' " Condition=" '$(DISABLE_CROSSGEN)' == '' "
AfterTargets="PublishMSBuildExtensions"> AfterTargets="PublishMSBuildExtensions">
<ItemGroup>
<NETCore10Assemblies Include="$(PublishDir)/System.ComponentModel.Primitives.dll;
$(PublishDir)/System.Collections.Specialized.dll;
$(PublishDir)/System.Collections.NonGeneric.dll;
$(PublishDir)/System.Private.DataContractSerialization.dll" />
</ItemGroup>
<!-- Move these "1.0" assemblies that TestPlatform lays down out of the way so crossgen doesn't pick them up.
We need https://github.com/dotnet/cli/issues/5464 fixed, so test platform is in a separate directory -->
<Move SourceFiles="@(NETCore10Assemblies)"
DestinationFiles="@(NETCore10Assemblies->'$(PublishDir)/%(Filename)%(Extension).bak')" />
<ItemGroup> <ItemGroup>
<!-- Removing Full CLR built TestHost assemblies from getting Crossgen as it is throwing error --> <!-- Removing Full CLR built TestHost assemblies from getting Crossgen as it is throwing error -->
<SdkFiles Include="$(PublishDir)/**/*" Exclude="$(PublishDir)/TestHost*/**/*;$(PublishDir)/Sdks/**/*" /> <SdkFiles Include="$(PublishDir)/**/*" Exclude="$(PublishDir)/TestHost*/**/*;$(PublishDir)/Sdks/**/*" />
@ -195,10 +183,6 @@
PlatformAssemblyPaths="@(PlatformAssemblies); PlatformAssemblyPaths="@(PlatformAssemblies);
@(PublishDirSubDirectories); @(PublishDirSubDirectories);
$(SharedFrameworkNameVersionPath)" /> $(SharedFrameworkNameVersionPath)" />
<!-- Move the "1.0" assemblies back -->
<Move SourceFiles="@(NETCore10Assemblies->'$(PublishDir)/%(Filename)%(Extension).bak')"
DestinationFiles="@(NETCore10Assemblies)" />
</Target> </Target>
<Target Name="RemoveVbc" <Target Name="RemoveVbc"

View file

@ -0,0 +1,19 @@
// 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.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class LinuxOnlyFactAttribute : FactAttribute
{
public LinuxOnlyFactAttribute()
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Linux)
{
this.Skip = "This test requires linux to run";
}
}
}
}

View file

@ -0,0 +1,19 @@
// 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.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class MacOsOnlyFactAttribute : FactAttribute
{
public MacOsOnlyFactAttribute()
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
this.Skip = "This test requires macos to run";
}
}
}
}

View file

@ -8,6 +8,7 @@ using Microsoft.Build.Construction;
using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit; using Xunit;
using FluentAssertions; using FluentAssertions;
using HelpActual = Microsoft.DotNet.Tools.Help;
namespace Microsoft.DotNet.Help.Tests namespace Microsoft.DotNet.Help.Tests
{ {
@ -65,5 +66,40 @@ Advanced Commands:
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().ContainVisuallySameFragment(HelpText); cmd.StdOut.Should().ContainVisuallySameFragment(HelpText);
} }
[Fact]
public void WhenInvalidCommandIsPassedToDotnetHelpItPrintsError()
{
var cmd = new DotnetCommand()
.ExecuteWithCapturedOutput("help invalid");
cmd.Should().Fail();
cmd.StdErr.Should().ContainVisuallySameFragment($"Specified command 'invalid' is not a valid CLI command. Please specify a valid CLI commands. For more information, run dotnet help.");
cmd.StdOut.Should().ContainVisuallySameFragment(HelpText);
}
[WindowsOnlyFact]
public void WhenRunOnWindowsDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("cmd", proc.StartInfo.FileName);
Assert.Equal("/c start https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
[LinuxOnlyFact]
public void WhenRunOnLinuxDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("xdg-open", proc.StartInfo.FileName);
Assert.Equal("https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
[MacOsOnlyFact]
public void WhenRunOnMacOsDotnetHelpCommandShouldContainProperProcessInformation()
{
var proc = HelpActual.HelpCommand.ConfigureProcess("https://aka.ms/dotnet-build");
Assert.Equal("open", proc.StartInfo.FileName);
Assert.Equal("https://aka.ms/dotnet-build", proc.StartInfo.Arguments);
}
} }
} }