有趣的T4问题 [英] Intriguing T4 question

查看:108
本文介绍了有趣的T4问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个项目的解决方案 - 每个都是一个类库。

I have a solution with two projects in - each is a class library.

第一个是一个类库,它暴露了一些类,
second 是一个T4模板,它有一个项目引用第一个。

The first is a class library that exposes a number of classes, the second is a T4 template which has a project reference to the first.

模板中的元代码指的是各个类中的第一个
项目,最终创建一个输出类,它本身取决于
第一个项目中的类。

The metacode in the template refers to various classes in the first project and ultimately it creates an output class that itself hinges in the classes in the first project.

显然有两个输出组件,称为第一个 .dll和
第二个 .dll。

Clearly there are two output assemblies, call them first.dll and second.dll.

我的问题是:有没有办法在一个程序集中执行此操作?目前我必须部署这两个程序集,因为在运行时,
second .dll中生成的类需要第一个 .dll中的支持类。

My question is: is there a way to do this in just one assembly? Currently I must deploy both assemblies because at runtime the generated class in second.dll requires the supporting classes in first.dll.

我确实尝试了一个实验,在项目第一次中,我添加了项目
second 中生成的.cs文件(作为链接)。

I did try an experiment and in project first i added the generated .cs file (as a link) that is in project second.

这意味着,一旦构建第一个 .dll是独立的 - 它一起需要所有类。

This means that once built first.dll is stand-alone - it has all classes required, together.

这里的问题是,如果我打破.tt文件并构建,那么生成的.cs将不会生成,然后项目
first 将不会构建(因为它有现在已破坏的源文件的链接,这意味着即使我修复.tt文件,项目
second 将永远不会构建,因为它需要构建时间访问项目$ b中的类$ b 第一个因为没有生成而不再有dll(因为没有生成.cs fi le目前)。

The problem here though is that if I ever break the .tt file and build, then the generated .cs won't get generated and then the project first won't build (because it has a link to that now broken source file) that means in turn that even if I fix the .tt file that project second will never build because it requires buildtime access to classes in project first which no longer has a dll because it didn't build (because there's no generated .cs file currently).

想法?

Thx

推荐答案


这里的问题是如果我打破.tt文件并构建,那么生成的.cs将不会生成,然后项目
first 将不会构建(因为它有一个指向该文件的链接)现在已破坏的源文件)这意味着即使我修复.tt文件,项目
第二将永远不会构建,因为它需要构建时间访问项目中的类
第一个,它不再有一个dll,因为它没有构建(因为当前没有生成的.cs文件)。

The problem here though is that if I ever break the .tt file and build, then the generated .cs won't get generated and then the project first won't build (because it has a link to that now broken source file) that means in turn that even if I fix the .tt file that project second will never build because it requires buildtime access to classes in project first which no longer has a dll because it didn't build (because there's no generated .cs file currently).

Hello Korporal,

Hello Korporal,

当你添加一个generated.cs作为first.dll的链接时,它已经开始生成first.dll的一部分,如果生成的话。 cs有任何错误,这两个DLL都无法传递给&nb sp; compile。

When you add a generated.cs as a link for the first.dll , it has begainning a part of first.dll and if the generated.cs has any error the both dll can not pass to compile.

对于后一种情况 "即使我修复了.tt文件...... " ,如果你想用.tt文件中的first.dll添加引用,你必须指定你附加的dll。换句话说,
第一个dll必须在second.dll之前编译完成。然后在第二个dll中,generated.cs可以引用first.dll中的类。如果您修复了.tt文件,那么第二个项目应该成功构建。如果您想对tt.file进行更改,那么应该再次构建
first.dll和second.dll。

For your latter case "even if I fix the .tt file ..." , if you want to add reference with first.dll from you .tt file you must specify which dll you attached .In other words,the first dll must be compiled finished before second.dll .Then in second dll the generated.cs could refer the classes from first.dll. If you fix the .tt file that second project should be build successfully.And if you want to take tt.file changes to first.dll,The first.dll and second.dll should be builded again.

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="D:\T4AssemblyRefResovle\Lib\Artech.T4AssemblyRefResovle.Foo.dll" #>
<#@ output extension=".cs" #>
public class HelloWorld
{}

>>我的问题是:有没有办法在一个程序集中执行此操作?

有关如何将多个dll合并为单个dll的方法。最好的选择是使用
ILMerge
功能工具。从这里获取更多信息。

For how to merge multiple dll into a single dll. The good choice is to use ILMerge  tool.Get more information from here.

https://blogs.msdn.microsoft.com/saveenr/2012/09/09/merging-my-assemblies-with-ilmerge/

此致,

Neil Hu

Neil Hu


这篇关于有趣的T4问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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