c# - 有没有办法限制 .NET Core 项目在使用 .NET Core 3.1 sdk 时只生成 .dll 作为输出文件

标签 c# .net asp.net-core .net-core

当我使用 .NET Core 3.1 sdk 构建我的 .NET Core 控制台应用程序时,它会同时生成 .exe 和 .dll 作为输出。当我使用 .NET Core 2.1 时,它只生成 .dll 作为输出。有没有办法限制 .NET Core 3.1 sdk 只生成 .dll 作为输出?

最佳答案

您可以使用 UseAppHost 来控制它MSBuild 设置:

The UseAppHost property was introduced in the 2.1.400 version of the .NET Core SDK. It controls whether or not a native executable is created for a deployment. A native executable is required for self-contained deployments.

In .NET Core 3.0 and later versions, a framework-dependent executable is created by default. Set the UseAppHost property to false to disable generation of the executable.

<PropertyGroup>
    <UseAppHost>false</UseAppHost>
</PropertyGroup>


如果您想在从命令行构建时禁用它,而不是在 .csproj 中设置它,请将属性作为参数传递。例如:

dotnet build /p:UseAppHost=false

关于c# - 有没有办法限制 .NET Core 项目在使用 .NET Core 3.1 sdk 时只生成 .dll 作为输出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61612362/

相关文章:

c# - 我应该如何设置用户控件来触发其子项的事件,就好像它们是它自己的一样?

unit-testing - 单元测试 Mvc6 TagHelpers

c# - 从 XML 节点读取值?

c# - Ubuntu - 运行 dotnet new 控制台时出现段错误错误

C# 项目更新从两个表中选择的行的 MySQL 列表

.net - Sort() 和 BinarySearch() 与整数/字符串的性能比较

.net - 多态性是否会干扰 NHibernate 的批量插入/更新功能?

c# - WCF webservice - 使用锁会导致问题吗?

c# - 当它似乎被添加到项目时,引用丢失的错误

c# - ArgumentNullException : Value cannot be null.(参数 'items')异常