1

So I have files that are used in multiple projects (in one solution). Which way would I choose?

  • Embedded Resource and use with Assembly.GetManifestResourceStream
  • Add file to Resources.resx and use with Properties.Resources.
  • Copy to Output Directoryand use the known path to read
  • Linked Resource?

Right now the files reside inside a Resource-Folder in the root directory of the solution. But this way there is no relative path to these files.

I could add them to properties/resources but to which project? There is no "main" project that handles these files. Or create a new "ResourceHolder"-project just for resources?

If I add them to multiple projects they are all copies and not links to the original file/path as far as I know... so that's also no option.

Can't you add resources solution wide? Or better have a solution wide folder and only if a project uses a file it is then copied to output and can be used with a relative path?

1

1 Answer 1

2

There are no solution-wide resources, because there is no artifact produced by the solution itself. The place to put the resources depends, in my opinion, on the semantics of the resources.

If they are, for example, icons, which must be consistent over several assemblies (i.e. over several controls that reside in different assemblies or several different applications belonging to a set of applications), then they semantically are global resources. Hence, I would put them into a separate resource assembly that is referenced by all other assemblies.

If they are separate resources that just happen to be the same right now (i.e. test data for different test assemblies), then they have, in my opinion, no global semantics and should be copied into every project which requires them. This would then also allow to distribute the resulting assemblies independently as they have no further dependencies on each other.

Regarding your third option: I would always try to avoid working on files directly. This only may be applicable in two scenarios: First, if the files do not belong to the application, i.e. they are user data (such as documents read and written by the application); that doesn't seem to be the case her. Second, if the files are so large that duplicating them would result in a substantial demand of disk space. Your question does not read like that's the case, but in such a situation it might be feasible to provide a central repository of the data.

Sign up to request clarification or add additional context in comments.

4 Comments

So let's say I want to use solution 1. I know have a new project containing the resources. How do I access them from another project? They also should not be inside the .dll or .exe.
I would just add them to the normal resources of the project that is supposed to contain the global resources (i.e. with the Resources tab in the project settings) and set the access modifier of the resources to public. Then every project can reference the Resources class of this central project.
But then I can't easily change them. It is a requirement that they are locally available so others can just open the file with Paint / TextEditor/ Whatever and change contents.
Ok, in that case I wouldn't call them resources and I wouldn't put them in a resource project. In this case they are really more like user content and hence they should be deployed to the user's folder (into LOCALAPPDATA, if you would consider them to be configuration).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.