Here is my project structure:
Here is my problem:
When I build my Web Application Project, the embedded resource in Class Library 2 is NOT copied to the bin directory of the Web Application Project as it should. If I add a project reference directly from my Web Application Project to Class Library 2, the file IS copied to the bin directory.
How can I get the embedded resource file to copy without having to add the unnecessary reference?
I think you need to mark it Content + Copy Always.
Refer to this page for details on the different Visual Studio file properties.
Update 1
Try creating a link to the file in your web application project. You can do this by...
Update 2
Using Content / Copy Always on any file in a referenced library project should cause the file to be copied to the bin folder of the main project. If the file is in a folder, it will be in that folder in the bin folder.
Make sure that if you are doing a Release build, you are looking bin/Release, and if you are doing a Debug build, you are looking in bin/Debug.
Also, try doing a Rebuild All.
Update 3
I see what you're saying now. When you reference a library DLL that is not in your solution, you are only referencing the DLL, not anything else that is in that project.
So, I think you are going to need to do one of the following...
MyLibraryContentFiles
that has only the content files of the library project, but not the code, and include this project in your solution. You might find that separating the content files from the code is advantageous anyway.Image
object. If it's a text file, you could return a plain string
.