**我是一名接受培训的学生,对 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;
}
我很感激你的帮助。**
最佳答案
限制
The generated files can't be compiled under MSBuild because it is VS dependent
看起来很奇怪。为什么您要以 .NET 环境为目标,但希望您的构建环境独立于 MS?当然,您至少需要一个 C# 编译器。
如果你真的想使用 MSBuild 之外的东西,还有很多替代品,比如 Mono 的 Microsoft.Build甚至 Make for Windows .
关于c#-4.0 - 是否有任何 MSBuild 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582250/