gpt4 book ai didi

c# - 如何调用 tlbexp 命令作为构建后事件以从 Visual Studio 2019 IDE 中的 C# EXE 导出类型库?

转载 作者:行者123 更新时间:2023-12-05 02:04:26 25 4
gpt4 key购买 nike

我开发了一个定义 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)"

Post-build event settings in VS

但是,当我从 Visual Studio 2019 构建项目时,出现以下错误:

error MSB3073: The command ""tlbexp.exe C:\Path\To\MyCSharpApp.exe"" exited with code 123.

我做错了什么?我在这里缺少什么?

如何在构建后事件中自动执行 tlbexp 调用?

最佳答案

tlbexp.exe 通常不在路径中。你可以做的是改用它(不像你那样包围“”):

call "$(DevEnvDir)..\Tools\VsDevCmd.bat"
tlbexp.exe $(TargetDir)$(TargetFileName)

这将执行等同于 "Developer Command Prompt for Visual Studio "将适当设置所有路径的 shell 命令,然后运行 ​​tlbexp:

enter image description here

关于c# - 如何调用 tlbexp 命令作为构建后事件以从 Visual Studio 2019 IDE 中的 C# EXE 导出类型库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64316348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com