【问题标题】:Cannot Run DNX Console Applications无法运行 DNX 控制台应用程序
【发布时间】:2016-05-30 19:51:20
【问题描述】:

我无法使用 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

这是project.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)

【问题讨论】:

    标签: dnx


    【解决方案1】:

    你配置错了。我想您想要的是 project.json 文件中的以下内容:

    {
        "frameworks": {
                "dnx451" : {
                }
                "dnxcore50" : {
                    "dependencies": {
                        "System.Console": "4.0.0-beta-*"
                    }
                }
        },
    
        "commands": {
            "me": "run"
        }
    }
    

    现在运行:

    dnu restore
    dnx . me
    

    它应该可以工作。

    【讨论】:

    • 是的,我在框架部分看到了错误。谢谢你。 “运行”是关键字吗??我原以为这是我的班级“程序”的名称
    • 究竟在哪里声明了这个“运行”关键字?不应该是"me" : "Program"吗?
    • 在 beta7 和更高版本是 dnx me 而不是 dnx . me
    【解决方案2】:

    System.Console 的最新版本(测试版除外)目前与“dnxcore50”不兼容,并且有重大更改。

    建议选项:

    1- 以完整框架“dnx451”而不是核心为目标;

    2- 仅使用带有“dnxcore50”的 System.Console 测试版;或

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-19
      • 2016-01-26
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      相关资源
      最近更新 更多