Search code examples
c#visual-studio-codeclass-librarycscregasm

VS Code - How can I produce a strongly named assembly?


I have a class library I use for an assembly. It is comprised of three classes - classes A and B provide supporting types and methods for class C. After an assembly is built from that library, I need to register it with the GAC; currently I use regasm for this:

  1. Build project in VS Code
  2. Create DLL files from C# source code using csc...I sign each one here with a keyfile
  • Class A first
  • Class B, which depends on Class A
  • Class C, which depends on both classes A and B
  1. Use regasm to register the primary assembly(class C)

My issue is that csc only supports C# versions up to 5. I am using the latest version of csc I could find - it was contained inside a Visual Studio folder under Program Files(I don't have a full install of Visual Studio, just some utilities). Using third-party software(dotPeek), I noticed that the assembly csc had created was targeting .NET 3.5; I target 5.0 in my project. It also only had references to class C that I could see, despite A and B being dependencies.

Out of curiosity, I looked at the build output from VS Code, and saw a DLL file for my project. In dotPeek, it correctly targeted .NET 5.0 and had clear references to classes A, B, and C. The only issue is that it is not strongly named.

Is the DLL from my build output the correct one to use? If so, how can I strongly name it?

I use VS Code due to limited resources in my server environment. If I need to use Visual Studio, it is preferable that I could do so on a different machine and port the finished assembly over.


Solution

  • After further research, this appears to be a dead end. Any DLL generated by VS Code targeting .NET >= 5.0 can not be used with regasm. I need to use regasm to create an assembly for my COM objects, so I have to target a lower version.

    "Unlike in .NET Framework, there is no support in .NET Core or .NET 5+ for generating a COM Type Library (TLB) from a .NET assembly. The guidance is to either manually write an IDL file or a C/C++ header for the native declarations of the COM interfaces. If you decide to write an IDL file, you can compile it with the Visual C++ SDK's MIDL compiler to produce a TLB."

    -from https://learn.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com#embedding-type-libraries-in-the-com-host