Open Symbai opened 2 years ago
Question. Are you have .NET 7 SDK installed? I have 7.0.100-rc.2.22452.3 (and previously version was working fine) and everything was working. Are you have either <PublishAot>true</PublishAot>
or <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
(not needed in .NET 7) in your project file?
My SDK is 6.0.400 and I'm building the winforms sample project, <PublishAot>true</PublishAot>
was missing, <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
not.
I've now added <PublishAot>true</PublishAot>
and published again but still no AOT.
I think this is your answer. https://github.com/dotnet/runtime/issues/61231#issuecomment-1235385283 or maybe slightly earlier for context. For now .NET 6 SDK a bit broken. You can either use specific version of ILCompiler or wait for NET 6 SDK to land fix, or install NET 7 preview
How can I use a specific version of the ILCompiler?
Try
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-preview.6.22324.4" />
With this I get: error : The ResolvedILCompilerPack ItemGroup is required for target ImportRuntimeIlcPackageTarget
NativeAOT does not support .NET 6, so I probably would limit my attempts here too. Let me know if you still need this.
Yeah it works fine with .NET 7. But it is normal that the output files are extremely huge in release mode? And that there are still many other files in the output directory?
For a console project a get a rather small app with only one executable.
native dll which is in the output dir you most likely can ignore. They are coming from WPF and that's SDK issue. Probbaly nobody bother with this yet. Minimal size of output EXE is limited to the fact that WinForms is using reflection a lot, Control is very fat class. Not sure what can be done to this, but this is mostly related to WinForms code.
Yeah I was talking about all of these:
clrjit.dll
D3DCompiler_47_cor3.dll
mscordbi.dll
vcruntime140_cor3.dll
and so on. There are 21 additional files with a total size of 21mb.
Not quite clear why do you have 21 additional files. If they are from your external libs, probably you need them. For me, tipical WinForms App + NativeAOT uses only
Other files, I never seen them. I assume we did not count PDB files, they are not required obviously.
I dont count PDB file. It is a simple "hello world" Winforms app with no other external lib / dependency than WinFormsComInterop. Deleting all code reduces it to 17 additiona files.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAot>true</PublishAot>
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WinFormsComInterop" Version="0.3.2" />
</ItemGroup>
</Project>
Project file: WinFormsNativeAOTTest.zip
//edit: I just moved only the executable into a new folder and it runs. So maybe all of the additional files can be deleted. I however havent tried running the executable on a system without any SDK / runtime / VC++ redis installed.
What command do you use for publish? dotnet publish
. Also I belive PlatformTarget
is redundant.
Can you run just dotnet publish
without additional switched, and open bin\Debug\net7.0-windows\win-x64\publish\
folder?
Doesn't matter, I published through VS but using dotnet publish without any additional parameter generates the same output:
\bin\Debug\net7.0-windows\win-x64\publish:
//edit: and yes I've cleaned the output folder before publishing.
.NET SDK:
Version: 7.0.100
Commit: E12B7AF219
Running time environment:
OS name: Windows
OS version: 10.0.22621
OS Platform: Windows
RID: Win10-X64
Base Path: C: \ Program Files \ Dotnet \ SDK \ 7.0.100 \
Host:
Version: 7.0.0
Architecture: X64
Commit: D099F075E4
.NET SDKS installed:
6.0.100-preview.5.21302.13 [C: \ Program Files \ Dotnet \ SDK]
6.0.112 [C: \ Program Files \ Dotnet \ SDK]
7.0.100 [C: \ Program Files \ Dotnet \ SDK]
do you have <PublishAot>true</PublishAot>
inside your csproj?
I've attached the project file above, yes I have.
C:\Users\User\Downloads\WinFormsNativeAOTTest
dotnet publish
If you have something else, you some issues in your setup. Maybe you have some Directory.Build.props above which annulls PublishAot or something else. Files which you are show indicates that you publish as regular self-contained app, not as NativeAOT application
hey bro. i can build winform native oat but i click button and it notifi errors See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
** Exception Text ** System.NullReferenceException: Object reference not set to an instance of an object. at getcpu.Form1.checkactive() + 0x19d at System.Windows.Forms.Button.OnClick(EventArgs) + 0xcf at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs) + 0xb1 at System.Windows.Forms.Control.WmMouseUp(Message&, MouseButtons, Int32) + 0x268 at System.Windows.Forms.Control.WndProc(Message&) + 0x670 at System.Windows.Forms.ButtonBase.WndProc(Message&) + 0x161 at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Interop.User32.WM msg, IntPtr wparam, IntPtr lparam) + 0x70
** JIT Debugging **
@NCLnclNCL can you show what's in your Form1.checkactive
function? Can you confirm that this is name of event handler for button click?
@NCLnclNCL can you show what's in your
Form1.checkactive
function? Can you confirm that this is name of event handler for button click? hey bro, i know .net framework has .net native and it supports compiling for x86, why is it difficult to compile x86 for native aot at .net core
If I publish the sample app, I still get a managed .NET dll file with an executable host file and all the .NET runtime dll files. But when I publish a console project with AOT I get a single unmanaged executable. This is what I've expected for Winforms as well.
I used this command
dotnet publish -r win-x64
and then went to thepublish
folder.