gpt4 book ai didi

visual-studio - 在 CoreBuild 之前运行目标?

转载 作者:行者123 更新时间:2023-12-04 22:28:29 26 4
gpt4 key购买 nike

我正在向我的项目中添加一个自定义 .tt 模板生成目标,以便在 CoreBuild 之前运行,并且似乎有两种方法可以做到:

<Project...>
<Target Name="TransformOnBuild" AfterTargets="BeforeBuild">
</Project>


<Project...>
<Target Name="TransformOnBuild" BeforeTargets="CoreBuild">
</Project>

如果我的目标应该在我的项目构建之前运行,因为项目依赖于它,我使用后者会更好吗?我已经看到前者用于生成文本模板之类的事情,但这似乎是一种不可靠的方法,因为它可能会在 CoreBuild 之后运行,这为时已晚。还是有什么原因为什么 AfterTargets="BeforeBuild" 仍然可以保证在核心构建之前运行?

我还看过 BeforeTargets="BeforeBuild" ,它会更早地构建。这是放置`.tt 文本生成目标的更好地方吗?

最佳答案

基于@stjin 的回答,似乎正在使用一个很好的解决方案

BeforeTargets="CoreCompile" DependsOnTargets="PrepareForBuild"

这就是 .net sdk(用于 .net 核心/标准项目的新型 csproj) is doing for automatic AssemblyInfo.cs generation

它使用以下注释来解释原因:

Note that this must run before every invocation of CoreCompile to ensure that all compiler runs see the generated assembly info. There is at least one scenario involving Xaml where CoreCompile is invoked without other potential hooks such as Compile or CoreBuild, etc., so we hook directly on to CoreCompile. Furthermore, we must run after PrepareForBuild to ensure that the intermediate directory has been created.



请注意,“中间目录”(在本例中为 obj/[TargetFramework])是在本例中放置输出 .cs 文件的位置,这也可能是您想要执行的操作。

关于visual-studio - 在 CoreBuild 之前运行目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44043918/

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