【发布时间】:2010-06-04 12:56:58
【问题描述】:
我刚刚创建了 T4 模板来为我的 ViewModel 类自动生成属性实现(请参阅此处:Automatic INotifyPropertyChanged Implementation through T4 code generation?)。
目前我需要让项目在我想要生成属性实现的解决方案中保存“.tt”文件。
因此,例如解决方案包含三个项目:T4Generation、SomeProjectWithViewModels、AnotherProjectWithViewModels。
然后在 T4Generation 中调用 T4 模板时,它会查看解决方案中的所有项目并找到所有 ViewModel 类并生成一个 C# 文件,其中包含相应项目中特定 ViewModel 的属性实现。
例子:
“SomeProjectWithViewModels.SomeViewModel.cs”
public partial class SomeViewModel : BaseViewModel
{
private string p_SomeProperty;
}
生成文件“SomeProjectWithViewModels.SomeViewModel.Properties.cs”
public partial class SomeViewModel
{
public string SomeProperty
{
get { ... }
set { ... }
}
}
我现在的问题是,是否有可能创建可以在任何解决方案中引用的程序集(即“T4Generation.dll”),从而使主机解决方案能够以某种方式调用代码生成过程。
例如,我将使用项目“SomeApplication.exe”、“SomeClassLibrary.dll”启动一个新的解决方案“SomeSolution.sln”,并在 SomeApplication 中引用“T4Generation.dll”,并在 SomeApplication 的构建过程中生成 T4将被调用。
这可能吗?
【问题讨论】: