我试图关注Oleg Sych关于T4 http://www.olegsych.com/2008/09/t4-tutorial-creatating-your-first-code-generator/的教程,kinduva“Hello,Northwind!”但是在第二步(在底部)我马上就得到了十个“缺少装配”的错误
错误1编译转换:类型>'Microsoft.SqlServer.Management.Sdk.Sfc.ISfcValidate'在未引用的程序集中定义。您必须添加对程序集的引用>'Microsoft.SqlServer.Management.Sdk.Sfc,Version = 10.0.0.0,Culture = neutral,> PublicKeyToken = 89845dcd8080cc91'。
我确保所有来自(下面的列表)的sql server程序集都在%windir%\ assembly中(我认为这是GAC),但没有好处。我将组件添加到visual-studio项目中;不好。我想我唯一能做的就是为程序集添加绝对路径,但这是一个可怕的解决方案,因为我无法与没有完全相同的绝对路径的程序员共享解决方案。任何想法如何解决这个问题,请&感谢?
<#@ template language="C#" #>
<#@ output extension="SQL" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#
Server server = new Server();
Database database = new Database(server, "Northwind");
Table table = new Table(database, "Products");
table.Refresh();
#>
create procedure Products_Delete
@ProductID int
as
delete from Products
where ProductID = @ProductID
以下是我在GAC中提出的内容
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.WmiEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.ReportingServices.Interfaces.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfoExtended.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Dmf.Adapters.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Dmf.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.DmfSqlClrWrapper.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.Collector.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.CollectorEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.Sdk.Sfc.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.Utility.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.UtilityEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.PolicyEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.RegSvrEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ServiceBrokerEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SmoExtended.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SqlEnum.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SqlWmiManagement.dll"
"C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SString.dll"
答案 0 :(得分:3)
您可以使用部分强名称来引用GACd程序集(即省略“.dll”) 例如,使用 &lt;#assembly name =“Microsoft.SqlServer.Management.Sdk.Sfc”#&gt;
答案 1 :(得分:1)
我收到同样的问题,我的修复是添加
&lt;#@ assembly name =“Microsoft.SqlServer.Management.Sdk.Sfc”#&gt;
这似乎对我有用
我现在看起来像这样
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension="SQL" #>
<#@ include file="T4Toolbox.tt" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#
Server server = new Server(@"localhost\mssql2008");
Database database = new Database(server, "BreakAway");
Table table = new Table(database, "Contact");
table.Refresh();
#>
答案 2 :(得分:0)
我有同样的问题。我可以解决它添加一些程序集...
<#@ template language="C#" Debug="true"#>
<#@ output extension="SQL" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#
Server server = new Server(@"SQLInstanceName");
Database database = new Database(server, "DBName");
Table table = new Table(database, "Countries");
table.Refresh();
#>
答案 3 :(得分:0)
我遇到了类似的问题,同时尝试开始使用T4。添加对Microsoft.SqlServer.Scripting
NuGet package的引用修复了我遇到的与程序集相关的问题。