简体   繁体   English

将命令行 Arguments 传递到 C# .NET 应用程序而不使用 ZADD4E130E8FD245A30CDED0AB1 内的清单文件

[英]Passing in Command Line Arguments to C# .NET app Without Using Manifest File Inside a UWP App

I have a UWP app that I am developing that launches another application, which in turn launches a bat file, which does certain tasks, in order to not block the UI thread, while having enough permissions to do the tasks.我有一个正在开发的 UWP 应用程序,它启动另一个应用程序,该应用程序又启动一个 bat 文件,该文件执行某些任务,以便不阻塞 UI 线程,同时具有足够的权限来执行任务。 The EXE I'm trying to launch is a separate .NET framework app that is in the same SLN, but a different project, in an app package project.我要启动的 EXE 是一个单独的 .NET 框架应用程序,它位于同一个 SLN 中,但在一个应用程序 package 项目中是一个不同的项目。 However, the second C# app that the UWP app is launching requires command line arguments that may as often as the user of the app decides, so they can't be hard-coded into the manifest file, and using the following command:但是,UWP 应用程序正在启动的第二个 C# 应用程序需要命令行 arguments,这可能与应用程序用户的决定一样频繁,因此不能将它们硬编码到清单文件中:

await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("ArgumentGroupName");

Is there an alternative to the above command that allows for parameters to be passed in, while changing the parameter value is available at every launch?是否有上述命令的替代方法允许传入参数,而每次启动时都可以更改参数值? I've googled for days without finding any topic on this apart from one comment on an SO post that I can't find that says that it can be done without using the app's manifest file.我已经用谷歌搜索了好几天,但没有找到任何关于此的主题,除了我找不到的 SO 帖子上的一条评论说它可以在不使用应用程序清单文件的情况下完成。 I am using the latest version of Visual Studio 2019 with the latest .NET Framework (4.8) and Windows SDK (Windows 2004-compatible).我正在使用最新版本的 Visual Studio 2019 和最新的 .NET 框架 (4.8) 和 Windows SDK(与 Windows 2004 兼容)。 The second C# app runs using the .NET Framework and the main UWP app uses the Windows SDK. The second C# app runs using the .NET Framework and the main UWP app uses the Windows SDK.

Passing in Command Line Arguments to C# .NET app Without Using Manifest File Inside a UWP App将命令行 Arguments 传递到 C# .NET 应用程序而不使用 ZADD4E130E8FD245A30CDED0AB1 内的清单文件

For your requirement, you could pass the launcher parameter with LocalSettings .根据您的要求,您可以使用LocalSettings传递启动器参数。 Store the parameter in the UWP client and retrieve value from launcher, then call process start with retrieved paramete.将参数存储在 UWP 客户端并从启动器中检索值,然后调用过程以检索到的参数开始。

For example例如

UWP Client UWP 客户端

private async void btnClick_Parameters(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
    {
        // store command line parameters in local settings
        // so the Lancher can retrieve them and pass them on
        ApplicationData.Current.LocalSettings.Values["parameters"] = "command parameter";

        await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("Parameters");
    }
}

Launcher启动器

string parameters = ApplicationData.Current.LocalSettings.Values["parameters"] as string;
Process newProcess = Process.Start(rootPath + @"WPF\WPF.exe", parameters);

For more detail please refer stanfen's blog UWP with Desktop Extension – Part 2有关更多详细信息,请参阅 stanfen 的博客UWP with Desktop Extension – Part 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM