的NuGet - 在不同的安装后,T4文件属性 [英] NuGet - T4 File properties are different after installed

查看:436
本文介绍了的NuGet - 在不同的安装后,T4文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个的NuGet包,提供一些T4模板到C $ cTemplates目录下的$。当我安装的NuGet包,T4模板都设置为TextTemplatingFileGenerator自定义工具属性。这是不对的。

I'm building a NuGet package that delivers some T4 templates into the CodeTemplates directory. When I install the NuGet package, the T4 templates all have the Custom Tool property set to "TextTemplatingFileGenerator". This isn't right.

我知道我可以通过改变我的注册表,使新的T4模板不会添加这种方式禁用此功能,但由于这是一个的NuGet包,这是不是一种选择。

I know I can disable this by altering my registry so that new T4 templates aren't added this way, but since this is a NuGet package, that is not an option.

我已经研究过PowerShell的,但我无法理解我还能做什么来实现我的目标。

I've looked into PowerShell, but I'm having trouble understanding what I would do to achieve my goal.

我看了的.csproj文件,XML和发现这一点:

I've looked at the .csproj file xml and found this:

<None Include="CodeTemplates\AddController\Controller.tt">
    <Generator>TextTemplatingFileGenerator</Generator>
    <LastGenOutput>Controller.cs</LastGenOutput>
</None>

如果我从这个节点删除TextTemplatingFileGenerator,那么该文件将作为我的愿望。

If I remove "TextTemplatingFileGenerator" from this node, then the file will work as I desire.

我应该在哪里何去何从?

Where should I go from here?

推荐答案

我不知道有一个很好的办法做到这一点。在博客中,<一个href="http://blogs.msdn.com/b/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-$c$c-vs-one-time-generation.aspx"相对=nofollow>大卫Ebbo写道:

I'm not sure there's a nice way to do this. In a blog post, David Ebbo wrote:

最后一件事我会提到这个   模型是,.TT文件通常   不属于你的项目。相反,它   住别处,并且仅其   输出成为项目的一部分。   那么,在技术上,该.TT文件可以   在项目中以方便编辑,但   那么你必须删除   TextTemplatingFileGenerator自定义   工具,因为你真的不希望它   自己(来执行它肯定会比   使用自定义的主机失败)。

One last thing I’ll mention about this model is that the .tt file is normally not part of your project. Instead, it lives somewhere else, and only its output becomes part of your project. Well, technically, the .tt file can be in your project for easy editing, but you then have to remove the ‘TextTemplatingFileGenerator’ custom tool, because you really don’t want it to execute on its own (it would surely fail with the custom host).

此使得它听起来像,这是当一个.TT文件被添加到项目中的Visual Studio行为

This makes it sound like this is Visual Studio behavior when a .tt file is added to the project.

这是说,斯科特Hanselman的AddMvc3ToWebForms 使得在的csproj文件中的一些改动一个GUID添加MVC功能(添加控制器/添加视图等),因此有可能,你可以做他的相似的code的东西,删除你的包在发电机部分文件并重新加载的项目?

That said, Scott Hanselman's AddMvc3ToWebForms makes some changes to a GUID in the csproj file to add MVC functionality (Add Controller / Add View, etc.), so it's possible you could do something similar to his code and remove the Generator section for files in your package and reload the project?

这篇关于的NuGet - 在不同的安装后,T4文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆