PublishAotCross.Tools 0.6.0.5

dotnet add package PublishAotCross.Tools --version 0.6.0.5
                    
NuGet\Install-Package PublishAotCross.Tools -Version 0.6.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PublishAotCross.Tools" Version="0.6.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PublishAotCross.Tools" Version="0.6.0.5" />
                    
Directory.Packages.props
<PackageReference Include="PublishAotCross.Tools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PublishAotCross.Tools --version 0.6.0.5
                    
#r "nuget: PublishAotCross.Tools, 0.6.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PublishAotCross.Tools@0.6.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PublishAotCross.Tools&version=0.6.0.5
                    
Install as a Cake Addin
#tool nuget:?package=PublishAotCross.Tools&version=0.6.0.5
                    
Install as a Cake Tool

PublishAotCross

Forked from MichalStrehovsky/PublishAotCross

This is a NuGet package with an MSBuild target to aid in crosscompilation with PublishAot. It helps resolving following error:

$ dotnet publish -r linux-x64
Microsoft.NETCore.Native.Publish.targets(59,5): error : Cross-OS native compilation is not supported.

This nuget package allows using Zig as the linker/sysroot to allow crosscompiling to linux-x64/linux-arm64/linux-musl-x64/linux-musl-arm64 from a Windows/Linux/macOS machine, and xwin to windows-x64/windows-arm64 from Windows, Linux or macOS machine.

The xwin implemetation is based on Windows10CE's project

Usage

Typical Cross build

Zig

By default it relies on Zig provided by the unofficial Vezel.Zig.Toolsets NuGet package. You can specify version of this package using the ZigVersion property (current default: 0.16.0.2). Instructions for using your own Zig binaries are near the end of this document.

If you don't want to use Zig from the Vezel.Zig.Toolsets NuGet package, you can specify /p:UseExternalZig=true. This will use whatever Zig is on your PATH. Download an archive with Zig for your host machine, extract it and place it on your PATH.

  1. Optional: download LLVM. We only need llvm-objcopy executable so if you care about size, you can delete the rest. The executable needs to be on PATH - you could copy it next to the Zig executable. This step is optional and is required only to strip symbols (make the produced executables smaller). If you don't care about stripping symbols, you can skip it.

  2. To your project that is already using Native AOT, add a reference to PublishAotCross.Tools.

  3. Publish for one of the newly available RIDs:

    • dotnet publish -r linux-x64
    • dotnet publish -r linux-arm64
    • dotnet publish -r linux-musl-x64
    • dotnet publish -r linux-musl-arm64
    • dotnet publish -r osx-x64
    • dotnet publish -r osx-arm64

    If you skipped the second optional step to download llvm-objcopy, you must also pass /p:StripSymbols=false to the publish command, or you'll see an error instructing you to do that.

    You can specify a custom glibc version via /p:GlibcVersion=<version> (e.g. 2.35). This appends the version suffix to the target triple (e.g. x86_64-linux-gnu.2.35).

This package also supports Windows-to-Windows Native AOT compilation without Visual Studio C++ tools, using xwin SDK store + lld-link + Zig toolchain.

XWin

The package is self-contained. No manual installation of xwin, lld-link, or Windows SDK is required. Add the package reference and build.

  1. To your project that is already using Native AOT, add a reference to this NuGet package.

  2. Publish for one of the newly available RIDs:

    • dotnet publish -c Release -r win-x64
    • dotnet publish -c Release -r win-arm64

Use Zig as c compiler on same host

This package auto detects if host and target platforms are different to determine if Zig is used or not. Even though on the same platform, Zig can also be used as the dropped in C Compiler with

dotnet publish -r linux-x64 /p:PublishAot=true

AotPreferCustom defaults to true (xwin + lld-link). Set -p:AotPreferCustom=false to use Visual Studio C++ tools.

Tested Variants

(Host)Windows x64 Linux GNU x64 Linux GNU arm64 Linux MUSL x64 Linux MUSL arm64
(target)Windows x64 O O N/A N/A N/A
(target)Windows arm64 O N/A N/A N/A N/A
Linux GNU x64 O O O N/A N/A
Linux GNU arm64 O O O N/A N/A
Linux MUSL x64 O O O N/A N/A
Linux MUSL arm64 O O O N/A N/A

Notes: N/A means it might work but not tested. macOS host/target are not tested yet.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0.5 32 7/23/2026