如何在启动时运行 Windows App SDK 打包的 C# 应用程序?

huangapple go评论65阅读模式
英文:

How to run Windows App SDK packaged C# app at startup?

问题

我想要让我的打包的C#应用在登录时启动。在这篇帖子的指导下,我配置了Package.appxmanifest并将相关的代码添加到我的应用程序。然而,当用户登录时,启动画面出现,但应用程序无法启动。

帖子提到了一点:

如果您的应用启用了启动激活,您应该通过覆盖OnActivated方法在您的App类中处理这种情况。

然而,WASDK应用程序没有"OnActivated"方法。我猜问题出在这里,我想知道如何正确配置我的代码来解决这个问题。

感谢任何帮助。

英文:

I want to run my packaged c# app to start at log-in. Under the guidance of this post, I configured Package.appxmanifest and added relevant code to my app. However, when users log in, the splash screen appears but then the application fails to launch.

The post mentions one thing:

> If your app is enabled for startup activation, you should handle this
> case in your App class by overriding the OnActivated method.

However, WASDK app doesn't have an OnActivated method. I guess the problem lies here and I wonder how to correctly configure my code to fix this issue.

Appreciate any help.

答案1

得分: 1

已解决。
根据此博客,我们应该以以下形式编写package.appxmanifest

<Extensions>
	<uap5:Extension
	Category="windows.startupTask"
	Executable="SingleInstancedError.exe"
	EntryPoint="SingleInstancedError.App">
		<uap5:StartupTask
		TaskId="SingleInstancedErrorId"
		Enabled="false"
		DisplayName="SingleInstancedError startup" />
	</uap5:Extension>
</Extensions>

但是,为了使其适用于Windows App SDK,必须删除这两行:

Executable="SingleInstancedError.exe"
EntryPoint="SingleInstancedError.App"

这样清单看起来像这样:

<Extensions>
	<uap5:Extension
	Category="windows.startupTask">
		<uap5:StartupTask
		TaskId="SingleInstancedErrorId"
		Enabled="false"
		DisplayName="SingleInstancedError startup" />
	</uap5:Extension>
</Extensions>

然后应用程序会在启动时正常运行。

英文:

Resolved.
According to this blog, we are supposed to write package.appxmanifest in this form:

&lt;Extensions&gt;
	&lt;uap5:Extension
	Category=&quot;windows.startupTask&quot;
	Executable=&quot;SingleInstancedError.exe&quot;
	EntryPoint=&quot;SingleInstancedError.App&quot;&gt;
		&lt;uap5:StartupTask
		TaskId=&quot;SingleInstancedErrorId&quot;
		Enabled=&quot;false&quot;
		DisplayName=&quot;SingleInstancedError startup&quot; /&gt;
	&lt;/uap5:Extension&gt;
&lt;/Extensions&gt;

However, to make it work for Windows App SDK, these two lines must be removed:

Executable=&quot;SingleInstancedError.exe&quot;
EntryPoint=&quot;SingleInstancedError.App&quot;

So that the manifest looks like this:

&lt;Extensions&gt;
	&lt;uap5:Extension
	Category=&quot;windows.startupTask&quot;&gt;
		&lt;uap5:StartupTask
		TaskId=&quot;SingleInstancedErrorId&quot;
		Enabled=&quot;false&quot;
		DisplayName=&quot;SingleInstancedError startup&quot; /&gt;
	&lt;/uap5:Extension&gt;
&lt;/Extensions&gt;

And the app runs normally at startup.

huangapple
  • 本文由 发表于 2023年3月4日 01:18:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定