MATLAB: How to choose which DLLs to generate when building a remotable .NET Assembly in MATLAB Builder NE 3.0.2 (R2009b)

MATLAB Builder NE

I am using MATLAB Builder NE 3.0.2 (R2009b) to my MATLAB code into a remotable .NET Assembly. This will automatically give me four DLLs (assemblies):
1. DLL containing the interface with MATLAB datatypes
2. DLL containing the interface with Native datatypes
3. DLL containing the actual implementation with MATLAB datatypes (depends on 1)
4. DLL containing the actual implementation with Native datatypes (depends on 2).
I do not wish to use interfaces, so I would only like to get one DLL containing the actual implementation that does not depend on any other DLL or assembly (apart from standard .NET and MATLAB Component Runtime (MCR) DLLs).
Furthermore, it would be more efficient if I could choose which kind of data types I want to use. Typically I either only need MATLAB datatypes or only native data types; I never need both, so it is cumbersome to have them both generated and compiled.

Best Answer

Currently, the choice that can be made in MATLAB Builder NE 3.0.2 (R2009b) about the type of DLLs to be generated is limited to whether the generated classes are remotable, and whether the assembly is private or global.
If you only require a remotable class which does not use interfaces, refer to the following steps:
1. Use MCC or DEPLOYTOOL to compile the class as normal and disable embedding the CTF-file into the assembly. Furthermore, run a verbose build (as you will need to repeat some of the build steps later).
2. Modify the generated C#-code in such a way that it does not depend on an interface anymore. For example, in the generated myRemotableClassNative.cs change the class definition:
public class myRemotableClass : MarshalByRefObject, ImyRemotableAssemblyNative.ImyRemotableClassNative, IDisposable
to:
public class myRemotableClass : MarshalByRefObject, IDisposable
and remove the line:
using ImyRemotableAssemblyNative;
3. Recompile the assembly. Look in the verbose build log for the command which was used to compile the DLL, for example:
c:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"c:\MATLAB\work\rtest\myRemotableAssembly\src\myRemotableAssemblyNative.xml" /t:library /r:"C:\MATLAB\R2009b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /linkres:"c:\MATLAB\work\myRemotableAssembly\src\myRemotableAssembly.ctf" /r:"c:\MATLAB\work\myRemotableAssembly\src\ImyRemotableAssemblyNative.dll" /out:"c:\MATLAB\work\myRemotableAssembly\src\myRemotableAssemblyNative.dll" "c:\MATLAB\work\myRemotableAssembly\src\myRemotableClassNative.cs" "c:\MATLAB\work\myRemotableAssembly\src\dotnet_mcc_component_data.cs"
Then call this command again, without the reference to ImyRemotableAssemblyNative.dll:
!c:\WINNT\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"c:\MATLAB\work\myRemotableAssembly\src\myRemotableAssemblyNative.xml" /t:library /r:"C:\MATLAB\R2009b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /linkres:"c:\MATLAB\work\myRemotableAssembly\src\myRemotableAssembly.ctf" /out:"c:\MATLAB\work\myRemotableAssembly\src\myRemotableAssemblyNative.dll" "c:\MATLAB\work\myRemotableAssembly\src\myRemotableClassNative.cs" "c:\MATLAB\work\myRemotableAssembly\src\dotnet_mcc_component_data.cs"
(Note that DEPLOYTOOL usually copies the compiled DLL from the 'src' to the 'distrib' folder automatically)