仅当修改文件时,MSBuild上的TextTransform吗? (或替代方法) [英] TextTransform on MSBuild only when file modified? (or an alternate route of doing this)

查看:92
本文介绍了仅当修改文件时,MSBuild上的TextTransform吗? (或替代方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将TextTransform与MSBuild集成在一起的项目,但是现在我的观点是文件太多,这减慢了开发时间。

I have a project that integrates TextTransform with MSBuild, but I am now at the point that the files are too many and it is slowing down development time.

我的流程是,我有一个POCO.cs;我使用Roslyn解析.cs文件以收集一些元数据。将元数据传递到.tt文件,然后将生成[Implementation] .cs

The process that I have is, I have a POCO.cs; I use Roslyn to Parse the .cs file to gather some metadata; hand the metadata to a .tt file that will then generate a [Implementation].cs

这是与我的问题相关的.csproj文件的一部分:

Here is part of the .csproj file that pertains to my question:

<PropertyGroup>
  <_CommonProgramFiles>$([System.Environment]::GetEnvironmentVariable('CommonProgramFiles(x86)'))</_CommonProgramFiles>
  <_CommonProgramFiles Condition=" '$(_CommonProgramFiles)' == '' ">$(CommonProgramFiles)</_CommonProgramFiles>
  <TextTransformPath Condition="'$(TextTransformPath)' == ''">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\TextTransform.exe</TextTransformPath>
  <!-- Initial default value -->
  <_TransformExe>$(TextTransformPath)</_TransformExe>
  <_RoslynDllPath>$(ProjectDir)Lib\RoslynWrapper.dll</_RoslynDllPath>
  <!-- Cascading probing if file not found -->
  <_TransformExe Condition="!Exists('$(_TransformExe)')">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\10.0\TextTransform.exe"</_TransformExe>
  <_TransformExe Condition="!Exists('$(_TransformExe)')">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\11.0\TextTransform.exe"</_TransformExe>
  <_TransformExe Condition="!Exists('$(_TransformExe)')">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\12.0\TextTransform.exe"</_TransformExe>
  <!-- Future proof 'til VS2013+2 -->
  <_TransformExe Condition="!Exists('$(_TransformExe)')">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\13.0\TextTransform.exe"</_TransformExe>
  <_TransformExe Condition="!Exists('$(_TransformExe)')">$(_CommonProgramFiles)\Microsoft Shared\TextTemplating\14.0\TextTransform.exe"</_TransformExe>
</PropertyGroup>

<ItemGroup>
  <Compile Include="SomePoco.cs" />
  <Compile Include="Properties\AssemblyInfo.cs" />
  <Compile Include="SomePocoMetadata.cs">
    <AutoGen>True</AutoGen>
    <DesignTime>True</DesignTime>
    <DependentUpon>SomePocoMetadata.tt</DependentUpon>
  </Compile>
</ItemGroup>
<ItemGroup>
  <None Include="SomePocoMetadata.tt">
    <Generator>TextTemplatingFileGenerator</Generator>
    <LastGenOutput>SomePocoMetadata.cs</LastGenOutput>
  </None>
</ItemGroup>

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="TransformOnBuild" AfterTargets="BeforeBuild">
  <Error Text="Failed to find TextTransform.exe tool at '$(_TransformExe)." Condition="!Exists('$(_TransformExe)')" />
  <ItemGroup>
    <_TextTransform Include="@(None)" Condition="'%(None.Generator)' == 'TextTemplatingFileGenerator'" />
  </ItemGroup>
  <!-- Perform task batching for each file -->
  <Exec Command="&quot;$(_TransformExe)&quot; &quot;%(_TextTransform.FullPath)&quot; -r &quot;$(_RoslynDllPath)&quot;" Condition="'%(_TextTransform.Identity)' != ''" />
</Target>

通过上述操作,.tt文件始终在转换,并且需要花费几分钟的时间来编译DLL。在MSBuild中,是否有一种方法可以仅在SomePoco.cs文件仅被修改时进行转换?

With the above, the .tt files are always transforming and it takes a couple of minutes to compile the DLL. Is there a way to do this in MSBuild to only transform when the SomePoco.cs file is modified only?

也许我应该研究另一种方法以获取什么?我想完成?

Is there maybe another approach that I should look into to get what i want accomplished?

推荐答案

我最终要做的是将ITaskItem []用作输入参数之一,在那里使用C#找出文件的最后修改版本,并确定是否需要生成该文件。

what i ended up doing was using with ITaskItem[] as one of the input parameters and in there i used C# to figure out the last modified of the files and determined if i needed to generate that way.

这篇关于仅当修改文件时,MSBuild上的TextTransform吗? (或替代方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆