开发者

How can I automatically include a custom configuration file from my class library into my executable project during release?

开发者 https://www.devze.com 2023-04-13 00:27 出处:网络
I have a VS2008 solution which contains a number of class libraries plus an executable project (a windows service). One of my class libraries is a wrapper for a 3rd party component which allows for a

I have a VS2008 solution which contains a number of class libraries plus an executable project (a windows service). One of my class libraries is a wrapper for a 3rd party component which allows for a great deal of configuration so I created a custom XML document called 3rdPartyConfig.xml and a strongly-typed parsing class called 3rdPartConfig.cs.

Since my executable project references that class library, when the app runs it's going to look for the XML file in it's executing location. To do this, I have set the following properties on 3rdPartyConfig.xml:

  • set Build Action = Content.
  • set Copy to output Directory = Copy always

When I run in Debug configuration I can see 3rdPartyConfig.xml has been copied to the build output folder . The app runs fine and is able to read the file. However, when I publish as Release, Visual Studio does not copy the XML file, so when the ap开发者_StackOverflow中文版p runs it cannot find it.

What can I do to ensure my custom configuration file is included in the Release build output? Do I need to write a pre- or post-build script?

Caveats:

  • I know that a workaround would be to scrap the XML file and add the configuration to the app.config. I have been asked to not do it that way (client wants to be able to substitute configuration files easily).
  • Another workaround would be to store the configuration info in a database. The client would prefer not to do that either.
  • I have adjusted for the fact that "executing location" gets nebulous when dealing with windows services. Rest assured my code does check in the installed location, not c:\windows\system32.

Thanks!


Just edit the "Copy To Output Directory" property in the solution for your file:

How can I automatically include a custom configuration file from my class library into my executable project during release?


Could you not just add the config file as a link to the executable project and set it to copy to the release directory if newer?

0

精彩评论

暂无评论...
验证码 换一张
取 消