T4模板添加现有项目的装配解决方案 [英] T4 template adding assembly of existing project in solution

查看:116
本文介绍了T4模板添加现有项目的装配解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要添加一个现有项目的装配在我的解决方案在我的T4模板文件。
的问题是,我的T4模板是在一个名为Project.WebApi项目,我需要在我的T4模板类是一个叫Project.Common.WebApi项目中。

Hi I need to add the assembly of an an existing project in my solution in my T4 Template file. The problem is that my T4 template is in a project called Project.WebApi and the class that I need in my T4 template is inside a project called Project.Common.WebApi.

我已经tryed导入命名空间是这样的:

I have tryed importing the namespace like this:

<#@ import namespace="Project.Common.WebApi.T4TemplateAttribute" #>



不过,我得到这个错误:

But I get this error:

The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)   

我已经tryed添加组件是这样的:

I have tryed adding the assembly like this:

<#@ assembly name="Project.Common.WebApi" #>

和我得到这个错误:

Compiling transformation: Metadata file 'Project.Common.WebApi' could not be found

我的项目包含T4Template(Project.WebApi)具有对Project.Common.WebApi,但是从我读T4Template不使用在项目中引用的参考。

My project that contains the T4Template (Project.WebApi) has a reference to the Project.Common.WebApi but from what I read T4Template does not use the references in the projects.

我怎样才能解决这个问题?

How can I solve this issues?

推荐答案

T4的作品从你的代码的其余部分几乎完全独立的。你在正确的轨道上,虽然与组装指令,但是你需要指定组件的实际DLL的完整路径,除非大会在海关总署(它可能不是)。

T4 works nearly completely independent from the rest of your code. You're on the right track though, with the assembly directive, but you'll need to specify a full path to the actual DLL of the assembly, unless the assembly is in the GAC (which it probably isn't).

不过幸运的是,你可以使用T4指令的MSBuild宏。所以,你可能会得到类似

Luckily, however, you can use MSBuild macros in T4 directives. So, you'll probably get something like

<#@ assembly name="$(SolutionDir)Project.Common.WebApi\bin\Debug\Project.Common.WebApi.dll" #>

请参阅的MSDN 有关此语法的一些背景。

See MSDN for some more background on this syntax.

您仍然还需要导入命名空间指令。

最后,要警惕项目构建秩序。现在包含您的T4模板项目依赖于Project.Common.WebApi,所以你需要确保Project.Common.WebApi先建。否则,你的T4模板可能会意外地链接到一个旧版本的程序集,使得虫子真的很难跟踪。

Finally, be wary of project build order. The project that contains your T4 template now depends on Project.Common.WebApi, so you'll need to make sure that Project.Common.WebApi is built first. Otherwise, your T4 template might accidentally link to an older version of the assembly, making bugs really hard to track.

如果你已经有一个项目引用它,你'再全部完成,但在其他方面则需​​要正确设置的依赖关系。您可以在Visual Studio中通过项目依赖项...对话框中做到这一点。右键单击该项目,以找到它。

If you already have a project reference to it, you're all done, but otherwise you need to set up the dependencies correctly. You can do this in Visual Studio via the "Project Dependencies..." dialog. Right-click the project to find it.

这篇关于T4模板添加现有项目的装配解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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