问题
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.
回答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()
来源:https://stackoverflow.com/questions/58416530/passing-command-line-arguments-to-wpf-core-3-0-sideloaded-application