【问题标题】:C# Compile .NET Core 3.0 to Native Code through Visual Studio 2019C# 通过 Visual Studio 2019 将 .NET Core 3.0 编译为 Native Code
【发布时间】:2019-06-29 17:30:14
【问题描述】:

我正在使用带有 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支持。
  • @IanKemp 以任何方式在 Visual Studio 2019 中执行 dotnet publish?
  • 尝试从构建后事件(项目 > 属性 > 构建事件 > 构建后事件命令行)运行它。
  • @IanKemp 这意味着构建项目两次?也许.csproj中有一个条目可以直接用VS2019编译它?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-06-07
    • 2020-01-23
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 2022-02-18
    • 2017-02-13
    • 1970-01-01
    相关资源
    最近更新 更多