T4“编译转换:具有相同身份的程序集” '已经导入了。尝试删除重复的引用之一。”?

发布于 2024-11-24 03:19:37 字数 287 浏览 4 评论 0原文

我一直在努力

编译转换:具有相同标识“xxxx”的程序集已被导入。尝试删除重复引用之一。

当使用 T4 在设计时生成一些代码时 - 将几个不同的可重用模板另存为 .ttinclude 文件,并在许多不同的“父”模板中共享。

当我删除其中一个引用(在我自己的 ttinclude 文件中)时,我在这之间切换,另一种选择是:

编译转换:无法找到类型或命名空间名称“yyy”(您是否缺少 using 指令)或者程序集参考?)

兜兜转转,有什么想法吗?

I've been struggling with

Compiling transformation: An assembly with the same identity 'xxxx' has already been imported. Try removing one of the duplicate references.

When using T4 to generate some code at design time - with a couple of different reusable templates saved as .ttinclude files, and shared in a number of different "parent" templates.

I toggle between this, and the alternative when I remove one of the references (in my own ttinclude file) which is :

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

Going round in circles, any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-12-01 03:19:37

好吧,找到了一个肮脏的解决方法。

如果有人有一些建议,我会喜欢更好的解决方案/方法吗?

发布我的过程可能对其他人有帮助。


  1. 使用模板指令来放置我的模板并包含
    模板进入调试模式,例如

    <#@ template language="C#" debug="true" hostspecic="true"#>

  2. 弹出打开%TEMP%以查看生成的文件(最近
    发生编译转换错误后已修改)。

  3. 搜索了所使用的丢失/重复的程序集/类。
    发现哪些“包含”模板具有相同的引用,例如

    <#@ include file="MyHelperTemplate.ttinclude"#>

    和:

    <#@ include file="EF.Utility.CS.ttinclude" #>

  4. 打开非自定义包含的包含文件夹
    与我自己发生冲突

    ..\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

  5. 打开此文件,删除其麻烦的导入

    <#@ import namespace="EnvDTE" #>

  6. 使用新名称将其保存在同一文件夹中,并更新引用以指向此新版本,例如

    <#@ include file="EF.Utility.CS.Custom.ttinclude" #>

  7. 将所需的导入放入“父”模板中,并从中删除
    “包含”模板。就我而言,这是:

    <#@ import namespace="EnvDTE" #>


现在它运行良好,完全没有问题,没有重复导入,并且正确引用了所有必需的程序集。

我确信有一种更复杂的方法来处理 T4 代码重用,从而完全消除这个问题。我最初尝试导入自己的自定义程序集,并使用模板的帮助程序,但是当我尝试构建自定义类库时,遇到了锁定 dll 的经典问题。

似乎 T4 Toolbox 可以通过 VolatileAssembly 自定义指令,很受欢迎,但对于我相当简单的程序来说看起来有点大材小用需要。也许当我有更多时间的时候。

Well, found a dirty workaround.

Would love a better solution / approach, if someone has some advice?

Posting my process as might be helpful to someone else.


  1. Used the template directive to put my templates and include
    templates into debug mode e.g.

    <#@ template language="C#" debug="true" hostspecific="true"#>

  2. Popped open %TEMP% to look at the generated file(s) (most recently
    modified) just after getting the compiling transformation error.

  3. Searched for the missing / doubled up assembly / class(es) used.
    Found which "included" templates both had same reference e.g.

    <#@ include file="MyHelperTemplate.ttinclude" #>

    and :

    <#@ include file="EF.Utility.CS.ttinclude" #>

  4. Opened the include folder for the non custom include that was
    causing the conflict with my own

    ..\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

  5. Opened this file up, removed its troublesome import

    <#@ import namespace="EnvDTE" #>

  6. Saved it with a new name in same folder and updated references to point to this new version e.g.

    <#@ include file="EF.Utility.CS.Custom.ttinclude" #>

  7. Put required imports into the "parent" templates, and removed from
    the "include" template. In my case this was:

    <#@ import namespace="EnvDTE" #>


Now it runs fine, no problems at all, no duplicated imports, and all required assemblies referenced correctly.

Am sure there is a much more sophisticated way of dealing with T4 code reuse which negates this problem entirely. I initially tried importing my own custom assembly, with helpers for the templates, but had what seems like a classic problem with locked dlls when I then tried to build my custom class library.

Seems T4 Toolbox has a solution to this with the VolatileAssembly Custom Directive, and is popular, but looks a bit overkill for my fairly simple needs. Maybe when I have more time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文