我正在使用带有C# 8.0的Visual Studio 2019,我的项目基于此示例:https://github.com/dotnet/corert/tree/master/samples/HelloWorld
当我打开命令提示符并在解决方案文件夹中导航时,我使用以下命令在本机代码中进行编译:
dotnet publish -c release -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