Call .NET DLL methods plug-in: Difference between revisions
Claesabrandt (talk | contribs) mNo edit summary |
Claesabrandt (talk | contribs) m (→Prerequisites) |
||
Line 52: | Line 52: | ||
== Prerequisites == | == Prerequisites == | ||
The plugin will need the .NET 2.0 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin. | The plugin will need the .NET 2.0 SP1 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin. | ||
== Issues == | == Issues == |
Revision as of 17:37, 31 October 2008
Author: claesabrandt (talk, contrib) |
Description
This is a NSIS plug-in, that can call methods in your managed .NET DLL.
Place the plugin in the NSIS plugins folder. You call your .NET DLL methods by calling CLR:Call. This expects the following parameters:
- Assembly dll filename
- Namespace and classname with dot in between
- Method name
- Number of parameters
- Parameters (optional)
At the moment, the supported parameter types are string, char, int, float and boolean. Return value can be of those types too but are returned as strings to NSIS. Before calling the plug-in, call SetOutPath and copy the .NET DLL to be invoked. Note that the .NET class must be marked as public.
Sample NSIS script calling a method in a .NET DLL, which takes five parameters: string, char, int, float and boolean and returns a string:
InitPluginsDir SetOutPath $PLUGINSDIR File "SomeAssembly.dll" CLR::Call /NOUNLOAD "SomeAssembly.dll" "SomeNamespace.SomeClass" \ "SomeMethod" 5 "mystring1" "x" 10 15.8 false pop $0 MessageBox MB_OK $0 ... CLR::Destroy
Notice the /NOUNLOAD. This is nessecary if you need to call CLR::Call more than once, otherwise the installer hangs on the second call. When done with calling CLR::Call, call CLR::Destroy, for instance in .onGUIEnd.
You do not have to put quotes around the dll filename, namespace, classname and method, but if the dll filename contains spaces, you need the quotes around that. Omitting the quotes only makes the code slightly easier to read, the result is the same.
Sample NSIS script calling a .NET method that takes no parameters and returns void:
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass SomeOtherMethod 0 ... CLR::Destroy
The plug-in is fully functional but still undergoes some development and changes.
NSIS Details view
While performing operations in a .NET method, you may want to write progress messages to the Details view in NSIS. rbchasetfb has written an excellent article on how to do this, including full source code. The article is located here. Many thanks to rbchasetfb for the good team work.
Download
Version 0.5 including source is available here CLR.zip (35 KB) as-is.
Prerequisites
The plugin will need the .NET 2.0 SP1 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin.
Issues
When the installer finishes, the CLR.dll file remains in the temporary plugins directory on the target machine. The file is not locked, but somehow the plugin cannot be deleted. The next time the user reboots the machine, this file is deleted automatically. This issue is being worked on.
Version history
- 0.1 Initial release of the plugin
- 0.2 Changed to native NSIS plugin and some bugfixes
- 0.3 Bugfix: If more than one class was found in an assembly, only the first one could be loaded.
- 0.4 CLR.dll is now compiled in release mode, in order to work on systems without VS2008 installed. Various other minor bugfixes as well.
- 0.5 CLR.dll is now compiled with Visual Studio 2005 so there is no need for Visual C++ 2008 Redist.
NSIS forum thread