wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Single-file deploymentBug

Open Jlim01 opened this issue 1 year ago • 3 comments

Describe the bug

I using Wpf UI - Compact Navigation template. but after i deploy single file in the visual studio , when I setup exefile, it couldn't execute. basic wpf app(without supporting WPFUI template) can execute. this is maybe bug.

(I followed that "https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=vs" this guideline for single file deployment)

To Reproduce

You should try this guideline [ https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=vs ]

and then execute your app

see Publish a single-file app(visual studio) part in the guideline

Expected behavior

publish ok, but can't execute program app on the publish folder path.

Screenshots

No response

OS version

window 11

.NET version

.net 8.0 win-x86

WPF-UI NuGet version

WPF-UI 3.0.3

Additional context

if you have issue when you publish, you can request help to chat gpt like it gave to me solution input into project's properties this <PropertyGroup> <InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces> </PropertyGroup>

Jlim01 avatar Jul 04 '24 02:07 Jlim01

I build and publish as a single file app.

You have to set a few different things for MSBuild to actually produce a single file executable. Here is a link to the most recent Workflow run with the build artifact.

syntax-tm avatar Jul 06 '24 15:07 syntax-tm

I build and publish as a single file app.

You have to set a few different things for MSBuild to actually produce a single file executable. Here is a link to the most recent Workflow run with the build artifact.

thanks your reply and I will do your solution. Actually , I resolved that problem before through try ~ catch. I debugged and found basePath became null when execute exe file not in the visual studio's ctrl+f5. nomally in the vs when execute(ctrl+f5), That path is that my program path(Dbug / Release Mode path) . but I execute exe file, basePath is null. so I just add try catch since basePath is null so can't go next logic. but Im wondering basePath is important part for starting app. but why basePath is null, is continue with logic and no problem? Im just add try ~ catch. and not set basePath, it is status just 'null' from exceute program to exit program.

private static readonly IHost _host = Host.CreateDefaultBuilder() .ConfigureAppConfiguration(c => { var basePath = Path.GetDirectoryName(AppContext.BaseDirectory) ?? throw new DirectoryNotFoundException( "Unable to find the base directory of the application." ); _ = c.SetBasePath(basePath); }) .ConfigureServices( (context, services) => { // App Host ..... }

Jlim01 avatar Jul 07 '24 00:07 Jlim01

Ctrl + F5 is start without debugging.

F5 is start debugging.

image

syntax-tm avatar Jul 07 '24 09:07 syntax-tm

The same reproduction from the latest stable version of the VS2022 community by expanding the newly created Compact Navigation template. The problem is pinpointed to a null path for _host in App.xaml.cs of the template code image Non-null object, but empty string information image Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)! or Path.GetDirectoryName(AppContext.BaseDirectory)! should be used

MNDIA avatar Nov 11 '24 22:11 MNDIA

Expect the template to be fixed soon

MNDIA avatar Nov 11 '24 23:11 MNDIA

Single file deployments cannot use the Location property (source). You can use AppContext.BaseDirectory instead.

syntax-tm avatar Nov 14 '24 23:11 syntax-tm