A few days ago, I encountered a problem on my Windows machine and had to reinstall everything. After reinstalling Visual Studio and attempting to compile my project, I started receiving the following error when trying to perform Ahead-of-Time (AOT) compilation with the following command:
dotnet publish -r win-x86 -c Release
C:Program Filesdotnetsdk8.0.400SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1203: Ahead-of-Time compilation is not supported for the target runtime identifier 'win-x86'
Before the crash and the subsequent reinstall, I was able to successfully publish my app as native with AOT. I can still compile into x86 release without problems. Since the crash, I haven’t altered any project configurations.
Details:
-
App Type: Windows console application
-
Current .NET SDK Version: 8.0.400
-
CSProj File:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PublishAot>true</PublishAot>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<Platforms>AnyCPU;x64;x86</Platforms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<TrimMode>partial</TrimMode>
<AssemblyName>MyApp</AssemblyName>
<PublishAot>true</PublishAot>
</PropertyGroup>
...my packages
</Project>
What steps can I take to resolve this issue and re-enable AOT compilation for my project?
Thanks!
What i did:
-
I installed from scratch
– .NET development for desktop
– Development of windows applications -
Opened my Console app and tried to execute
dotnet publish -r win-x86 -c ReleaseI expected a normal x86 AOT compilation as it used to work.
4
Beginning with .NET 8, according to the Native AOT deployment documentation, on Windows you must install the following:
Visual Studio 2022, including the Desktop development with C++ workload with all default components.
If you did not do that when you installed Visual Studio 2022, follow the instructions from Modify Visual Studio workloads, components, and language packs:
-
Find and rerun the installer. If already installed, it’s likely at
C:Program Files (x86)Microsoft Visual StudioInstallersetup.exe
-
From the list of installed versions of Visual Studio, pick the version of Visual Studio 2022 you want to modify, then pick “Modify”.
-
From the “Modifying – Visual Studio 2022” dialog, pick “Workloads” and then “Desktop development with c++”. You may need to scroll down to see it:
From your question it appears you picked “.NET desktop development” which is not sufficient.
-
Finish up the installer and restart.
Once installed you should be able to publish native builds on Windows. But do note the following Platform/architecture restrictions:
Platform Supported Architecture Windows x64, Arm64
Thus you cannot publish a native x86 (32-bit) build, you can only publish a native x64 or arm64 build:
dotnet publish -r win-x64 -c Release