Visual Studio 2010: How refer to a C# .Net class l

2019-06-25 13:34发布

This is probably a very basic question but I haven't found any detailed information about how project references works in Visual Studio.

I have a Visual Studio 2010 C# solution containing a MainApp project and a C# class library project with third party assemblies inside. When referring to the class library project from the MainApp project, should I just add a project reference or do I need to add references to the third party assemblies within the class library project as well?

In some cases it seems like the third party assemblies are not loaded correctly if I just have the Class Library project reference in my MainApp project although all DLL files (incl third party DLLs) show up in the output folder when building the complete solution.

Edit: I've posted a more specific question since the general answer did not help in my case: How to refer self-contained C# class library project with IronPython inside (Visual Studio 2010)

1条回答
可以哭但决不认输i
2楼-- · 2019-06-25 13:47

When using thrid party assemblies/dlls I find it bect to create a folder in a project called "Dependencies" and place them in there, that way they don't get lost or hidden in amongst your source.

Your class library project should reference the thrid party assemblies. You'll need to browse for those (after clicking add reference) and then set the Copy Local property True, that way they will be copied to the directory into which any compiled code is placed.

Your other project just needs to reference your class library project(remember to set the Copy Local property), select it from the Projects list after clicking add reference.

Oh I forgot to add your code files that refer to any publics on the referenced assemblies will require a using statement to link to them.

查看更多
登录 后发表回答