簡體   English   中英

具有構建過程的T4模板

[英]T4 template with Build Process

我的要求是,當構建發生時,應該執行T4模板。
這是我在模板中編寫的代碼。

<#@ 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#>

運行正常,但是當我嘗試構建它時,出現了一個異常,即找不到Newtonsoft DLL。

解決方案生成后,這是我在項目文件中為運行模板所做的操作。

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v11.0\Microsoft.TextTemplating.targets" />
<PropertyGroup>
 <TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>

  <ItemGroup>
    <T4ReferencePath Include="$(VsIdePath)PublicAssemblies\" />
  </ItemGroup>

Newtonsoft.dll位於解決方案文件夾根目錄中的DLL文件夾中。

我看到了@Get Visual Studio帖子,它在每個版本上都運行T4模板,並且還遵循@MarkGr建議的步驟,但是沒有運氣。

我正在使用VS2012。 誰能告訴我我要去哪里錯了?

嘗試使用此ItemGroup。 它應該可以解決問題。 至少在VS2013中

<ItemGroup>
    <T4ParameterValues Include="SolutionDir">
      <Value>$(SolutionDir)</Value>
    </T4ParameterValues>
  </ItemGroup>

http://blogs.msdn.com/b/t4/archive/2013/08/29/what-s-new-in-t4-for-visual-studio-2013.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM