MSBuild timestamp issue with incremental build
I have a C# class library project that references another class library project (EdmResources references Framework). EdmResources only contains a T4 template which is always executed when the project builds, to compile and write out EDMX files for Entity Framework.
The EdmResources project always builds, regardless of whether the Framework assembly is up-to-date or needed to be built as well - this is slowing down our build process a lot. What I want is for EdmResources to only build when the Framework assembly required re-compiling.
I tried outputting the last write time of the Framework assembly as the output of EdmResources.tt, then only do the EDMX generation if the last write time on the assembly is greater than the timestamp recorded in the output file of the template.
This doesn't work though because MSBuild always updates the last write time of the Framework assembly, even if there were no changes and the code was not re-compiled.
Basically, is there a way to generate a signal file from MSBuild during the build of the Framework project that reflects the real build timestamp? IE, it only gets updated when some code is actually re-compiled. That file can then be used instead of the last write time on the Framework assembly.
Thanks!
I found a good solution. I put this code into my Framework project file at the top:
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);
AfterCompilation
</TargetsTriggeredByCompilation>
</PropertyGroup>
Then added the AfterCompilation target at the bottom of the file:
<!-- This target will be called by CoreCompile only when it runs -->
<Target Name="AfterCompilation" >
<!-- Output Timestamp File -->
<ItemGroup>
<SignalFile Include="$(OutDir)MyCompany.Framework.timestamp" />
</ItemGroup>
<PropertyGroup>
<Ticks>$([System.DateTime]::Now.Ticks)</Ticks>
</PropertyGroup>
<WriteLinesToFile File="@(SignalFile)" Lines="$(Ticks)" Overwrite="true" />
</Target>
So this means that the timestamp file will only be generated when the code compiles, if the CoreCompile target is never called then the timestamp file is not updated. I can then look at this timestamp file from my T4 template and correctly determine if I need to rebuild my EDMX files as well.
链接地址: http://www.djcxy.com/p/92430.html上一篇: 从生成服务器预处理T4模板时发生FileNotFoundException
下一篇: 具有增量构建的MSBuild时间戳问题