有没有办法限制 .NET Core 项目在使用 .NET Core 3.1 sdk 时只生成 .dll 作为输出文件 [英] Is there a way to restrict .NET Core projects to generate only .dll as output files when using .NET Core 3.1 sdk
问题描述
当我使用 .NET Core 3.1 sdk 构建我的 .NET Core 控制台应用程序时,它会同时生成 .exe 和 .dll 作为输出.当我使用 .NET Core 2.1 时,它只生成 .dll 作为输出.有没有办法限制 .NET Core 3.1 sdk 只生成 .dll 作为输出?
When i build my .NET Core Console Application using .NET Core 3.1 sdk,it generates both .exe as well as .dll as output. When i was using .NET Core 2.1 it was generating only .dll as output. Is there a way to restrict .NET Core 3.1 sdk to generate only .dll as output?
推荐答案
您可以使用 UseAppHost
MSBuild 设置:
You can control this with the UseAppHost
MSBuild setting:
UseAppHost
属性是在 .NET Core SDK 2.1.400 版本中引入的.它控制是否为部署创建本机可执行文件.独立部署需要本机可执行文件.
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.
在 .NET Core 3.0 及更高版本中,默认情况下会创建依赖于框架的可执行文件.将 UseAppHost
属性设置为 false
以禁用可执行文件的生成.
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 中设置它,请将属性作为参数传递.例如:
If you want to disable this when building from the command line, instead of setting it within the .csproj, pass the property as an argument. For example:
dotnet build /p:UseAppHost=false
这篇关于有没有办法限制 .NET Core 项目在使用 .NET Core 3.1 sdk 时只生成 .dll 作为输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!