質問

c#ソリューションをビルドすると、.ttファイルは.csファイル出力を作成しません。しかし、ソリューションエクスプローラーで.ttファイルを1つずつ右クリックし、[カスタムツールを実行]を選択すると、 .csが生成されるため、ビルドツールの設定は正しいです。カスタムツールを.ttファイルで実行するようにソリューション全体をビルドするにはどうすればよいですか?

役に立ちましたか?

解決

ポール、 TextTransform.exe または Elton Stoneman's MSBuildタスク assembly および include は、T4がVisual Studioとコマンドラインホスト。

他のヒント

私自身の質問に答えると、この議論に従って設計時に生成されることになっています:

https://web.archive.org/web/20081227142303/http://www.olegsych.com/2008/02/t4-template-directive/

Visual Studio 2013では、これらの行を.csprojファイルに追加するだけで、.ttファイルを取得してターゲットを再生成できました。

<PropertyGroup>
  <!-- Get the Visual Studio version – defaults to 10: -->
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <!-- Keep the next element all on one line: -->
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<!-- To enable build tasks on your development computer, install Modeling SDK for Visual Studio. https://www.microsoft.com/en-us/download/details.aspx?id=40754 -->
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<!-- Run the Transform task at the start of every build -->
<PropertyGroup>
  <TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<!-- Overwrite files that are read-only, for example because they are not checked out -->
<PropertyGroup>
  <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
</PropertyGroup>
<!-- Transform every template every time -->
<PropertyGroup>
  <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>

ただし、これが機能するには、モデリングをインストールする必要があります。 SDK for Visual Studio 。このページのすべての情報と、利用可能なオプションのより詳細な説明を見つけました:ビルドプロセスでのコード生成

Visual Studio 2017(おそらく次のバージョンも)では、ビルド前イベントにこれを追加する必要があります:

"$(DevEnvDir)TextTransform.exe" -out "$(ProjectDir)YourTemplate.cs" "$(ProjectDir)YourTemplate.tt"

p.s。私のために働いた唯一のソリューション。

p.s.s。ルートプロジェクトディレクトリにない場合は、テンプレートのパスを変更します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top