views:

131

answers:

1

Here is my project structure:

  • Web Application Project
    • Has project reference to Class Library 1 in same Visual Studio 2008 solution
  • Class Library 1
    • Has project reference to Class Library 2 in same solution
  • Class Library 2
    • Has a file marked as Build Action: Embedded Resource and Copy to Output Directory: Copy Always

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?

A: 

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...

  1. Right-click your web project (or a folder inside it) using Solution Explorer
  2. Select Add > Existing Item
  3. Navigate to your file and select it
  4. Click the little arrow on the right side of the Add button and choose Add As Link

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...

  1. Include that project in your solution
  2. Link to the file (as in Update 1)
  3. Create a new project called something like 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.
  4. Embed any files you need within the library project (DLL) (using Embedded Resource), then provide a property on a public class that provides some kind of interface for referencing the file. If it's an image file, you could return an Image object. If it's a text file, you could return a plain string.
DanM
Thank you for your suggestion. I changed it to Content + Copy Always as you recommended, but it didn't solve the problem - it still isn't copied up to the web application's bin folder.
Aaron
@Aaron, I updated by answer. Hopefully, this will solve your problem now.
DanM
Thanks again for taking the time to try to help me figure this out. Your update definitely works in that the file is copied along with the web application, but it isn't copied in the bin folder next to the .dll that the class library creates.If I wanted the web application to have any direct relationship to class library 2 or any of the files in it, I would just add a reference to the class library 2 project in the web application. It just doesn't seem like I should have to do that - Visual Studio should recognize the Copy Always and copy it up to the web applications bin folder.
Aaron
@Aaron, I just went into an ASP.NET app and added a file to one of my library apps. I set it to Content / Copy Always. I didn't copy or link anything. I built the solution. And it turns out, it *does* copy the file into the bin folder. So, I'm not sure why it's not working for you. I did another update to my answer.
DanM
@DanM Is your library app referenced directly by the ASP.NET app? I've had the same results where it copies it correctly if it is directly referenced, but, as in this case, it does not copy it if the file is in a class library that is not directly referenced. Does that make sense?
Aaron
@Aaron, I see what you're saying...Another update :)
DanM
@DanM Apologies for not making myself clear. All 3 projects mentioned in my original question are in the same solution, and all of the references are project references (not a reference just to the dll file).
Aaron