有谁知道一种方法,或者是否有可能让一个自包含的单文件 dotnet core 3.1 控制台应用程序自行重启?我之前使用下面的代码在其他控制台应用程序中完成了此操作并且它有效,但是它不适用于我的单文件应用程序。
相反,我得到以下异常
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
我怀疑这是由于运行时包含在目录中而窗口不知道使用它。如果我将应用程序发布为非单个文件应用程序,则使用 exe 重新启动就可以正常工作。但是我更喜欢使用自包含的单个文件,因为它使人们更容易传输单个 exe。
ProcessStartInfo info = new ProcessStartInfo
{
FileName = Environment.GetCommandLineArgs()[0],
UserName = creds.UserName,
PasswordInClearText = creds.Password,
Domain = "mydomain",
Verb = "runas"
};
// Start the process
Process.Start(info);
// Exit the current one
Environment.Exit(0);
我已经查看了 Application.Restart 方法,但是我需要使用 runas 动词,因为我的应用程序正在处理 kerberos 令牌并且必须在用户的上下文中运行并传递它提示用户。
对此的任何帮助将不胜感激,我已经为此旋转轮胎大约一天了。我发现了很多关于如何创建单个文件应用程序的文章,但没有找到如何让一个文件自行重新启动它的文章。