简体   繁体   中英

How to get Visual Studio to transform specific T4 Templates on build?

Is it possible to get Visual Studio to build only a specific set of T4 Templates on build?

Currently I use the solution provided here to make Visual Studio transform all of my T4 Template files upon build. However, I have a T4 Template that runs into this issue when it is transformed during build time. Therefore, I want to transform all templates except this particular one.

More specifically, I have the following code in my .csproj :

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <TransformOnBuild>true</TransformOnBuild>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
</PropertyGroup>

which "works" to rebuild most of my T4 Templates the way I want.

However, I have a T4 Template included in that .csproj that makes use of the Host variable in such a way that it causes the transformation to fail during build time (see here ).

It is necessary that all of the templates except the latter are transformed upon build, so is there any way I can achieve this behavior?

Note: This type of <PropertyGroup> is used across multiple projects in multiple solutions, so for the sake of keeping things the same across the board I would prefer to continue using this for my transformations, if at all possible.

Add a condition to the metadata item for the template you don't want to transform as follows:

<Content Include="TextTemplate2.tt" >
  <Generator Condition="$(BuildingInsideVisualStudio)=='true'">TextTemplatingFileGenerator</Generator>
  <LastGenOutput>TextTemplate2.txt</LastGenOutput>
</Content>

This will stop the Microsoft.TextTemplating.targets from recognising the file as one that needs to be transformed, except when building inside Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM