Reputation: 2293
I am trying to generate code on every build of my project using VS2012.
I have 3 projects in my solution :
When I am clicking on Build/Transform All T4 Templates, there is no problem, the generation goes well.
But I am trying to configure my build to include this step automatically on every build.
I have added this code to my csproj :
<Import Project="$MsBuildToolsPath)\Microsoft.CSharp.Targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<OverWriteReadOnlyOutputFiles>true</OverWriteReadOnlyOutputFiles>
</PropertyGroup>
<Import Project="$(MSBuildExtensionPath32)\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets"/>
I have made up myself the path "\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets" from what I found on my pc. The example I took it from was :get-visual-studio-to-run-a-t4-template-on-every-build
The problem comes from this line I am using : <#@ include file="$(SolutionDir)\xxx\yyy\zzz\mytemplate.tt">
and I receive the error :
Failed to resolve include text for file : D:\Projects\pppp\qqq\eeee\$(SolutionDir)\xxx\yyy\zzz\mytemplate.tt
As the template works well when it is generated "by hand" (Build/Transform All T4 Templates), I wonder what might be the problem for generating it at build time.
Any idea?
Upvotes: 5
Views: 4215
Reputation: 3026
The problem is that when you are running your template during the build process it is being executed under different host and $(SolutionDir) macro does not exist. Try using relative path instead e.g.
<#@ include file="..\xxx\yyy\zzz\mytemplate.tt">
Upvotes: 2