Deploy with VS2022 single exe-File for .Net 6 WPF-Application not works
Asked Answered
R

2

11

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 create WPF-App (.Net Framework) WPF4Test using .Net Framework 4.7.2
  • I put code sign command ("C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\signtool.exe" sign /a /n "my company name" /t http://timestamp.comodoca.com/authenticode $(TargetPath)) in postbuild step
  • I build release and enter password of certificate during sign process
  • bin\Release folder contains 3 files (WPF4Test.exe, WPF4Test.exe.config, WPF4Test.pdb)
  • I copy WPF4Test.exe to share folder and application is executable and signed

I test process in VS2022 with .Net 6

  • I create WPF-Application WPF6Test using .Net 6.0
  • I deploy Application in a folder (in assistant i must select folder twice) (default set configuration Release and destination runtime portable)
  • pubxml is created and i publish application
  • deployment folder contains 5 files (WPF6Test.deps.json, WPF6Test.dll, WPF6Test.exe, WPF6Test.pdb, WPF6Test.runtimeconfig.json)
  • I copy WPF6Test.exe to share folder, but application not start without error message

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?

Rafflesia answered 12/11, 2021 at 9:27 Comment(1)
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.Avant
G
18

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
Gather answered 23/2, 2022 at 15:37 Comment(0)
T
2

Edit your publish profile settings,

  • Select Deployment mode as Framework-dependent
  • Select the target runtime to something other than Portable (Produce single file is not available for Portable)
  • Under File Publish options, select Produce single file

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!

Tilden answered 13/1, 2022 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.