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

标签 c# visual-studio msbuild com typelib

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

相关文章:

c# - 有没有办法在 c# 谓词中进行这种转换

c# - MsDeploy - 无法更新应用程序池

MSBuild:它是什么?我什么时候需要它?

c# - 以高效且省时的方式构建、启动 ASP.NET Web 应用程序并运行 Microsoft CodedUI 测试

c# - 如何将文件从 .NET 应用程序上传到 Rocket.Chat-Channel?

c# - File.WriteAllText 不保留换行符

c# - Windows CE 6.0 (OEM 5.37) 不显示沙漏光标

html - Visual Studio 中 angular 在 html 中的静态类型

visual-studio - 如何在 C++ 中创建 CMYK 模式图像?

android - 如何使用 msbuild 在命令行上覆盖项目属性