Note that there are some explanatory texts on larger screens.

plurals
  1. POT4 template will not transform with build
    primarykey
    data
    text
    <p>I'm using VisualStudio Ultimate 2012 (Update 1) on Windows 7. I can get my T4 template to generate a file by: <em>right click [tt file] | run Custom tool</em>. That works great! (yay for me). It also works if I run the menu command: <em>Build | Transform All T4 Templates</em>. But I want automation! I run into a problem when I try to get the generated code file to be produced with every build -- which is my goal.<br> I looked at this: <a href="https://stackoverflow.com/questions/1293320/t4-transformation-and-build-order-in-visual-studio">T4 transformation and build order in Visual Studio</a></p> <p>this isn't what I want. It discusses using a pre-build build event. I wanted it to be part of the build.</p> <p>and this: <a href="https://stackoverflow.com/questions/3427079/is-there-a-way-to-get-visual-studio-to-run-transform-all-templates-upon-a-succ">Is there a way to get Visual Studio to run “Transform All Templates” upon a successful build?</a></p> <p>this isn't what I wanted either. It discusses using a post-build event.</p> <p>then I found this: <a href="http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/" rel="nofollow noreferrer">Understanding T4: MSBuild Integration</a></p> <p>from <a href="http://www.olegsych.com/" rel="nofollow noreferrer">Oleg Sych's blog</a>:</p> <p>Perfect! This is what I want. Although his blog discusses VS2010, I have adopted it to VS2012 where applicable.</p> <p>I walked through each of his steps for implementing this. I installed <a href="http://www.microsoft.com/en-us/download/details.aspx?id=30668" rel="nofollow noreferrer">Visual Studio SDK 2012</a> &amp; <a href="http://www.microsoft.com/en-us/download/details.aspx?id=30680" rel="nofollow noreferrer">Visual Studio Visualization and Modeling SDK (2012)</a></p> <p>I started with using the Tangible T4 plug in, but thinking there was a problem with that, I used Oleg's T4 Toolbox Beta. Sadly, with either I seemed to get the same results: an error with a build.</p> <p>I followed his instruction on his site and reread all the steps and parts. I have been researching for days, and now my first post here. I am stuck. Thanks for looking...</p> <p>To recap: I get an error when I build in visual studio 2012 or when I run the msbuild from the command-line (but again not when I <em>run Custom Tool</em> or use the manual <em>Transform All T4 Templates</em> - Both of those work fine).</p> <p>Here is my t4template called <code>s_code.tt</code>:</p> <pre><code>&lt;#@ template debug="true" hostSpecific="true" language="C#" #&gt; &lt;#@ output extension=".js" #&gt; &lt;#@ assembly name="System.Core" #&gt; &lt;#@ assembly name="System.Xml" #&gt; &lt;#@ assembly name="EnvDTE" #&gt; &lt;#@ assembly name="EnvDTE80" #&gt; &lt;#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #&gt; &lt;#@ import namespace="System.Diagnostics" #&gt; &lt;#@ import namespace="System" #&gt; &lt;#@ import namespace="System.Text" #&gt; &lt;#@ import namespace="System.IO" #&gt; &lt;#@ import namespace="EnvDTE" #&gt; &lt;#@ import namespace="EnvDTE80" #&gt; &lt;#@ import namespace="Microsoft.VisualStudio.TextTemplating" #&gt; &lt;#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #&gt; &lt;# IServiceProvider serviceProvider = (IServiceProvider)Host; EnvDTE.DTE dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE)); var configName = dte.Solution.SolutionBuild.ActiveConfiguration.Name; string filename = this.Host.ResolvePath("s_code_source.txt"); string[] lines = File.ReadAllLines(filename); bool isAccountFound = false; int linecount = lines.Length; int currentline = 0; for (int i=0;i&lt;linecount;i++) { if (Contains_S_Account(lines[i])) { if (configName.ToUpper() == "DEBUG") { WriteLine("var s_account = \"macudev2\""); } else if (configName.ToUpper() == "RELEASE") { WriteLine("var s_account = \"macudev\""); } currentline = i; isAccountFound = true; } else { WriteLine(lines[i]); } } for (int i=currentline;i&lt;linecount;i++) { WriteLine(lines[i]); } #&gt; &lt;#+ private bool Contains_S_Account(string line) { if (line.ToLower().Contains("var s_account")) { return true; } else { return false; } } #&gt; </code></pre> <p>Here is my <code>.csproj</code> file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; &lt;Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /&gt; &lt;PropertyGroup&gt; &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt; &lt;Platform Condition=" '$(Platform)' == '' "&gt;AnyCPU&lt;/Platform&gt; &lt;ProductVersion&gt; &lt;/ProductVersion&gt; &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt; &lt;ProjectGuid&gt;{0A44E136-F4A4-4B31-95DD-2C8A79FDFAF4}&lt;/ProjectGuid&gt; &lt;ProjectTypeGuids&gt;{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}&lt;/ProjectTypeGuids&gt; &lt;OutputType&gt;Library&lt;/OutputType&gt; &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt; &lt;RootNamespace&gt;Macu.Content&lt;/RootNamespace&gt; &lt;AssemblyName&gt;Macu.Content&lt;/AssemblyName&gt; &lt;TargetFrameworkVersion&gt;v4.0&lt;/TargetFrameworkVersion&gt; &lt;UseIISExpress&gt;true&lt;/UseIISExpress&gt; &lt;IISExpressSSLPort /&gt; &lt;IISExpressAnonymousAuthentication /&gt; &lt;IISExpressWindowsAuthentication /&gt; &lt;IISExpressUseClassicPipelineMode /&gt; &lt;TargetFrameworkProfile /&gt; &lt;TransformOnBuild&gt;True&lt;/TransformOnBuild&gt; &lt;IncludeFolders&gt;$(MSBuildProjectDirectory)\Include&lt;/IncludeFolders&gt; &lt;/PropertyGroup&gt; &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "&gt; &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt; &lt;DebugType&gt;full&lt;/DebugType&gt; &lt;Optimize&gt;false&lt;/Optimize&gt; &lt;OutputPath&gt;bin\&lt;/OutputPath&gt; &lt;DefineConstants&gt;DEBUG;TRACE&lt;/DefineConstants&gt; &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt; &lt;WarningLevel&gt;4&lt;/WarningLevel&gt; &lt;/PropertyGroup&gt; &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "&gt; &lt;DebugType&gt;pdbonly&lt;/DebugType&gt; &lt;Optimize&gt;true&lt;/Optimize&gt; &lt;OutputPath&gt;bin\&lt;/OutputPath&gt; &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt; &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt; &lt;WarningLevel&gt;4&lt;/WarningLevel&gt; &lt;/PropertyGroup&gt; &lt;ItemGroup&gt; &lt;Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"&gt; &lt;EmbedInteropTypes&gt;True&lt;/EmbedInteropTypes&gt; &lt;/Reference&gt; &lt;Reference Include="envdte80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"&gt; &lt;EmbedInteropTypes&gt;True&lt;/EmbedInteropTypes&gt; &lt;/Reference&gt; &lt;Reference Include="Microsoft.CSharp" /&gt; &lt;Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"&gt; &lt;EmbedInteropTypes&gt;True&lt;/EmbedInteropTypes&gt; &lt;/Reference&gt; &lt;Reference Include="Microsoft.VisualStudio.TextTemplating.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /&gt; &lt;Reference Include="System" /&gt; &lt;Reference Include="System.Xml" /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;Content Include="shared\script\s_code.js"&gt; &lt;AutoGen&gt;True&lt;/AutoGen&gt; &lt;DesignTime&gt;True&lt;/DesignTime&gt; &lt;DependentUpon&gt;s_code.tt&lt;/DependentUpon&gt; &lt;/Content&gt; &lt;Content Include="shared\script\s_code_source.txt" /&gt; &lt;Content Include="Web.config" /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;Compile Include="Properties\AssemblyInfo.cs" /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;Content Include="shared\script\s_code.tt"&gt; &lt;Generator&gt;TextTemplatingFileGenerator&lt;/Generator&gt; &lt;LastGenOutput&gt;s_code.js&lt;/LastGenOutput&gt; &lt;Parameters&gt; &amp;lt;%3fxml version="1.0" encoding="utf-16"%3f&amp;gt; &amp;lt;ArrayOfParameterStorage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&amp;gt; &lt;/Parameters&gt; &lt;/Content&gt; &lt;None Include="Properties\PublishProfiles\Local.pubxml" /&gt; &lt;None Include="Web.Debug.config"&gt; &lt;DependentUpon&gt;Web.config&lt;/DependentUpon&gt; &lt;/None&gt; &lt;None Include="Web.Release.config"&gt; &lt;DependentUpon&gt;Web.config&lt;/DependentUpon&gt; &lt;/None&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;T4ReferencePath Include="$(VsInstallDir)PublicAssemblies\" /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;Folder Include="shared\images\" /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup /&gt; &lt;ItemGroup&gt; &lt;Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /&gt; &lt;/ItemGroup&gt; &lt;PropertyGroup&gt; &lt;VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''"&gt;10.0&lt;/VisualStudioVersion&gt; &lt;VSToolsPath Condition="'$(VSToolsPath)' == ''"&gt;$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)&lt;/VSToolsPath&gt; &lt;/PropertyGroup&gt; &lt;Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /&gt; &lt;Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets" /&gt; &lt;Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /&gt; &lt;Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /&gt; &lt;ProjectExtensions&gt; &lt;VisualStudio&gt; &lt;FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"&gt; &lt;WebProjectProperties&gt; &lt;UseIIS&gt;True&lt;/UseIIS&gt; &lt;AutoAssignPort&gt;True&lt;/AutoAssignPort&gt; &lt;DevelopmentServerPort&gt;30698&lt;/DevelopmentServerPort&gt; &lt;DevelopmentServerVPath&gt;/&lt;/DevelopmentServerVPath&gt; &lt;IISUrl&gt;http://localhost:50012/&lt;/IISUrl&gt; &lt;NTLMAuthentication&gt;False&lt;/NTLMAuthentication&gt; &lt;UseCustomServer&gt;False&lt;/UseCustomServer&gt; &lt;CustomServerUrl&gt; &lt;/CustomServerUrl&gt; &lt;SaveServerSettingsInUserFile&gt;False&lt;/SaveServerSettingsInUserFile&gt; &lt;/WebProjectProperties&gt; &lt;/FlavorProperties&gt; &lt;/VisualStudio&gt; &lt;/ProjectExtensions&gt; &lt;PropertyGroup&gt; &lt;PreBuildEvent&gt; &lt;/PreBuildEvent&gt; &lt;/PropertyGroup&gt; &lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. &lt;Target Name="BeforeBuild"&gt; &lt;/Target&gt; &lt;Target Name="AfterBuild"&gt; &lt;/Target&gt; --&gt; &lt;/Project&gt; </code></pre> <p>Here is the error I see after running <code>MSBuild</code> from command line:</p> <pre><code>C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Conten t&gt;msbuild macu.content.csproj /t:TransformAll Microsoft (R) Build Engine version 4.0.30319.17929 [Microsoft .NET Framework, version 4.0.30319.17929] Copyright (C) Microsoft Corporation. All rights reserved. Build started 1/17/2013 2:16:59 PM. Project "C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\M acu.Content\macu.content.csproj" on node 1 (TransformAll target(s)). ExecuteTransformations: Performing incremental T4 transformation Calculating whether transformed output is out of date... Transforming template shared\script\s_code.tt... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Micr osoft.TextTemplating.targets(396,5): warning : Compiling transformation: The va riable 'isAccountFound' is assigned but its value is never used. Line=24, Colum n=7 [C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu. Content\macu.content.csproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Micr osoft.TextTemplating.targets(396,5): error : Running transformation: System.Nul lReferenceException: Object reference not set to an instance of an object.\r [C :\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Conten t\macu.content.csproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Micr osoft.TextTemplating.targets(396,5): error : at Microsoft.VisualStudio.TextT emplating7D294BC599798219F70D124BB1976BCDFB50B07280E2004F9365EC71A617D68D059E43 6CBD1AD344727611A619EE41F939B60372B3E16565CA2D4E4B40FBC5C7.GeneratedTextTransfo rmation.TransformText() in c:\Users\[myUserName]\Documents\Visual Studio 2012\Proje cts\Macu.Content\Macu.Content\shared\script\s_code.tt:line 21. Line=21, Column= 0 [C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Co ntent\macu.content.csproj] Done Building Project "C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\ Macu.Content\Macu.Content\macu.content.csproj" (TransformAll target(s)) -- FAIL ED. Build FAILED. "C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Cont ent\macu.content.csproj" (TransformAll target) (1) -&gt; (ExecuteTransformations target) -&gt; C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Mi crosoft.TextTemplating.targets(396,5): warning : Compiling transformation: The variable 'isAccountFound' is assigned but its value is never used. Line=24, Col umn=7 [C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Mac u.Content\macu.content.csproj] "C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Cont ent\macu.content.csproj" (TransformAll target) (1) -&gt; (ExecuteTransformations target) -&gt; C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Mi crosoft.TextTemplating.targets(396,5): error : Running transformation: System.N ullReferenceException: Object reference not set to an instance of an object.\r [C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Cont ent\macu.content.csproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Micr osoft.TextTemplating.targets(396,5): error : at Microsoft.VisualStudio.TextT emplating7D294BC599798219F70D124BB1976BCDFB50B07280E2004F9365EC71A617D68D059E43 6CBD1AD344727611A619EE41F939B60372B3E16565CA2D4E4B40FBC5C7.GeneratedTextTransfo rmation.TransformText() in c:\Users\[myUserName]\Documents\Visual Studio 2012\Proje cts\Macu.Content\Macu.Content\shared\script\s_code.tt:line 21. Line=21, Column= 0 [C:\Users\[myUserName]\Documents\Visual Studio 2012\Projects\Macu.Content\Macu.Co ntent\macu.content.csproj] 1 Warning(s) 1 Error(s) Time Elapsed 00:00:01.04 </code></pre> <p>Can you see anything that I am doing which is causing the error, and do you know how to fix it so I can use msbuild and not run into this error?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload