.net-core - C# 通过 Visual Studio 2019 将 .NET Core 3.0 编译为 Native Code
问题描述
我正在使用带有 C# 8.0 的 Visual Studio 2019,我的项目基于此示例:https ://github.com/dotnet/corert/tree/master/samples/HelloWorld
当我打开命令提示符并在我的解决方案文件夹中导航时,我使用以下命令编译本机代码:
dotnet 发布 -c 发布 -r win-x64
这很好用。
但是,在 Visual Studio 2019 中编译/构建(而不是使用 cmd)不会生成本机代码。在输出窗口中没有“生成本机代码”步骤。
这是我的 .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyVersion>1.0.1234</AssemblyVersion>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Platforms>x64</Platforms>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-*" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
</Project>
解决方案
您可以在构建后事件中发布它而无需重新编译
dotnet publish --no-build --no-restore /p:NativeLib=Shared -r win-x64 -c release
推荐阅读
- .net - InstanceContextMode.Single 是否可用于 WCF basicHttpBinding?
- zebra-printers - 尝试使用 SGD 代码更改 Zebra 打印机上的 IP 配置
- pycharm - Pycharm 默认不折叠自定义代码区域
- amazon-web-services - 如何通过代码启用 AWS Elastic Beanstalk 运行状况规则“忽略负载均衡器 4xx”?
- google-api - 如何长时间访问(离线)Google API?
- arrays - 如何在数组中插入公式?
- c - 简单的 Windows 程序在 Linux 终端中运行,但不在 Windows cmd 中
- python - 如何在构建 Json 字符串时清除数组并重置 for 循环中的值?
- go - 如何使用 client-go 访问 kubernetes CRD?
- java - 如何在java中打印多个int