how do I mark a file as a data file in a visual studio 2010 vsto clickonce application?

馋奶兔 提交于 2019-12-11 04:29:32

问题


I'm making a Word 2007 add-in with C# 4.0 in Visual Studio 2010. I need an Access 2007 database (a .accdb file) to be placed in the data directory by the clickonce installer. Unfortunately, the file is getting put elsewhere, so the application can't find it at runtime. I've seen various articles refer to using the Application Files dialog on the Publish tab of the project properties to mark the file as a data file, but I have no Application Files button for some reason.

Any idea how to make the Application Files dialog appear, or some other way to manually mark my .accdb file as a data file?


回答1:


In the Solution Explorer, if you set the file's property to be Copy to Output Directory = Copy Always. Then when you go to Application Files they should default as a Data File.

However, since this is your database I would consider looking at make it safe across updates so you might consider this post.

See http://msdn.microsoft.com/en-us/library/dd465298.aspx

By the way, "Application Files" button should be on the project properties' Publish tab.




回答2:


VSTO Applications do not have the Application Files button available, and you can't set the file types specifically. If your file is not being deployed to the data directory and you want it to be, rename it with a file extension that is marked by ClickOnce as data. This includes .xml, .mdb, and .mdf. Otherwise, the file is deployed with the VSTO application and will be in the same location as the rest of the files.

The location of the deployment files for a VSTO application can be discovered programmatically this way:

System.Reflection.Assembly.GetExecutingAssembly.CodeBase

You might want to move the database, though, because unless you deploy it as data, it will be lost when an update is performed. Or you can check out this article about where to put your data to keep it safe from ClickOnce updates.




回答3:


I was able to get things to work by using the Mage tool as described here:

http://msdn.microsoft.com/en-us/library/6fehc36e.aspx

The trick with MageUI is it's open file dialog assumes you want to open a manifest associated with a .exe; a vsto project has a .dll, so the manifest doesn't appear in the files list by default, which was really tripping me up.

Basically, this process is a pain because you have to remember to do it manually. I don't know if there's a way to make this part of the build (maybe a post-build step? But this is really a post-publish step).



来源:https://stackoverflow.com/questions/3153672/how-do-i-mark-a-file-as-a-data-file-in-a-visual-studio-2010-vsto-clickonce-appli

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