Including xml files when deploying WPF application

亡梦爱人 提交于 2019-12-23 08:05:07

问题


I have a WPF application with 3 projects to represent a 3-layer architecture. One project is set as the main project. I have some XML files in one of the non-main project. These XML files are accessed by functions defined in classes of that project.

When I try to publish the application using VS2010 ClickOnce, the XML files are not included in the installation file even after marking the files' Build Action to Content and Copy-to-OutputDirectory as Copy Always. When running the installed application, the application reports that the files are not found. I can see an Application_Files folder in the installation folder generated by ClickOnce, but it does not contain the XML files.

So, my question is how can I include the XML files in the installation folders and also get their location URL while running the application.

Thanks, Naveen

Update 1: The application solution structure consists of three projects, say P1, P2, and P3. P3 is the main startup project. P1 and P2 are class library projects. The XML files are added to the P2 project. The files are marked as Build Action -> Content and Copy -> Copy Always. However, these files are not copied to the application's data folder by ClickOnce while publishing the application.


回答1:


Simple Solution. Right click on yo project file which you want to publish. Select properties. Then select publish in the opened window. Click on Apllication files button. There, find yo .xml file, which will of type 'Data file' by default. Change it to Include. Save Rebuild and publish and thats it.

Hope it helps someone in need of it.




回答2:


there a 2 locations clickonce uses:

  • a location for the main executable and all necessary dll's
  • a location for everything that isn't executable, i.e. resources, like your xml

so you have an application directory and a data directory. Addressing the application dir can still be done like this AppDomain.CurrentDomain.BaseDirectory.

But if you want to address the data dir, you need something specific for the clickonce: ApplicationDeployment.CurrentDeployment.DataDirectory.

I'm not sure if you have checked that data dir, because you haven't mentioned it in your post.



来源:https://stackoverflow.com/questions/5547846/including-xml-files-when-deploying-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!