我在t4模板和单元测试中使用相同的代码。两者都引用相同的程序集:单元测试执行成功,t4返回错误: 运行转换:System.MissingMethodException:找不到方法:'System.Data.Entity.DbSet`1
T4模板:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" #>
<#@ assembly name="C:\VSProjects\VS.CodeGen\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #>
<#@ assembly name="C:\VSProjects\VS.CodeGen\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll" #>
<#@ assembly name="C:\VSProjects\VS.CodeGen\VS.CodeGen.Source\bin\Debug\VS.CodeGen.Source.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="VS.CodeGen.Source.Models" #>
<#@ output extension=".cs" #>
<#
var connectionString = "Data Source=MyComputer;Initial Catalog=GenSource;Integrated Security=True;MultipleActiveResultSets=True";
using (var ctx = new GenSourceContext(connectionString))
{
var dsp = ctx.Dsps;
}
#>
测试代码:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VS.CodeGen.Source.Models;
namespace VS.CodeGen.Test
{
[TestClass]
public class TestT4
{
[TestMethod]
public void TestMethod1()
{
var connectionString = "Data Source=MyComputer;Initial Catalog=GenSource;Integrated Security=True;MultipleActiveResultSets=True";
using (var ctx = new GenSourceContext(connectionString))
{
var dsp = ctx.Dsps;
}
}
}
}
导致错误的原因是什么?
谢谢!