Visual studio 2010 从VisualStudio中T4生成器的路径中卸下部件

Visual studio 2010 从VisualStudio中T4生成器的路径中卸下部件,visual-studio-2010,t4,Visual Studio 2010,T4,在我的项目中,我安装了Resharper,我正在使用VisualStudio中的T4模板进行设计时模板制作 我有 <#@ assembly name="$(SolutionDIr)FTest\bin\Debug\FTest.dll" #> <#@ assembly name="$(SolutionDIr)FTest\bin\Debug\nunit.framework.dll" #> 当使用与FTest.dll使用的dll相同的dll进行导入时,我该如何操作?我不想使用R

在我的项目中,我安装了Resharper,我正在使用VisualStudio中的T4模板进行设计时模板制作

我有

<#@ assembly name="$(SolutionDIr)FTest\bin\Debug\FTest.dll" #>
<#@ assembly name="$(SolutionDIr)FTest\bin\Debug\nunit.framework.dll" #>
当使用与FTest.dll使用的dll相同的dll进行导入时,我该如何操作?我不想使用Resharper版本的nunit

编辑:

在像GarethJ所说的那样设置注册表项后,消息如下所示:

Error   12  Running transformation: System.InvalidCastException: [A]NUnit.Framework.CategoryAttribute cannot be cast to [B]NUnit.Framework.CategoryAttribute. Type A originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'LoadFrom' at location 'C:\Repos\BSF-Functional-Automation\FunctionalTest\FunctionalTest\bin\Debug\nunit.framework.dll'. Type B originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'Default' at location 'C:\Program Files (x86)\JetBrains\ReSharper\v6.1\Bin\nunit.framework.dll'.
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.<TransformText>b__5(Object x)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.<TransformText>b__4(MethodInfo m)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.TransformText()
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)        1   1   
运行转换时出现错误12:System.InvalidCastException:[A]NUnit.Framework.CategoryAttribute无法强制转换为[B]NUnit.Framework.CategoryAttribute。类型A源自位置“C:\Repos\BSF Functional Automation\Functional test\Functional test\bin\Debug\nunit.framework.dll”的上下文“LoadFrom”中的“nunit.framework,Version=2.5.10.11092,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77”。类型B源自“C:\Program Files(x86)\JetBrains\ReSharper\v6.1\Bin\nunit.framework.dll”位置的上下文“Default”中的“nunit.framework,Version=2.5.10.11092,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77”。
位于Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.b__5(对象x)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source,Func`2谓词)
在Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.b__4(MethodInfo m)上
位于System.Linq.Enumerable.WhereEnumerableInterator`1.MoveNext()
位于System.Collections.Generic.List`1..ctor(IEnumerable`1集合)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
在Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.TransformText()上
在Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession会话,字符串源,ITextTemplatingEngineHost主机,字符串和结果)1

导入只提供了一个“using”语句,而不是一个引用,因此在这里并不重要

LoadFrom上下文中加载的类型A是T4中的assembly标记正在加载的类型。 来自Resharper目录的类型B从此错误中显示为来自对包含“BaseTest”的程序集的反射


我会尝试查看BaseTest的构建,看看Resharper是否可以潜入这里。您可能可以通过在basetest的程序集上运行reflector或ildasm来验证这一理论。

请尝试暂时关闭程序集缓存,以便我们在异常中获得更干净的数据。这应该删除appdata下的临时程序集idrectory,让我们看看真正比较的是哪两个程序集,然后我们可以尝试找出resharper的目录被拉入的位置。HKEY\U LOCAL\U MACHINE\SOFTWARE[Wow6432Node]\Microsoft\VisualStudio\10.0\text模板设置字符串值ShadowCopy=FALSETONE。现在显示未缓存的DLL。
((CategoryAttribute)y)
在此段中,我觉得
y
是类型A,
CategoryAttribute
是类型B,我们正试图将A转换为B。消息说类型B来自Resharper的Nunit,它告诉我,我在那里键入的文本
CategoryAttribute
来自Resharper,变量
y
来自BaseTest程序集。如果我在T4文件中键入type(C#generics)或
(CategoryAttribute)y
的代码
,我希望它也使用BaseTest程序集引用的nunit。但不幸的是,如果我在其中键入类型名称,它会选择错误的程序集类型。感谢您花时间来帮助我。我通过使用反射在整个模板中获取类型临时修复了它,并且除了带字符串的字符外,我从不手写类型名称-但是请帮助我理解T4引擎如何拾取一些BaseTest DLL中未引用的随机DLL(是,BaseTest项目不引用任何resharper nunit)或者提到使用@assembly指令。我手头没有Resharper可以尝试,但可能是Resharper的安装已将Resharper nunit添加到devenv.exe.config中的探测路径中。这可能会导致T4在对间接使用类型进行基本解析时首先找到它。Resharper确实将其nunit Dll添加到devenv配置-谢谢!
    <#
    var someVar = (TestAttribute)typeof(BaseTest).GetMethods()
    .Where(
    x => x.GetCustomAttributes(false).Where(y => y.Name == "CategoryAttribute" && ((CategoryAttribute)y).Name == "Smoke").Any()
     )
    #>
Error   21  Running transformation: System.InvalidCastException: [A]NUnit.Framework.CategoryAttribute cannot be cast to [B]NUnit.Framework.CategoryAttribute. Type A originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'LoadFrom' at location 'C:\Users\Chandirasekar Thiaga\AppData\Local\assembly\dl3\ZGE1068O.OD1\ARWGXOXD.EMZ\7407d57d\ff3a4298_6ceccc01\nunit.framework.dll'. Type B originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'Default' at location 'C:\Program Files (x86)\JetBrains\ReSharper\v6.1\Bin\nunit.framework.dll'.
Error   12  Running transformation: System.InvalidCastException: [A]NUnit.Framework.CategoryAttribute cannot be cast to [B]NUnit.Framework.CategoryAttribute. Type A originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'LoadFrom' at location 'C:\Repos\BSF-Functional-Automation\FunctionalTest\FunctionalTest\bin\Debug\nunit.framework.dll'. Type B originates from 'nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' in the context 'Default' at location 'C:\Program Files (x86)\JetBrains\ReSharper\v6.1\Bin\nunit.framework.dll'.
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.<TransformText>b__5(Object x)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.<TransformText>b__4(MethodInfo m)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.VisualStudio.TextTemplating64EAA000670725A96AF52252D093BE63.GeneratedTextTransformation.TransformText()
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)        1   1