This library automatically locates and uses the RegAsm.exe utility and will register a .Net class library, passing the /tlb:
command, to generate a COM visible library.
Example Usage:
public static void Main(string[] args)
{
Config config = ConfigJsonReader.ReadConfiguration(@".\config.json");
RegAsmLocation regAsmLocation = RegAsmLocation.MakeDefaultRegAsmLocation();
DllInstaller installer = new DllInstaller();
installer.Install(config, regAsmLocation);
}
See the Json Config File Example to manually write your configuration or save your configuration in Json format using ConfigJsonWriter
:
ConfigData configData = new ConfigData(
libraryOrigin: @"C:\Users\PC\MyLibrary.dll",
libraryDestination: @"C:\Windows\SysWOW64\MyLibrary.dll",
outputFileName: @"MyLibraryForComVisibility.dll");
ConfigJsonWriter.WriteConfiguration("installconfig.json", configData);
You may also read in the ConfigData
object form your created Json file using the ConfigJsonReader
.
ConfigData configData = ConfigJsonReader.ReadConfiguration("installconfig.json");
Be sure to decorate your class library with the proper ComVisible(true)
attributes:
namespace RiderLibraryTest
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Class1
{
public Excel.Workbook ExcelWorkbook;
public Class1()
{
}
[ComVisible(true)]
public void Init(Excel.Workbook workbook)
{
ExcelWorkbook = workbook;
}
~Class1()
{
Marshal.ReleaseComObject(ExcelWorkbook);
ExcelWorkbook = null;
}
}
}