2

I am writing an add-in for a software (namely Autodesk Robot).

The software's maintainers have produced a document describing the creation of an add-in, which explains the following steps:

[1. to 6. are about configuring writing and building your project.]

  1. Then File menu \ Open \ File -> open created dll file (in our example …\MyAddin\bin\Debug\MyAddin.dll)

  2. Add created tlb library to dll (right hand mouse click menu), Resource type should be named as TYPELIB:

Their illustration

  1. Change TYPELIB number onto 1 using Properties (right hand mouse click menu)
  2. Close Visual Studio and save changes to dll file
  3. Take \ copy created dll file to any computer you want to use, after locating it in target folder please register it this way: Open Command Prompt window as Admin And register it by commands: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /tlb /codebase MyAddin.dll

I am trying to automate the process of generating and embedding the .tlb file. After reading about this quite extensively, I found this question and the link to this blog post which is in the comments of the accepted answer.

I have added an .rc file to my project, created the .tlb file, put the two of them in the .\bin\Debug folder of the project, compiled the .rc to a .res and finally pointed the builder to this resource file I just created, as the answer to the question mentioned above suggested.

My .rc file content is as follows:

1 TYPELIB "RobotOrientAddIn.tlb"

When I build my project, I don't get any error message, but if I open the created dll file, there is no trace of the "TYPELIB" resource in the file's tree... and I have no idea why!

Reading MS docs didn't help much as I am not very familiar with the .NET jargon.

I am very confused about this and would appreciate if someone could help. Ultimately, I would like to do all this in post-build events so that there is no manual fiddling after building the project.

Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75
  • Are you truing to build an .rc file from a .NET project? .rc files are for C++ project only. so, you can build the tlb, but you have to add it to the .NET final binary as described in the post steps 6->8 – Simon Mourier Jul 15 '19 at 17:13
  • @SimonMourier That could explain why, thanks. Is there no way at all to do this programmatically? I like programming not doing the same thing twice! – Jacques Gaudin Jul 15 '19 at 18:05
  • Something went wrong at the "pointed the builder to this resource file" step. This just isn't useful and can only get the user of the library into trouble. Embedding the type library is useful for the kind of DLL that can be registered with regsvr32.exe. So *not* a C# library. You need regasm.exe to generate and register the type library, as shown, that's enough. Ideally it is done with an installer. All installer builder utilities can do this, usually just with point-and-click instead of programming. – Hans Passant Jul 15 '19 at 20:01
  • @HansPassant Thanks. I don't understand *why* the software needs the embedded typelib but the add-in is not recognised if it is not embedded as described in their document. I will have an installer, but for now I want to automate the build process. I thought anything accessible through the GUI was also available as a terminal command. Maybe I'm asking for too much? – Jacques Gaudin Jul 16 '19 at 08:06
  • @SimonMourier Sorry to be insistant but I found this: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ww9a897z(v=vs.100) It seems like an `rc` file can be used in a VB .net project. Am I understanding correctly? – Jacques Gaudin Jul 16 '19 at 21:24
  • I never said it couldn't. This link describes the same steps as your post. The thing is you can't do this from a Visual Studio project UI. This is all manual because Win32 resources are not .NET resources, but yes, compilers (C#, VB.NET) do support them with the command line. What you can do also is modify the msbuild file (.csproj) and add some custom steps or parameters ("Win32Resource") to it: https://learn.microsoft.com/en-us/visualstudio/msbuild/csc-task?view=vs-2015 – Simon Mourier Jul 16 '19 at 22:59

1 Answers1

1

I am also trying to automate this process to make it easy to debug Robot Add-ins and I got to:

  1. Download NirCmd and install it to your Windows folder.

  2. In Visual studio add a Post-Build event commands:

    "%Windir%\nircmd.exe" elevate "%Windir%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /tlb /codebase $(TargetFileName)
    echo 1 typelib $(TargetName).tlb > $(TargetName).rc
    nircmd.exe wait 5000
    "%ProgramFiles(x86)%\Windows Kits\10\bin\10.0.18362.0\x86\rc.exe" "$(TargetName).rc"
    nircmd.exe wait 5000
    "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" "$(SolutionPath)" -property:Win32Resource="$(TargetDir)$(TargetName).res" -property:Configuration=Debug -property:Platform="Any CPU" -property:PostBuildEvent=
    "%Windir%\nircmd.exe" elevate "%Windir%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /tlb /codebase $(TargetFileName)
    

    1st Creating the tlb file.
    2nd Create the rc file.
    3rd Waiting 5 second unitle the tlb file created (increase if needed).
    4th Compiling the rc file into Win32 Resource File(.res).
    5th (optional) Waiting 5 second just to be sure every thing done before the final build.
    6th Rebuilding using the res file.
    7th Registering the final dll file with embedded tlb.
    .

Very Important: Check the paths for regasm.exe, rc.exe and MSBuild.exe file and modify it if needed.

Then after you need only to build your dll as usual and it will be ready to be accepted by Autodesk Robot Add-Ins Manager.

This worked on VS2019 and Autodesk Robot 2020.

Good Luck

  • Interesting, I need to try that. To be honest, I gave up on add-ins. I now use a Python shell to manipulate Robot with custom high-level functions. – Jacques Gaudin Dec 21 '20 at 22:09