msbuild 中动态生成 C# 文件的问题
我有一个源 XML 文件,用于创建 C# 文件,然后将其编译为项目的一部分。
目前我有一个 BeforeBuild 目标,它运行我的 XML 到 C# 转换器。
问题是,当运行 BeforeBuild 步骤时,旧文件似乎已由构建系统存储,因此新文件将被忽略。
我该如何解决这个问题? 看起来 Transforms 是可行的方法,但它们能做的事情很有限。
I have a source XML file that is used to create C# files that are then compiled as part of a project.
Currently I have a BeforeBuild target that runs my XML to C# converter.
The problem is that by the time the BeforeBuild step is run the old files appear to have been stored by the build system so the new files are ignored.
How can I get around this? It seems that Transforms would be the way but they are limited in what they can do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想您的“由构建系统存储”可以翻译为包含您希望编译的 .cs 文件的 ItemGroup 是在读取 msbuild 文件时生成的,而不是在执行编译目标时生成的。 您有多种选择:
请参阅 CreateItem任务<输出>
请参阅输出元素我希望这有帮助。
I guess your "stored by the build system" can be translated as the ItemGroup containing the .cs files you wish to compile is generated when the msbuild file is read, as opposed to when your compile target is executed. You have several options:
<CreateItem>
see CreateItem task<Output>
see Output elementI hope this helps.
嗯,我们这里有类似的东西。 我们使用 .tt 从 xml 文件生成 .cs。 这两个文件都是特定 csproj 的一部分。 在 csproj 上转到“属性”->“BuildEvents”会在预构建事件命令行中给出这个小片段:
不知道这对您是否有任何用处,我希望它足以作为最后的解决方法。
Well we have something similar-ish here. We gen a .cs off an xml file using a .tt. Both files are part of a specific csproj. Going properties->BuildEvents on the csproj gives this little snippet in the Pre-build event command line:
No idea if that's of any use to you, I hope it might suffice as a last chance workaround.
我认为您需要向我们展示一些您的规则/构建文件。 您应该有一个以 xml 作为依赖项的 cs 文件的规则/依赖项。
我不确定“由构建系统存储”是什么意思,
请仔细检查您的规则是否有错误/遗漏。
I think you need to show us a little of your rule/build file. You should have a rule/dependency for the cs file that has the xml as the dependency.
I am not sure what you mean by "stored by the build system"
Check your rules carefully for errors/omissions.