I need a single exe-file on a windows pc executing a.Net WPF program. This file must be signed with a code authentication certificat. With this certificat the exe-file is executed on foreign windows system without system warnings or administration rights after copy deployment by user to a trusted place.
I can do this with VS2019 and.Net 4.7.2. But I want go forward to VS2022 and.Net 6.0. Below a simple sample working with VS2019. You can step over signtool, because in VS 2022 already fails the posibility to create a single exe files. Same happens with VS 2019 and.Net 5.0 already in the past, but I find some post with information that single exe-file with WPF first work in future with.Net 6.0. Now, after release of.Net 6.0 and VS2022 I try it again. More options in deployment assistent for single file are available, but nothing creates a single exe-file!
Working process in VS2019:
I test process in VS2022 with.Net 6
If I copy the whole folder to share and application run. I can delete WPF6Test.deps.json and WPF6Test.pdb, but i need 3 files (WPF6Test.dll, WPF6Test.exe, WPF6Test.runtimeconfig.json).
I go back to VS2022 and add additional pubxml file with changed profil option (deploment mode independent, create single file, activate compile ready to run). But now I get 7 files (D3DCompiler_47_cor3.dll, PenImc_cor3.dll, PresentationNative_cor3.dll, vcruntime140_cor3.dll, WPF6Test.exe, WPF6Test.pdb, wpfgfx_cor3.dll).
What do I have to do to get a single exe file? How I can sign this exe file during publishing process?
You need to set 'IncludeAllContentForSelfExtract' in the project file or if you using the CLI to build 'IncludeNativeLibrariesForSelfExtract'.
Even if you tick or set single exe if you are producing a self contained exe it will not including the native libraries.
Project File (your-project.csproj)
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
.Net CLI
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true --self-contained true
Edit your publish profile settings,
Save the profile settings and try publishing again. This should produce a single exe file.
If you select the Deployment mode as Self-Contained or independent, it will produce 7 files as you mentioned.
Hope this helps for publishing to a single file!
https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file
IncludeNativeLibrariesForSelfExtract
to true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.