C#通过Visual Studio 2019将.NET Core 3.0编译为本机代码

时间:2019-02-05 20:01:52

标签: c# .net-core .net-core-3.0 corert

我正在将Visual Studio 2019与C#8.0一起使用,我的项目基于以下示例: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>

1 个答案:

答案 0 :(得分:0)

您可以在构建后事件中发布它,而无需重新编译 dotnet publish --no-build --no-restore /p:NativeLib=Shared -r win-x64 -c release