且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有可能执行一个.NET的DLL没有一个exe加载它?

更新时间:2023-01-06 21:25:18

刚开始PowerShell提示符。

Just start a PowerShell prompt.

  [Reflection.Assembly]::LoadFile("Name of your dll")
  [Your.NameSpace.And.TypeName]::YourMethod()

我看到你想要这从C#

I see you want this from C#

使用大会限定的名称创建类型:

Create the Type using the Assembly Qualified name:

 var t = Type.GetType("NameSpace.Type,Name Of Dll");
 var m = t.GetMethod("NameOfMethod");
 m.Invoke(null, new object[] { params });

这应该让你开始。

我并不确切地知道你的意思在一个新的进程,但它不应该是很难换到一个.EXE /的.ps1,您可以用命令行上的一些选项启动此。

I don't exactly know what you mean by "In a new process", but it should not be to difficult to wrap this into a .exe/.ps1 that you can start with some option on the commandline.

所以,你没有创造您想要调用DLL的每一个新的.exe文件。

So you do not have to create a new .exe for every DLL you want to invoke.

但是,如果你想开始一个新的进程,你应该开始一个新的进程,这通常通过启动一个新的.exe文件完成的。

But if you want to start a new process, you should start a new process, this is typically done by starting a new .EXE.