使用 Visual Studio 2017 将 .NET Core 应用程序编译为 EXE 文件 [英] Compile a .NET Core application as an EXE file using Visual Studio 2017

查看:30
本文介绍了使用 Visual Studio 2017 将 .NET Core 应用程序编译为 EXE 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

为什么 Visual Studio 2017 仍在生成 DLL 文件?

Why is Visual Studio 2017 is still producing a DLL file?

我确定这是我忘记的某个地方的快速设置...

I'm sure it's a quick setting somewhere that I forgot...

<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.SqlServerCore.EF.SqlServer.csproj" />
  </ItemGroup>

</Project>

推荐答案

2019 年更新:

.NET Core 3.0+ 项目现在将包含默认情况下您构建的平台的可执行文件.这只是一个 shim 可执行文件,您的主要逻辑仍在 .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 文件.您可以将 --self-contained 更改为 true 以还包括 .NET Core 运行时,因此 .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 Core 运行时支持的所有平台(Windows、Linux 和 macOS).这被称为便携式"设备.或依赖于框架"部署.

This DLL file works across all platforms that are supported by the .NET Core runtime (Windows, Linux, and macOS). This is called a "portable" or "framework dependent" deployment.

如果您真的想要一个 .exe 文件,请考虑独立部署.这将创建一个输出,其中包含它自己的 .NET Core 运行时副本和一个 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 application 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.

这篇关于使用 Visual Studio 2017 将 .NET Core 应用程序编译为 EXE 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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