【发布时间】:2018-11-12 09:12:30
【问题描述】:
我当前的应用如下所示:
public static class Program
{
//Default code-gen unless we include DISABLE_XAML_GENERATED_MAIN in the build properties.
static void Main(string[] args)
{
IActivatedEventArgs activatedArgs = AppInstance.GetActivatedEventArgs();
if(ActivationKind.CommandLineLaunch.Equals(activatedArgs?.Kind))
{
CommandLineActivatedEventArgs cmdLineArgs = activatedArgs as CommandLineActivatedEventArgs;
CommandLineActivationOperation operation = cmdLineArgs.Operation;
string activationPath = operation.CurrentDirectoryPath;
System.Console.WriteLine("foo");
}
else
{
global::Windows.UI.Xaml.Application.Start((p) => new App());
}
}
}
我的清单:
<Application Id="App" Executable="$targetnametoken$.exe" desktop4:SupportsMultipleInstances="true">
<uap5:Extension Category="windows.appExecutionAlias" [...]
根据用户是从命令提示符还是开始菜单启动应用程序,UI 将如图所示显示。但是当用户从 cmd 启动应用程序时,不会显示 Console.WriteLine("foo") 的输出。
因此,我添加了desktop4:Subsystem="console"。这会导致控制台窗口启动,无论用户是否启动了应用程序,用户是从 startmneu 还是命令行启动应用程序。
我如何确保仅通过从命令提示符开始才能显示控制台窗口?我必须创建第二个 uwp 项目吗?
【问题讨论】: