问题描述
我开发了一个定义COM UDT(用户定义类型)的C#.EXE:
[ComVisible(true)]
[StructLayout(LayoutKind.Sequential)]
[Guid(" ... some GUID ... ")]
public struct MyStructure
{
... varIoUs fields ...
}
我需要从此C#.EXE创建类型库。 我可以使用Visual Studio命令提示符来做到这一点:
> tlbexp.exe MyCSharpApp.exe
此命令产生MyCSharpApp.tlb
文件。
我想使用Visual Studio 2019 自动化这一步。
因此,我在构建后事件中输入了以下行:
"tlbexp.exe $(TargetDir)$(TargetFileName)"
但是,当我从Visual Studio 2019构建项目时,出现以下错误:
error MSB3073: The command ""tlbexp.exe C:\Path\To\MyCSharpApp.exe"" exited with code 123.
我在做什么错?我在这里想念什么?
解决方法
tlbexp.exe通常不在路径中。您可以做的就是改用它(不像以前那样用“”括起来):
call "$(DevEnvDir)..\Tools\VsDevCmd.bat"
tlbexp.exe $(TargetDir)$(TargetFileName)
这将执行与"Developer Command Prompt for VS 2019“ shell命令等效的命令,该命令将适当地设置所有路径,然后运行tlbexp: