T4获取解决方案的当前工作目录 [英] T4 Get Current Working Directory of Solution

查看:499
本文介绍了T4获取解决方案的当前工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010的T4,我想遍历在我的解决方案中的文件,但是我发现,在一种沙箱中,并且当前工作目录T4源代作品是Visual内工作室10的目录中的程序文​​件。



是否有引用该溶液中的T4文件是在相对论,以便它不会破坏构建的方式,或适用于不具有相同的文件结构等另外一个人的盒子?



感谢


解决方案

您还没有表现出你的模板头或任何代码,所以我会认为你没有设置像这样



<$ p $的hostspecific属性设置为true p> <#@模板语言=C#hostspecific =真#>



ITextTemplatingEngineHost界面会给你你需要的信息。
http://msdn.microsoft.com/en-us/库/ microsoft.visualstudio.texttemplating.itexttemplatingenginehost.aspx

 <#= this.Host.ResolveParameterValue( - , - ,项目)#> 



我不相信有参考的解决办法,但你可以在路径这你* .TT文件,并从那里得到的其他文件。



要从相对于文本模板的位置加载一个文件,可以使用this.Host.ResolvePath ()


I am using T4 in Visual Studio 2010, and I want to iterate over the files in my solution, however I have found that T4 source generation works in a kind of a sandbox, and the current working directory is inside of the Visual Studio 10 directory in program files.

Is there a way to reference the solution the T4 file is in relativistically, so that it doesn't break the build, or works on some one else's box that doesn't have the same file structure etc?

Thanks

解决方案

You haven't shown your template header or any code so I'll assume you haven't set the hostspecific attribute to true like so

<#@ template language="C#" hostspecific="True" #>

The ITextTemplatingEngineHost interface will give you the information you need. http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.itexttemplatingenginehost.aspx

<#=this.Host.ResolveParameterValue("-", "-", "projects") #>

I don't believe there is a way to reference the solution, but you can get the path in which your *.tt file is and from there get other files.

To load a file from a location relative to the text template, you can use this.Host.ResolvePath().

这篇关于T4获取解决方案的当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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