C# 从Linux上的.NETCore2.0开始
我正在尝试启动默认的web浏览器,打开带有C# 从Linux上的.NETCore2.0开始,c#,linux,.net-core,C#,Linux,.net Core,我正在尝试启动默认的web浏览器,打开带有Process.start()的链接。我使用Process.Start(“https://www.google.com“”,但我的.NET核心应用程序因以下原因崩溃: 发生异常:CLR/System.ComponentModel.win32an异常 “System.ComponentModel.Win32Exception”类型的未处理异常 在System.Diagnostics.Process.dll中发生:“没有此类文件或 位于System.Diag
Process.start()
的链接。我使用Process.Start(“https://www.google.com“”
,但我的.NET核心应用程序因以下原因崩溃:
发生异常:CLR/System.ComponentModel.win32an异常
“System.ComponentModel.Win32Exception”类型的未处理异常
在System.Diagnostics.Process.dll中发生:“没有此类文件或
位于System.Diagnostics.Process.ResolvePath的目录(字符串
文件名)位于System.Diagnostics.Process.StartCore(ProcessStartInfo
在System.Diagnostics.Process.Start()处启动
系统.诊断.流程.启动(ProcessStartInfo-startInfo)
中的VPGameHelper.Program.Main(字符串[]args)
/home/jj/VPGameHelper/Program.cs:第30行
我想这可能就是你想要的: 最初的问题是在哪里
干杯,快乐编码 谢谢。我需要确保在xdg open中用引号括住我的url。
public static void OpenBrowser(string url)
{
try
{
Process.Start(url);
}
catch
{
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}