Deploy external file in c# solution with clickonce

做~自己de王妃 提交于 2019-12-10 17:14:09

问题


I've a problem with Visual Studio Express 2010 c# edition. I've a project that reference a DLL. This DLL has an external Excel file marked as Build Action = Content Copy to Output Directory = Copy Always

When I build the solution, this Excel file is correctly copied into BIN\release solution folder.

BUT if I try to deploy the same solution, with Publish wizard, the Excel file is not copied in the install directory.

Please, could anyone help me?


回答1:


Are you saying that the Excel file is referenced only by the dll you are including in your project? That is a secondary reference, and ClickOnce will not see it and automatically include the file.

First, on your dll, I'm assuming it is referenced directly by your project. If so, then be sure you have added it to your project and set the Build Action to "none" and "copy to output directory" to "do not copy". Then delete your reference to it and re-add it, pointing it to the version now included in your project. Set the "copy local" property to "true". This will ensure the dll itself gets deployed correctly.

For the Excel file, you are going to have to add it to your project. Set the build action to "content" and set "copy to output directory" as "copy always". It will not be included automatically because it is a secondary reference to the ClickOnce app, not a direct/primary reference like the dll is.




回答2:


Open the Publish properties for your ClickOnce project. Then click on the 'Application Files ...' button. That launches a dialog where you can control which files are being included in the publishing package.

In order for your XLSX file (or any other non build file) to appear in that dialog you need to mark is as 'Content' in the Build Action of the properties window.




回答3:


Try to include this file into solution and set "Copy to Output Directory" to "Copy always"




回答4:


It appears your file is not listed in the "PublishFiles" list. Open the Projects Properties, go to "Publish" Tab, click on "Application Files" button, make sure you see the DLL file in the list of files with Publish Status as "Include".




回答5:


You could avoid the problem by inserting the Excel file as a resource, then writing it out like this:

File.WriteAllBytes(DestinationFileName, Properties.Resources.MyResourceFile);

I'm making an assumption that the Excel file is some kind of template you are using to build an output file from.



来源:https://stackoverflow.com/questions/7729202/deploy-external-file-in-c-sharp-solution-with-clickonce

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