在我的项目中,我安装了 Resharper,并且我正在使用 Visual Studio 中的 T4 模板进行设计时模板。
我有
<#@ assembly name="$(SolutionDIr)FTest\bin\Debug\FTest.dll" #>
<#@ assembly name="$(SolutionDIr)FTest\bin\Debug\nunit.framework.dll" #>
我也有
<#@ import namespace="NUnit.Framework" #>
然后我在这样的代码中有一个演员表
<#
var someVar = (TestAttribute)typeof(BaseTest).GetMethods()
.Where(
x => x.GetCustomAttributes(false).Where(y => y.Name == "CategoryAttribute" && ((CategoryAttribute)y).Name == "Smoke").Any()
)
#>
我得到一个无效的演员表异常。它告诉我模板生成器使用的 'nunit.framework' dll 与项目 dll 使用的不同。
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'.
当使用 <#@ import namespace="NUnit.Framework" #> 导入时,我该如何导入与 FTest.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