Skip to content

在Linux通过wine编译能在Windows使用的C# Native Aot

Notifications You must be signed in to change notification settings

scgm0/NativeAotTest

Repository files navigation

在 Linux 通过 wine 编译能在 Windows 使用的 C# Native Aot

使用的 Linux 发行版: Arch Linux

方案一

  • 1.使用 AUR 助手yayparu安装winemsvc-wine-git

  • 2.在.Net官网下载dotnet8exe安装程序,使用wine运行并安装

  • 3.运行wine regedit修改注册表HKEY_CURRENT_USER\Environment添加以下环境变量:

    `/opt/msvc`是aur中`msvc-wine-git`的默认安装路径,如果安装在了其他路径请自行替换
    PATH: /opt/msvc/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64
    LIB: /opt/msvc/Windows Kits/10/Lib/10.0.22621.0/um/x64;Z:/opt/msvc/Windows Kits/10/Lib/10.0.22621.0/ucrt/x64;/opt/msvc/VC/Tools/MSVC/14.41.34120/lib/x64
    
  • 4.设置项目属性<IlcUseEnvironmentalTools>true</IlcUseEnvironmentalTools>

  • 5.在项目根目录运行wine dotnet publish ./ -r win-x64 -c Release触发编译

  • 6.运行编译结果wine ./bin/Release/net8.0/win-x64/publish/NativeAotTest.exe,成功打印Hello, World!

方案二(推荐)

  • 1.使用 AUR 助手yayparu安装winemsvc-wine-git

  • 2.在项目中引入PublishAotCross.targets(复制到其他项目中时,PublishAotCross.targetsCrosscompile.targets应该一起复制)

    (可选)
    如果`msvc-wine-git`安装目录不是`/opt/msvc`,请在项目中添加`MSVCWineBinPath`属性
    默认为<MSVCWineBinPath>/opt/msvc/bin</MSVCWineBinPath>
    
  • 3.在项目根目录运行dotnet publish ./ -r win-x64 -c Release触发编译

  • 4.运行编译结果wine ./bin/Release/net8.0/win-x64/publish/NativeAotTest.exe,成功打印Hello, World!

About

在Linux通过wine编译能在Windows使用的C# Native Aot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages