0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsコンテナーで .NET 10 Preview のファイルベースアプリのNativeAOT出力を試す

Posted at

Preview版で環境を変更したくないのでWindowsコンテナーを使ってみます。

動作環境

  • Windows 11 24H2

下記の方法でWindowsコンテナーとdockerをインストールしておく。

Compose.yml

services:
  dotnet10:
    image: mcr.microsoft.com/dotnet/sdk:10.0-preview-windowsservercore-ltsc2025
    container_name: dotnet10
    volumes:
      - .\dotnet10:C:\dotnet10
    working_dir: C:\dotnet10

あらかじめ、dotnet10 フォルダーを作成し、中に test.cs を作成しておく。

Console.WriteLine("ハロー、ファイルベースアプリ!");

NativeAOTコンパイル環境構築

コンテナーを起動。

docker compose run --rm dotnet10

まずはマネージドで実行。

dotnet run test.cs

ハロー、ファイルベースアプリ!

publish (ファイルベースはデフォルトでNativeAOT) してみます。

dotnet publish test.cs

C:\Users\ContainerAdministrator.nuget\packages\microsoft.dotnet.ilcompiler\10.0.0-preview.7.25380.108\build\Microsoft.NETCore.Native.Windows.targets(142,5): error : Platform linker not found. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites, in particular the Desktop Development for C++ workload in Visual Studio. For ARM64 development also install C++ ARM64 build tools.

エラーが出力されました。C++ビルドツールが入ってないですよという意味のようです。残念ながら公式のイメージにはC++向けのビルドツールが入っていません。

色々試した結果、vs_BuildTools.exe で解決します。

curl -SLO https://aka.ms/vs/17/release/vs_BuildTools.exe
start /wait vs_BuildTools.exe --quiet --norestart --wait --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.26100
dotnet publish test.cs

成功しました。artifacts/test/test.exe に出力されます。

C:\dotnet10>dir /s
 Volume in drive C has no label.
 Volume Serial Number is 8EB4-9540

 Directory of C:\dotnet10

09/06/2025  01:10 PM    <DIR>          .
09/05/2025  01:28 AM    <DIR>          ..
09/06/2025  12:59 PM    <DIR>          artifacts
09/06/2025  12:53 PM               209 test.cs
09/06/2025  01:10 PM         4,465,872 vs_BuildTools.exe
               2 File(s)      4,466,081 bytes

 Directory of C:\dotnet10\artifacts

09/06/2025  12:59 PM    <DIR>          .
09/06/2025  01:10 PM    <DIR>          ..
09/06/2025  01:47 PM    <DIR>          test
               0 File(s)              0 bytes

 Directory of C:\dotnet10\artifacts\test

09/06/2025  01:47 PM    <DIR>          .
09/06/2025  12:59 PM    <DIR>          ..
09/06/2025  01:47 PM         3,754,496 test.exe
09/06/2025  01:47 PM        13,815,808 test.pdb
               2 File(s)     17,570,304 bytes

     Total Files Listed:
               4 File(s)     22,036,385 bytes
               8 Dir(s)  435,931,357,184 bytes free

実行してみます。

artifacts\test\test.exe

??????????????!

見事に文字化けしました。why?

chcp

Active code page: 437

コードページが 437 (OEM米国) になっています。65001 (UTF-8) を指定して再度実行します。

chcp 65001
artifacts\test\test.exe

ハロー、ファイルベースアプリ!

Congratulation!

おしまい。

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?