gpt4 book ai didi

c# - 无法从 .net 核心运行注册协议(protocol)进程,但可以从 .net 框架运行

转载 作者:行者123 更新时间:2023-12-04 08:01:32 26 4
gpt4 key购买 nike

以下代码在 .net 框架上成功启动了 Teams session ,但抛出了 System.ComponentModel.Win32Exception ( The system cannot find the file specified. ) 在 .net 核心上运行时:

using System;

namespace TryToRunMsteams
{
class Program
{
static void Main(string[] args)
{
var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
System.Diagnostics.Process.Start(msg);
}
}
}
这是为什么?两者都是同一个用户(检查 Environment.UserName )。
如何在 .net 核心中运行注册协议(protocol)进程?

最佳答案

Can't run a registered-protocol-process from .net core, but can from .net framework


主要原因是您的目标是多个平台,而不仅仅是 .NET 框架。以 .NET 框架为目标时,标准 Process.Start将如您所见。
 var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
System.Diagnostics.Process.Start(msg);
解决在 .NET Core 中启动进程的问题请参阅下面的语法。
 var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
System.Diagnostics.Process.Start("cmd", $"/C start {msg}");
您确实拥有的另一个选项(不会解决您的问题)是检查您正在运行的平台。如果需要基于平台执行特定操作,可能会很有用。 *请注意,这需要 System.Runtime.InteropServices命名空间。
 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Do something for Windows
}

关于c# - 无法从 .net 核心运行注册协议(protocol)进程,但可以从 .net 框架运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66443034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com