如何将命令行参数传递给 AppDomain.ExecuteAssembly?
我正在尝试使用 AppDomain.ExecuteAssembly() 运行程序集(.NET 3.5、Windows 窗体应用程序)。
我需要这样做的原因是我可以更改应用程序基目录和探测路径(即探测/依赖路径是应用程序的父文件夹,因此 app.config 不会据我所知)
但是,我似乎无法传递命令行参数。
我正在尝试执行这样的方法:
myAppDomain.ExecuteAssembly("c:\folder\application\application.exe", Nothing,
New String() { "argument 1", "argument 2", "argument 3" })
但是,我的应用程序没有收到参数。
我做错了什么?
I'm trying to run an assembly (.NET 3.5, Windows Form application) using AppDomain.ExecuteAssembly()
.
The reason I need to do this is so that I can change the application base directory and probing paths (ie. the probing/dependency path is the parent folder of the application so an app.config won't work to my knowledge)
However, I can't seem to pass command-line arguments.
I'm trying to execute the method like this:
myAppDomain.ExecuteAssembly("c:\folder\application\application.exe", Nothing,
New String() { "argument 1", "argument 2", "argument 3" })
However, my application does NOT receive the arguments.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要解析传递给 static void Main(string[] args) 函数的命令行参数,而不是使用 Environment.GetCommandLineArgs()
You will need to parse the command-line arguments that are passed to the static void Main(string[] args) function instead of using Environment.GetCommandLineArgs()
这是一个小型 a .NET 3.5 解决方案,其中包含两个可执行文件,它们完全符合您想要成功执行的操作,并且有用。我不知道我和你做的有什么不同。
Here is a small a .NET 3.5 solution with two executables that does exactly what you are trying to do successfully and it works. I don't know what I did different than you.