将命令行参数传递给WPF Core 3.0侧面加载的应用程序 [英] Passing command line arguments to WPF Core 3.0 sideloaded application

查看:38
本文介绍了将命令行参数传递给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="http://schemas.microsoft.com/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侧面加载的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆