views:

84

answers:

2

I have a library project that has some content files (e.g., XML and schema files, image files, etc.) all with Build Action set to Content (copy always).

This library project lives in a Visual Studio solution that also has a test application (WPF) that references the library.

When I build the solution, all the content files from the dependent library project get copied to the bin folder of my test application. (They also get copied to the bin folder of the library project.)

Today, I gave the assembly dll generated by my library project to another programmer for him to reference. It didn't even occur to me, however, that this was not enough. I needed to give him the content files as well. So I did, and he added them to his project.

This solution works, but I'm uncomfortable with it. I don't like that the content files are mixed in with his project files. This makes it more likely they could be accidentally changed or deleted.

So, I'm hoping I can get some advice on how to share libraries with other programmers when content files are involved.

Note: It's not that I'm trying to hide the content files (it's actually important that programmers referencing this library have access to them), but I would like them to remain separate from the referencing project yet still get copied properly to the bin folder when their project is compiled. I guess what I'm saying is, I want it to be as if they have the library project in their solution, just not the code files and xaml files.

Thanks.

EDIT:

One idea that occurs to me is that I could copy just the folder structure and content files from my library project into a new class library project. Then, anyone referencing my library project could add this minimal class library in their solution. They would still have to reference the dll as a separate step, but this is definitely better than the current solution. Maybe I could even write a post-build event that automatically copies all content files from my library project to the minimal class library. (Now, I just have to research how to actually write a build event :)). Comments welcome.

EDIT 2:

I built on my original edit to come up with a solution I think I'm going to be happy with. See my answer below.

+2  A: 

Make the content files embedded resources. You can then get at them with Assembly.GetManifestResourceStream(). It makes your assembly a lot more portable - you're no longer relying on file system locations at execution time.

Jon Skeet
@Jon, that would definitely solve the portability issue, but I need the "customers" of this library to be able to view the content files, which is why I made them content in the first place.
DanM
@DanThMan: Could you write a separate tool (or method) to extract the resources for those that need them as separate files, but keep them in the assembly for those that don't?
Jon Skeet
@Jon, Hmm, do you mean build a custom installer for my library project that installs the dll and content files directly into the bin folder of the referencing application? I'm sure something like this is possible, but it sounds like a bit of an undertaking.
DanM
Not an installer just a separate executable. Part of the problem is that I don't know what your library is for, who your customers are or why they need to see the files within the file system.
Jon Skeet
@Jon, This is a little bit tricky to explain, but one of the issues is that I have an XML Schema Set that contains xsd files from both the referencing application *and* the referenced library. Specifically, the application extends the referenced xsd file using an <xs:redefine> element, adding additional "table" elements to the base tables the library needs. This results in one big schema that contains all the tables and the keys/keyrefs to establish referential integrity. So, the referencing application needs access to the xsd files from the referenced library.
DanM
How are they doing this XSD manipulation? It seems they could call some function your library provides which returns the file as a string. If that worked, then your implementation of the library could use Jon's suggestion.
Frank Schwieterman
@Frank, That's definitely a good runtime solution, but it's hard to to extend (redefine) a schema file you can't see. It's also very helpful to have the design-time validation of XML files you get if all the xsd files are physically available.
DanM
A: 

I decided to remove the content files from the library project and put them in a new "content-only" library project that contains only content. If anyone needs to use the library project, I just share the dll and the content-only library project folder. This way, the relationship between projects and content files in the solution folder remains exactly the same, and everything updates automatically when I compile.

DanM