T4 中缺少组件会成为 GAC 地狱吗?
我试图遵循 Oleg Sych 关于 T4 的教程 http://www.olegsych.com/2008/09/t4-tutorial-creatating-your-first-code-generator/,kinduva“你好,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"
I was trying to follow Oleg Sych's tutorials on T4 http://www.olegsych.com/2008/09/t4-tutorial-creatating-your-first-code-generator/, kinduva "Hello, Northwind!" but right away in the second step (at bottom) I got ten "missing assembly" errors like this
Error 1 Compiling transformation: The type >'Microsoft.SqlServer.Management.Sdk.Sfc.ISfcValidate' is defined in an assembly that is >not referenced. You must add a reference to assembly >'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, >PublicKeyToken=89845dcd8080cc91'.
I made sure all the sql server assemblies from (list below) are in %windir%\assembly (I think that’s the GAC), but no good. I added the assemblies to the visual-studio project; no good. I guess the only thing I can do is add absolute paths to the assemblies, but that is a HORRIBLE solution since I can’t share the solution with programmers who don’t have exactly the same absolute paths. Any ideas how to fix this, please & thanks?
<#@ 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
Here's stuff I put in the 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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过使用部分强名称(即省略“.dll”)来引用 GACd 程序集
例如,使用
<#程序集名称=“Microsoft.SqlServer.Management.Sdk.Sfc”#>
You can reference GACd assemblies by using the partial strongname (i.e. omitting the ".dll")
for example, use
<# assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
我收到了同样的问题,我的修复方法是添加
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
这似乎对我有用
我的现在看起来像这样
I was recieving the same problem, my fix was adding
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
That seemed to work for me
Mine looks like this now
我有同样的问题。我可以通过添加一些程序集来解决它...
I had the same issue. I could resolve it adding some assemblies ...
我在尝试开始使用 T4 时遇到了类似的问题。添加对
Microsoft.SqlServer.Scripting
NuGet 包的引用 修复了我遇到的与程序集相关的问题。I ran into a similar problem, while trying to get started working with T4. Adding a reference to the
Microsoft.SqlServer.Scripting
NuGet package fixed the assembly-related issues I was running into.