反映已编译的程序集并生成文件作为 MSBuild 过程的一部分

Reflect compiled assembly and generate a file as part of the MSBuild process

我希望生成一个 .targets 文件,我可以将其捆绑在 nuget 包中,当构建引用项目时,该文件反映编译的程序集并在 bin 文件夹中生成一个文件作为构建的一部分过程。

这能做到吗?如果是,怎么做?

您可以添加 install.ps1 to your nuget package, that modifies the csproj file to add a post build event 而不是生成 .targets 文件。从那里你可以执行任何捆绑的 powershell 脚本,或基本的 shell 命令。