无法运行DNX控制台应用程序

6

我遇到了一些困难,无法使用dnx命令行运行一个简单的控制台测试应用程序。我知道这是目前正在发展的技术,但为了自己的理智,我想让它继续运行。

以下是程序:

using System;

public class Program
{
    public void Main(string[] args)
    {
        Console.WriteLine("Foo");
        Console.ReadLine();
    }
}

这是 DNVM 列表。
Active Version     Runtime Architecture Location                   Alias
------ -------     ------- ------------ --------                   -----
  *    1.0.0-beta4 clr     x64          C:\Users\Tim\.dnx\runtimes
       1.0.0-beta4 clr     x86          C:\Users\Tim\.dnx\runtimes
       1.0.0-beta4 coreclr x64          C:\Users\Tim\.dnx\runtimes
       1.0.0-beta4 coreclr x86          C:\Users\Tim\.dnx\runtimes

这是项目的json文件。
{

    "frameworks": {
        "aspnet50":{}
    },

    "dnxcore50" : {
      "dependencies": {
        "System.Console": "4.0.0-*",
        "System.Collections": "4.0.10-*",
        "System.Linq": "4.0.0-*",
        "System.Threading": "4.0.10-*",
        "Microsoft.CSharp": "4.0.0-*"
      }
    },

    "commands": {
        "me": "Program"
    }
}

这是 dnu build ConsoleApp 的结果。
Building ConsoleApp for Asp.Net,Version=v5.0
  Using Project dependency ConsoleApp 1.0.0
    Source: C:\_Git\learndnx\ConsoleApp\project.json

  Using Assembly dependency framework/mscorlib 4.0.0.0
    Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll

  Using Assembly dependency framework/System 4.0.0.0
    Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll

  Using Assembly dependency framework/System.Core 4.0.0.0
    Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Core.dll

  Using Assembly dependency framework/Microsoft.CSharp 4.0.0.0
    Source: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll


Build succeeded.
    0 Warnings(s)
    0 Error(s)

Time elapsed 00:00:00.3038706

在这里我感到困惑,因为我看过的一些旧视频现在已经过时了,我不确定去哪里查找有关更改内容的信息。

我期望dnx ConsoleApp me会运行我的程序,但是它很遗憾并没有运行。

错误:

System.InvalidOperationException: Unable to load application or execute command 'Program'. Available commands: me.
   at Microsoft.Framework.ApplicationHost.Program.ThrowEntryPointNotfoundException(DefaultHost host, String applicationN
ame, Exception innerException)
   at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
   at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
2个回答

7
您的配置有误。我猜您想在project.json文件中添加以下内容:
{
    "frameworks": {
            "dnx451" : {
            }
            "dnxcore50" : {
                "dependencies": {
                    "System.Console": "4.0.0-beta-*"
                }
            }
    },

    "commands": {
        "me": "run"
    }
}

现在运行:
dnu restore
dnx . me

它应该可以正常工作。


2
是的,我看到了框架部分的错误。谢谢。"run"是关键字吗?我以为那应该是我的类名"Program"。 - ChiliYago
这个“run”关键字是在哪里声明的?不应该是“me”:“Program”吗? - bitbonk
4
从 beta7 版本开始,应该使用 dnx me 而不是 dnx . me - pg0xC

0

除了beta版本以外,最新版本的System.Console与"dnxcore50"不兼容,并且有破坏性变化。

建议选项:

1- 将目标框架改为完整框架"dnx451";

2- 仅使用带有"dnxcore50"的System.Console的beta版本;或者

3- 使用Debug.Print()代替Console.WriteLine()


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接