My requirement is when the build happens the T4 template should get executed.
Here is the code I have written in the template.
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(SolutionDir)dll\Newtonsoft.Json.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Text"#>
<#@ import namespace="Newtonsoft.Json"#>
<#@ import namespace="Newtonsoft.Json.Linq"#>
<#@ output extension=".txt" #>
<#
string serverPath = this.Host.ResolvePath("DLLs.js");
string body;
using (var stream = new FileStream(serverPath, FileMode.Open, FileAccess.Read))
{
var streamReader = new StreamReader(stream);
body = streamReader.ReadToEnd();
}
#>
<#=body#>
This runs fine but when I am trying to build it is giving an exception that it is unable to find the Newtonsoft DLL.
Here is what I did in the project file to run the template when the solution builds.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v11.0\Microsoft.TextTemplating.targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<ItemGroup>
<T4ReferencePath Include="$(VsIdePath)PublicAssemblies\" />
</ItemGroup>
The Newtonsoft.dll is in a folder called DLL in the root of solution folder.
I saw the post @ Get Visual Studio to run a T4 Template on every build and also followed the steps suggested by @MarkGr but with no luck.
I am using VS2012 . Can anybody tell me where am I going wrong?