VS2017将NetCoreApp编译为EXE [英] VS2017 Compile NetCoreApp as EXE

查看:330
本文介绍了VS2017将NetCoreApp编译为EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2017中创建了一个NetCoreApp(v1.1)。编译它时,我得到了一个DLL,而不是生成的项目的预期EXE。我确实检查了 csproj 文件,并确认输出类型设置为 exe ,但没有骰子。

I created a NetCoreApp (v1.1) in Visual Studio 2017. When I compile it, I get a DLL produced instead of the expected EXE for the built project. I did check the csproj file and confirmed the output type is set to exe, but no dice.

有什么想法为什么VS2017仍在生成DLL?我确定这是我忘记的某个地方的快速设置,它也是凌晨1点。 :)

Any ideas why VS2017 is still producing a DLL? I'm sure its a quick setting somewhere that I forgot... its also 1 AM. :)

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Core.EF.SqlServer\Core.EF.SqlServer.csproj" />
  </ItemGroup>

</Project>


推荐答案

更新2019:

.NET Core 3.0+项目现在将包含默认情况下所构建平台的可执行文件。这只是一个填充程序可执行文件,您的主要逻辑仍然在 .dll 文件中。

.NET Core 3.0+ projects will now include an executable for the platform you build on by default. This is just a shim executable and your main logic is still inside a .dll file.

但是.NET Core 3.0还引入了单文件部署,因此使用

But .NET Core 3.0 also introduced single-file deployments so deploying with

dotnet publish -r win-x64 -p:PublishSingleFile=True --self-contained false

将创建一个包含所有依赖项的.exe文件。您可以将-自包含更改为 true ,以也包含.NET Core运行时。不需要在目标计算机上全局安装。

will create a single .exe file containing all your dependencies. You can change --self-contained to true to also include the .NET Core Runtime as well so .NET Core does not need to be installed globally on the target machine.

原始

.NET Core应用程序应该是 .dll 文件。在这种情况下,将 OutputType 设置为 Exe 表示可执行,并执行所有必要的操作以确保输出可运行(输入从 Main()方法指向 .runtimeconfig.json 文件)。生成的dll文件应使用以下命令运行:

.NET Core applications are supposed to be .dllfiles. OutputType set to Exe in this case means "executable" and does everything necessary to ensure that the output is runnable (entry point from Main() method, .runtimeconfig.json file). The resulting dll file is meant to be run using:

dotnet yourapp.dll 

此dll文件可在.net核心运行时支持的所有平台(Windows,Linux,macOS)上运行。这称为便携式或依赖于框架部署。

This dll file works across all platforms that are supported by the .net core runtime (windows, linux, macOS). This is called a "portable" or "framework dependant" deployment.

如果您确实想要 .exe 文件,请考虑独立的部署。这将创建一个包含自己的.net核心运行时副本和 yourapp.exe 文件的输出-但它还会增加已发布应用的大小,并且需要在发布新版本的运行时时,将对其进行更新。
而且,生成的应用程序仅可在为其发布的操作系统上运行。

If you want really a .exe file, consider self-contained deployments. This will create an output that contains its own copy of the .net core runtime and an yourapp.exe file - but it also increases the size of the published app and it needs to be updated when new versions of the runtime are released. Also, the resulting application only works on the operating system published for.

请参考 .NET Core应用程序部署 ,以获取有关部署选项以及如何设置它们。

Refer to .NET Core application deployment for more details on the deployment options and how to set them up.

这篇关于VS2017将NetCoreApp编译为EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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