紫薇修真诀,cadeau,0xc000022
假设我有一个简单的“ hello world”控制台应用程序,我想发送给朋友来运行。朋友没有安装.net core,所以我知道我需要为他构建一个独立的应用程序。很简单,我只需在项目目录中运行以下命令:
dotnet publish -r win-x64 -c release --self-contained
朋友是多少位的操作系统,你就标记要发布成什么样子的, --self-contained这个标签的解释自包含,就是说你的相关依赖项与你的应用程序不挂钩,将会产生依赖,缺少一个dll就会缺胳膊少腿。所以这样你就必须将整个文件夹都托给朋友。
看看文件夹里的情况,它会发生什么?293个文件,这直接将.net core的运行时也打包了,这非常nice!不过我这文件真的很多,我很难受!朋友会说:这什么鬼?exe在哪里?
所以.net core给我们提供了一个命令标志, dotnet publish -r win-x64 -c release /p:publishsinglefile=true 您会注意到,我们不再指定自包含标志。这是因为假设如果您将其打包为单个exe,则将需要它的所有依赖关系。这一定说得通。我们试着去运行该命令。随后打开publish文件,我们发现!这也太干净了吧! 但是文件还是有点大呀,这可只是一个hello world呀!,我们在思考如何进行优化大小,当然这一点微软也给我们考虑到了!!!
使用命令 dotnet publish -r win-x64 -c release /p:publishsinglefile=true /p:publishtrimmed=true 我们拭目以待吧。
不通过dotcli发布可以修改一下项目文件,再通过visualstudio发布!
<project sdk="microsoft.net.sdk.windowsdesktop"> <propertygroup> <outputtype>exe</outputtype> <targetframework>netcoreapp3.0</targetframework> <usewindowsforms>true</usewindowsforms> <runtimeidentifier>win10-x64</runtimeidentifier>//发布平台 <publishsinglefile>true</publishsinglefile>//是否单个exe </propertygroup> <propertygroup> <publishtrimmed>true</publishtrimmed>//启用压缩 </propertygroup> </project>
祝.net core愈来愈好!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论