简体   繁体   English

带有DLL的C#模板调用方法Assembly错误时

[英]C# Templates with DLL Upon calling the method Assembly error

I am trying to use a template .tt file to create the table names for an api driven application. 我正在尝试使用模板.tt文件来创建api驱动的应用程序的表名。 I can do this now with a static method as such. 我现在可以使用静态方法执行此操作。 But obviously this is not very reusable. 但这显然不是很可重用。

public string[] GetEntities()
{
    return new string[] { "Entity01", "Entity02", "Entity03" }; 
} 

So what I am trying to accomplish is to allow my SqlFactory to go out and get my entities. 因此,我要完成的工作就是允许我的SqlFactory走出去并获取我的实体。 This is what I was trying: 这是我正在尝试的:

<#@ assembly name="$(SolutionDir)\MultiApiConnector\bin\SqlFactory.dll"#>    
<#+
public string[] GetEntities()
{
string hostName = ""; 
string dbName = "";
IDatabase database = DatabaseFactory.CreateDatabaseConnection("SqlServer", "Server=" + hostName + ";Integrated security=SSPI;database=" + dbName + ";");
return  database.GetRows;
}#>

Severity Code Description Project File Line Suppression State Error Compiling transformation: The type 'Object' is defined in an assembly that is not referenced. 严重性代码说明项目文件行抑制状态错误编译转换:类型'Object'是在未引用的程序集中定义的。 You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 您必须添加对程序集“ netstandard,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51”的引用。 MultiApiConnector C:\\Users\\Dell\\source\\repos\\MultiApiConnector\\MultiApiConnector\\Controllers\\Common.tt 16 MultiApiConnector C:\\ Users \\ Dell \\ source \\ repos \\ MultiApiConnector \\ MultiApiConnector \\ Controllers \\ Common.tt 16

For my own edification I went out and did quite a number of searches about this error I looked in the current project to make sure that there was a reference to netstandard and there is. 为了我自己的兴趣,我出去了,并在当前项目中进行了很多搜索以查找该错误,以确保存在对netstandard的引用。 I went to the SqlFactory project and it is there as well under the sdk. 我去了SqlFactory项目,它也位于sdk下。 I have looked into adding the netstandard to either solution and it is already there. 我已经考虑将netstandard添加到任一解决方案中,并且已经存在。 Tried to add a reference to my config with no luck. 试图添加引用到我的配置没有运气。 I have searched stackoverflow for something similar to no avail. 我已经在stackoverflow上搜索了类似于无效的内容。 I am sure I am doing something wrong as I am new to templates. 我肯定是做错了,因为我是模板新手。 If you need any more information please let me know. 如果您需要更多信息,请告诉我。

Add a netstandard reference to your template: 将netstandard引用添加到您的模板:

<#@ assembly name="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" #>
<#@ assembly name="$(SolutionDir)\MultiApiConnector\bin\SqlFactory.dll"#>
<#+
    public string[] GetEntities()
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM