Missing Assemblies in T4 becomes GAC Hell?
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 sin开发者_如何学Cce 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"
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" #>
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
<#@ 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();
#>
I had the same issue. I could resolve it adding some assemblies ...
<#@ 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();
#>
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.
精彩评论