Reputation: 2708
I have create a windows service app with resources (.resx) files on it. Now my problem is when I install my service using a setup project. It seems that it can't find my .resx file. What do I need to do so that my resources file can be embedded to my program?
Update
Fixed it. @UnhandledException is correct. That is one way to fixed the issue but for some reason it's not working for me. What I did to fixed it is to show all files within my project on Visual studio. I browse through bin\debug
. I found the resources file which actually has ".resources" extension to it. I copied it to c:\Program Files\my app\
and voila, it worked. It may not be the right approach but I need it this time.
Thanks,
Upvotes: 0
Views: 6070
Reputation: 24922
If you are running a Windows Service application and need to access a resource, mark that resource as, Build Action: Embedded Resource, and use the below code to get the absolute path to your resource file:
/// <summary>
/// This method seems a bit complicated for fetching a file's path,
/// but it's flexible enough to fetch a path for both console
/// applications and service applications.
/// </summary>
/// <param name="relativePath">Relative path to a resource.</param>
/// <returns>Absolute path.</returns>
private string GetAppAbsolutePath(string relativePath)
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), relativePath);
}
Hope this helps.
Upvotes: 0
Reputation: 63065
Changed the Build Action to Embedded Resource in properties of resources (.resx) file and each files inside resources.
Upvotes: 2