如何使用NuGet软件包部署T4包含文件 [英] How to deploy T4 include files with NuGet packages
问题描述
我有一些T4包含文件,我想在多个项目中重复使用.因此,我创建了一个NuGet程序包,并将文件放在该程序包的Tools文件夹中.现在它们已安装在 packages \ PackageName.x.x.x \ Tools
文件夹中,我可以在项目的T4文件中添加一个include指令.
I have some T4 include files which I want to reuse in several projects. So I have created a NuGet package and placed the files in the Tools folder of the package. Now they are installed in the packages\PackageName.x.x.x\Tools
folder and I can add an include directive in my T4 files in the project.
但是,这样做的缺点是,路径中有一个版本号,当我创建软件包的新版本时,该版本号会更改.这就需要我更新项目中的所有include指令.
But the disadvantage of this is, that there is a version number in the path which will change when I create new versions of the package. That would require me to update all include directives in the project.
有人知道这样做的好方法的提示吗?
Does anybody know a hint for a good approach for this?
推荐答案
T4 include指令不能识别msbuild属性,但汇编程序可以.因此,您可以使用基本模板类,并从NuGet包中引用程序集.
The T4 include directive doesn't recognise msbuild properties, but the assembly one does. So you can use a base template class and reference an assembly from within your NuGet package.
使用NuGet 2.5(在原始帖子发布时可能不可用),您可以创建msbuild .props文件.分配$(MSBuildThisFileDirectory)将程序集的相对路径组合到新的msbuild属性.然后,可以在使用NuGet包的项目的T4模板中使用新属性.
With NuGet 2.5 (probably not available at the time of the original post) you can create an msbuild .props file. Assign $(MSBuildThisFileDirectory) combined the relative path to the assembly to a new msbuild property. The new property can then used in the T4 template of projects which are using the NuGet package.
这篇关于如何使用NuGet软件包部署T4包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!