[英]A reference to “ .dll” this could not be added
在我的解決方案中的項目中,我有以下代碼來生成.dll程序集。 主要使用msdn文檔和stackoverflow上的另一個問題的答案開發。 代碼構建並運行正常,並在項目中的bin \\ debug文件夾中生成“.dll”程序集。 但是,我在解決方案中的其他項目中引用程序集時遇到問題。 我右鍵單擊references-> add reference並選擇“.dll”文件。 當我單擊確定時,我會收到此問題標題中所述的錯誤消息。 謝謝。
// Retrieve application domain ie environment where applications execute
// This is done because if an assembly is loaded into the default
// application domain it cannot be unloaded from memory while the process
// is running. However if another application domain is opened to load
// and execute the assembly, the assembly is unloaded when the application
// domain is unloaded.
AppDomain currentDomain = AppDomain.CurrentDomain;
// Now create a dynamic assembly in the current application domain
// and allow it to be executed and saved to disk
AssemblyName name = new AssemblyName("FieldIdEnum");
AssemblyBuilder assemblyBuilder = currentDomain.DefineDynamicAssembly(name,
AssemblyBuilderAccess.RunAndSave);
// Now we define a dynamic module in the assembly that was just created
// For this single single module assembly the module has the same name as
// the assembly
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(name.Name,
name.Name + ".dll");
// Now we define the public enumeration with the name "DbFieldId" and an
// underlying type of Integer
EnumBuilder myEnumBuilder = moduleBuilder.DefineEnum("EnumeratedTypes.DbFieldId",
TypeAttributes.Public, typeof(int));
// Now retrieve the FieldId table from the database, bear in mind that the
// string description will have white spaces, these need to be trimmed
// otherwise they are invalid for enum
// For this to work a reference was added to ConsoleApplication4 and
// Entity Framework
using (FieldIdEntities dbEntities = new FieldIdEntities())
{
var lines = dbEntities.CSV_FIELD_DETAILS;
foreach (var field in lines)
{
myEnumBuilder.DefineLiteral(field.DESCRIPTION.Replace(" ", String.Empty), (int)field.FIELD_ID);
}
}
// Now create the enum
myEnumBuilder.CreateType();
// If good so far save the assembly:
assemblyBuilder.Save(name.Name + "dll");
您是否嘗試將包含DLL的項目添加到同一解決方案中,然后在參考管理器中選擇
解決方案 - >項目 - > [您的dll項目]
那么visual studio會添加適當的dll本身?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.