我想我可能終於在這裏找到了解決方案。當瀏覽如何在項目文件中提到XAML文件用於c#項目時,我意識到了這一點。
讓我們假設一個使用C.xml
數據的文件A.tt
和B.tt
,並且我們希望在C.xml
更改時重新生成代碼。
編輯項目文件。您的A.tt
和B.tt
定義應該是這個樣子:
<ItemGroup>
<None Include="A.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>A.cs</LastGenOutput>
<DependentUpon>C.xml</DependentUpon>
</None>
<None Include="B.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>B.cs</LastGenOutput>
<DependentUpon>C.xml</DependentUpon>
</None>
</ItemGroup>
此外,您將需要(當然...)
<ItemGroup>
<None Include="C.xml" />
</ItemGroup>
而且還指令自動生成A.cs
和B.cs
:
<Compile Include="A.cs">
<DependentUpon>A.tt</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="B.cs">
<DependentUpon>B.tt</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
我相信當你創建模板文件時,大部分的工作都已經完成了,所以你真的必須做廣告d是<DependentUpon>C.xml</DependentUpon>
部件到ItemGroup
的A.tt
和B.tt
。
順便說一句:我想出了熱Visual Studio構建C#項目:MSBuild。項目文件本身(* .csproj)是一個MSBuild文件,類似於Makefile。因此,一個解決方案可能是在「構建」XML文件時觸摸* .tt文件...我會保持發佈。 – 2010-01-22 08:09:11