我正在使用 dotnet 将 ASP.NET Core DNX 命令行工具从 RC1 移植到 RC2。它使用完整的框架 4.5.1。我已将其简化为一个非常简单的项目。我怀疑我缺少一些基本的东西,但我似乎找不到平行的例子。如果这是一个简单的修复,请提前道歉。
重现步骤
这是我的 project.json 文件。
{
"version": "1.0.2-alpha001",
"description": "Tools.Cli Class Library",
"authors": [ "Test" ],
"buildOptions": {
"emitEntryPoint": true,
"outputName": "dotnet-hello"
},
"dependencies": {
"Microsoft.DotNet.Cli.Utils": "1.0.0-preview1-002702"
},
"frameworks": {
"net451": { }
}
}
这是我的 program.cs 文件。
using System;
namespace Tools.Cli
{
public class Program
{
public static int Main(string[] args)
{
Console.WriteLine("\x1B[31m" + "Hello World" + "\x1B[39m");
// The following line causes the error. Commenting out this line allows this to run.
Console.WriteLine(Microsoft.DotNet.Cli.Utils.AnsiColorExtensions.Red("Test"));
return 0;
}
}
}
我正在创建一个 NuGet 包并将其作为工具从另一个项目中引用。
预期行为
运行dotnet hello
以红色打印 Hello World,然后以红色打印测试。
这在没有打印测试行的情况下完美地工作。
实际行为
显示以下异常。未打印 Hello World。
dotnet hello
Unhandled Exception: System.IO.FileNotFoundException:
Could not load file or assembly 'Microsoft.DotNet.Cli.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies.
The system cannot find the file specified.
at Tools.Cli.Program.Main(String[] args)
此时我收到一个错误对话框,提示进行调试。
我已经尝试过许多其他具有相同结果的程序集。
我将此作为问题发布在 GitHub 的 dotnet/cli 上,但尚未收到回复。 https://github.com/dotnet/cli/issues/3274
环境数据
.NET 命令行工具 (1.0.0-preview1-002702)
产品信息: 版本:1.0.0-preview1-002702 Commit Sha:6cde21225e
运行环境:操作系统名称:Windows 操作系统版本:10.0.10586 操作系统平台:Windows RID:win10-x64