I have a .Net solution comprising several projects. One of these projects holds all the business logic on which depends a WPF project.
The business logic projects uses a bunch of resource files for different functionality.
Previously the two projects were only one, so what I did then is to set all these resource files to "Copy to Output Directory" to true. The running application composed the file paths as follows.
static readonly string ResourceFilePath =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"resources\\thefile.ext");
I know I can use resources and that works fine (except for the disappearance of the extension, and the replacement of .
characters with _
).
However, there are also times where I have directory tree holding a bunch of files. The running application copies the whole thing in some temporary location.
As with individual resource files, I had all the files set to be copied to the output directory in Visual Studio. The running application would compose the path of the directory, and then use that path to recursively copy everything to the temporary location.
static readonly string ResourceFilesPath =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"resources\\somedirectory\\");
public void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
...
This all worked well while debugging in Visual Studio, and also with the application installed. And because the files are on disk, they were individually version controlled.
My problem is with the second scenario where I copy a directory and file structure. I can't do that with resources, and now that the business logic is in a separate project, the resource files are not copied in the output directory of the front-end project.
My question is: are there better approaches to deal with many resources in some directory tree?
Maybe you can use GetAssembly or GetEntryAssembly to get a reference to the WPF assembly so the Location properly returns the desired output path?
Or you can set up build events for the business logic project to copy the resources to WPF project's output path.