将命令行参数传递给WPF Core 3.0侧面加载的应用程序

编程入门 行业动态 更新时间:2024-10-27 09:35:50
本文介绍了将命令行参数传递给WPF Core 3.0侧面加载的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个在Core 3.0上运行的WPF应用程序.我通过Windows应用程序打包项目发布了它.因为它是WPF应用程序,所以我需要将其添加到appxmanifest中:

I have a WPF app that runs on Core 3.0. I published it via Windows Application Packaging Project. Because it's WPF app, I needed to add this to appxmanifest:

<Extensions> <uap5:Extension Category="windows.appExecutionAlias" Executable="MyApp.exe" EntryPoint="MyApp"> <uap5:AppExecutionAlias> <uap5:ExecutionAlias Alias="MyApp.exe" /> </uap5:AppExecutionAlias> </uap5:Extension> </Extensions>

然后,我以侧面加载的形式发布了WPF应用程序,当我从Windows开始"菜单启动它时,它的运行情况还不错.问题是我需要从命令行启动它,并且需要传递几个命令行参数.但是,当我通过输入别名从命令行启动应用程序时,它仅传递以下参数:-ServerName:App.App7adfdfg54shnsdfh87asrgsdfg1.mca这不是我的论点-我的论点根本没有通过.因此,我尝试将其添加到我的WPF .csproj文件中:

Then I published the WPF app as sideloaded and it works just fine when I start it from the Windows Start menu. The problem is that I need to start it from command line and I need to pass few command line arguments. But, when I start the app from command line by typing the alias, it only passes this argument: -ServerName:App.App7adfdfg54shnsdfh87asrgsdfg1.mca which is not my argument - mine arguments are not passed at all. So then I tried to add this to my WPF .csproj file:

<Reference Include="Windows.Foundation.UniversalApiContract"> <HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath> <IsWinMDFile>true</IsWinMDFile> </Reference>

所以我可以在WPF App.xaml.cs文件中调用它:

so I could call this in my WPF App.xaml.cs file:

using test = Windows.ApplicationModel.AppInstance; ... Windows.ApplicationModel.Activation.IActivatedEventArgs args = test.GetActivatedEventArgs();

但是这样做之后,args为空.有什么想法如何解决这个问题并将参数实际传递给我的WPF应用程序吗?谢谢.

But after doing this, args are null. Any ideas how to solve this and actually pass arguments to my WPF app? Thanks.

推荐答案

我在.appxmanifestlines文件中缺少几行.添加参考:

I was missing few lines in the .appxmanifestlines file. Add he reference:

xmlns:uap5="schemas.microsoft/appx/manifest/uap/windows10/5"

将其添加到IgnorableNamespaces:

Add it to the IgnorableNamespaces:

IgnorableNamespaces="uap uap5 rescap desktop4">

并将其添加到AppExecutionAlias:

And add this to AppExecutionAlias:

<uap5:AppExecutionAlias desktop4:Subsystem="console"> <uap5:ExecutionAlias Alias="DeploymentScripts.UI.exe" /> </uap5:AppExecutionAlias>

然后甚至可以从 Environment.GetCommandLineArgs()

更多推荐

将命令行参数传递给WPF Core 3.0侧面加载的应用程序

本文发布于:2023-11-16 07:47:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602360.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   侧面   应用程序   加载   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!