0

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>

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>

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

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

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

  • Hi, You cannot pass parameters to the UWP app via the command line (Even WPF application). You might consider using a URI scheme instead of a command line scheme, this is the [documentation](https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-uri-activation) – Richard Zhang Oct 17 '19 at 01:55
  • Where are you calling `Windows.ApplicationModel.AppInstance.GetActivatedEventArgs()`? Are you running inside the container when it's `null`? – mm8 Oct 17 '19 at 11:50
  • I'm calling it at the beginning of the OnStartup method in App.xaml.cs file. – Jiří Batulka Oct 18 '19 at 12:33
  • @JiříBatulka: And how do you confirm that it is `null`? – mm8 Oct 18 '19 at 13:23
  • @mm8 A simple MessageBox after if (args == null) statement. – Jiří Batulka Oct 18 '19 at 14:24
  • @JiříBatulka Hi, is the answer from mm8 is helpful? if so, please mark it as an answer, thank you – Richard Zhang Oct 21 '19 at 07:12
  • @Richard Zhang - MSFT Hi, I had to switch my priority somewhere else, I'll do it as soon as I'll try the solution. – Jiří Batulka Oct 21 '19 at 13:20

1 Answers1

1

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

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

Add it to the IgnorableNamespaces:

IgnorableNamespaces="uap uap5 rescap desktop4">

And add this to AppExecutionAlias:

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

Then it's possible to access arguments even from Environment.GetCommandLineArgs()