I am having difficulty registering a C# component for COM interop using Visual Studio 2022. I thought I understood the problem, but even so, I have failed to get it working.
This is the basic problem:
- Visual Studio 2022 is a 64-Bit application
- When you build with Visual Studio 2022 it invokes the 64-Bit version of MSBuild
- The 64-Bit version of MSBuild invokes the 64-Bit version of RegAsm, which registers the component as a 64-Bit COM component
Since most COM-Based applications in the real world are 32-Bit applications, this is most likely not what you want.
Although this is clearly by design, I find it to be an unfortunate design choice and I have opened an issue in the Developer Community. If you agree with me, it might help gave the issue an up-vote.
Following the instructions on this page I thought it was going to be easy to update our projects by:
- unchecking the option "Register for COM interop"
- replacing it with a post-build-event to run the 32 bit version of RegAsm
This is the command that I have defined as a post-build-event:
"%Windir%Microsoft.NET\Framework\v4.0.30319\regasm.exe” “$(TargetPath)” /codebase
This leads to the error MSB3073, and the text "The command ... exited with code 123".
In full the output line is:
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5710,5): error MSB3073: The command ""%Windir%Microsoft.NET\Framework\v4.0.30319\regasm.exe” “C:\CS3\Output\Applications\interop\McDaMBusTimer.dll” /codebase" exited with code 123.
I have tried several variations of the command, but I haven't found a definition which works.
Does anybody know the exact command that I have to enter as a post-build-step?