MATLAB: Can MATLAB Compiler SDK for .NET create a strong-named .NET assembly

dllencryptedMATLAB Builder NEnamenamednetsharedsignsignedstrongstrongly

To be able to install a .NET assembly to GAC, it needs to be signed with a strong name. I would like to know if MATLAB Compiler SDK can create strong-named .NET assemblies.

Best Answer

Strong-named .NET assemblies(https://docs.microsoft.com/en-us/dotnet/standard/assembly/strong-named) can be created with MATLAB Compiler SDK with below instructions. The MWArray.dll is already strongly named and can be registered in the Global Assembly Cache (GAC).
In order to create a strong-named assembly, you will need to provide a public-private key pair(https://docs.microsoft.com/en-us/dotnet/standard/assembly/create-public-private-key-pair). Key pair files usually have an .snk extension. To achieve this, you can use Strong Name tool (Sn.exe, https://docs.microsoft.com/en-us/dotnet/framework/tools/sn-exe-strong-name-tool) to create a public-private key pair and store it to a file by following below command line example:
sn -k sgKey.snk
After getting the snk file, If you use deploytool to create the .NET assembly, check the "Create Shared Assembly" option under "Additional runtime settings" and select the key file created above. If you use mcc to create it, specify the key file in the -W switch as follows as an example:
mcc -W 'dotnet:test,Class1,4.0,D:\sgKey.snk,version=1.0' -T link:lib -d D:\test\for_testing -v class{Class1:D:\test.m}
  The DLL thus generated must now be a signed-strongly named .Net Assembly. You can check whether the DLL is a strongly named DLL by using the sn.exe tool. Please see the “–vf” option on the following page:
https://docs.microsoft.com/en-us/dotnet/framework/tools/sn-exe-strong-name-tool At the Developer Command Prompt (or the Visual Studio Command Prompt in Windows 7) run the following command:
sn –vf <dllname.dll>