What I need is to start a new process from a .dll, that resides in the /lib
folder... well, I have a Console Application project in my solution, that I want to generate desired .dll from.
When I let the output type of this particular project set as Console Application, it generates an .exe file. When I then rename that .exe file to .dll, I am able to start a new process from it. But when I change output type of that project to Class Library in Visual Studio, it delivers .dll, but I can not start a new process from that .dll anymore (see code below).
I do not want to do the rename manually and I do not want to use any post-build events/actions either. Furthermore, keeping .exe generated would be fine, unless we strictly need the users not to be able to simply double-click that .exe and let it do, what it is designed for, because the consequences could be brutal.
So, does anyone please know some nice solution to this problem? Every suggestion is warmly velcome, tips on what and how to set in Visual Studio and / or what to change in my code to do the tricks - but I can not make any significant changes to project and solution structure, still, every information welcome. Thanks.
Using Visual Studio 2012 and solution is all set to use .NET 4
So how I call the new process:
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.ErrorDialog = false;
psi.RedirectStandardError = false;
psi.RedirectStandardOutput = false;
psi.RedirectStandardInput = false;
psi.CreateNoWindow = true;
psi.FileName = @"SomeAssembly.dll";
psi.Arguments = @"";
Process process = new Process(); //only works when SomeAssembly.dll is a renamed .exe
process.StartInfo = psi;
process.Start();
EDIT: I feel the need to tell, that this specific project might in future not only be run from the application as a new process, but could be loaded in-memory and run using the EntryPoint.Invoke
method or just partially, creating some of it's Objects the same way using reflection. So yes, the .DLL assembly needs to have an EntryPoint
whereas still being a .DLL ... feel free to ask for further info, will happily provide.