在.NET Core RC2中生成.exe文件 [英] Build .exe file in .NET Core RC2

查看:88
本文介绍了在.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 Files\dotnet\dotnet.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.

我的内容

 bin\Debug\netcoreapp1.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天全站免登陆