Is it possible to execute a .NET dll without an exe to load it?

后端 未结 5 1471
野性不改
野性不改 2020-12-09 09:09

I\'m curious if there\'s a way to execute a static .DLL method in a new process without having to create an .EXE for it?

AFAIK, this isn\'t possible with native Win3

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 09:37

    Just start a PowerShell prompt.

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

    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 });
    

    This should get you started.

    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.

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

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

提交回复
热议问题