I have a C# project that I'd like to use as a .NET Standard 2.0 library for other .NET assemblies and as a COM component for native code. I could create the COM object just fine when I targeted the full .NET Framework, but when I created a new project targeting .NET Standard, I got this error when I tried register it:
regasm /codebase /tlb MyLib.dll
RegAsm : error RA0000 : Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
How can I build and register a DLL that is compatible with both .NET Standard and COM?
Ensure that .NET 4.7.1 is installed. Even then, since Visual Studio doesn't copy NuGet packages to the output directory, expect to get a similar "Could not load file or assembly" error for one of those.
If you can live with a single project but two DLLs, this is an alternative: In your .csproj, remove the TargetFramework
line and replace it with multiple targets, according to what your code needs, for example:
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
Then use the net461 DLL for use by COM and the netstandard2.0 for use by .NET.