**我是一名正在接受培训的学生,C# 经验很少。我们公司正在开发使用 T4 模板(C# VS2010)的解决方案。生成的文件无法在 MSBuild 下编译,因为它依赖于 VS。我的任务是找到一个工具或一个库或一个 .dll 文件或 SDK 或任何可以在构建时替代 VS 的东西。否则,我必须将生成的代码修改为 VS 独立于我自己,我认为这对我来说是一项艰巨的任务。代码示例:
Project GetProjectContainingT4File(DTE dte) {
// Find the .tt file's ProjectItem
ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
// If the .tt file is not opened, open it
if (projectItem.Document == null)
projectItem.Open(Constants.vsViewKindCode);
if (AlwaysKeepTemplateDirty) {
// Mark the .tt file as unsaved. This way it will be saved and update itself next time the
// project is built. Basically, it keeps marking itself as unsaved to make the next build work.
// Note: this is certainly hacky, but is the best I could come up with so far.
projectItem.Document.Saved = false;
}
return projectItem.ContainingProject;
}
感谢您的帮助。**