在 .NET Core RC2 中构建 .exe 文件 [英] Build .exe file in .NET Core RC2

查看:31
本文介绍了在 .NET Core RC2 中构建 .exe 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我使用新的 .NET Core RC2 模板构建项目时,我都没有获得可运行的 .EXE 文件.如果我按 F5 来调试我的控制台应用程序,它可以通过

Every time I build a project using the new .NET Core RC2 templates I am not provided with a runnable .EXE file. If I hit F5 for debugging my console application it runs fine through the

C:Program Filesdotnetdotnet.exe 

申请.如果我使用

dotnet run 

文件夹中的命令,它也运行良好.但我认为没有 .NET Core CLI 工具就无法运行应用程序.

command in the folder, it runs fine as well. But I see no way to run the application without the .NET Core CLI tools.

我的内容

 binDebug
etcoreapp1.0

文件夹如下所示:

如您所见,没有可用的 .EXE 文件.只是 dll.

As you can see there is no .EXE file available. Just the dll.

我是否忽略了什么?还是我的 project.json 文件有问题?

Am I overlooking something? Or is there something wrong with my project.json file?

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

谢谢!

推荐答案

.NET Core 中实际上有 2 个应用模型:

There are actually 2 app models in .NET Core:

  • 便携式应用:深受DNX 控制台应用"的启发,这些应用不生成 .exe 文件,而是由 .NET Core 执行共享运行时(其版本由 Microsoft.NETCore.App 包定义,这要归功于其特殊的 type: platform 属性).必须在机器上安装相应的 .NET Core 运行时才能使用便携式应用程序.如果找不到确切的版本,则在运行 dotnet run 时会抛出异常.

  • Portable apps: heavily inspired by "DNX console apps", these apps don't produce .exe files and are instead executed by the .NET Core shared runtime (whose version is defined by the Microsoft.NETCore.App package, thanks to its special type: platform attribute). The corresponding .NET Core runtime must be installed on the machine to be able to use portable apps. If the exact version cannot be found, an exception is thrown when running dotnet run.

独立应用:独立应用与旧的 .NET 控制台应用非常相似,因为它们生成 .exe 文件..NET Core 运行时不必安装在机器上,因为它直接嵌入到应用程序本身中.

Standalone apps: standalone apps are really similar to good old .NET console apps as they produce .exe files. The .NET Core runtime doesn't have to be installed on the machine, because it is directly embedded with the application itself.

您目前使用的是第一个模型.要使用独立模型,您需要调整您的 project.json:

You're currently using the first model. To use the standalone model, you need to tweak your project.json:

  • 添加一个 runtimes 部分以列出您的应用将针对的环境(例如 win7-x64ubuntu.14.04-x64).您可以在此处找到完整列表.
  • 删除 Microsoft.NETCore.App 依赖项.你可以用这个包代替它:"NETStandard.Library": "1.5.0-rc2-24027".
  • Add a runtimes section to list the environments your app will target (e.g win7-x64 or ubuntu.14.04-x64). You can find the complete list here.
  • Remove the Microsoft.NETCore.App dependency. You can replace it by this package instead: "NETStandard.Library": "1.5.0-rc2-24027".

以下是独立应用的示例:

Here's an example of a standalone app:

{
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "warningsAsErrors": true
  },

  "dependencies": {
    "Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "NETStandard.Library": "1.5.0-rc2-24027"
  },

  "frameworks": {
    "net451": { },

    "netcoreapp1.0": {
      "dependencies": {
        "System.Net.Ping": "4.0.0-rc2-24027"
      },

      "imports": [
        "dnxcore50",
        "dotnet5.6",
        "portable-net451+win8"
      ]
    }
  },

  "runtimes": {
    "win7-x64": { }
  }
}

这篇关于在 .NET Core RC2 中构建 .exe 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆