Visual Studio安装程序:如何定位Windows公共文档文件夹? [英] Visual Studio Installer: How to Target Windows Public Documents Folder?

查看:117
本文介绍了Visual Studio安装程序:如何定位Windows公共文档文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个桌面应用程序,该应用程序需要将SDF文件安装到SpecialFolder.CommonDocuments文件夹(在Win 7中为C:\Users\Public\documents).在Visual Studio桌面部署项目中,如何在文件系统编辑器中指定此文件夹?

I am creating a desktop app that needs to install an SDF file to the SpecialFolder.CommonDocuments folder (C:\Users\Public\documents in Win 7). In a Visual Studio desktop Deployment Project, how do I specify this folder in the File System Editor?

我尝试在文件系统编辑器中创建一个自定义文件夹,并将其指向属性"窗格中的CommonDocuments文件夹,如下所示:

I tried creating a custom folder in the File System Editor and pointing it to the CommonDocuments folder in the Properties pane, like this:

不幸的是,该规范无法建立.我不想对文件夹路径进行硬编码,因为在Windows版本之间它会有所不同.那么,如何在文件系统编辑器中指定CommonDocuments文件夹?感谢您的帮助.

Unfortunately, that specification won't build. I don't want to hard-code a folder path, since it varies between Windows versions. So, how do I specify the CommonDocuments folder in the FileSystem Editor? Thanks for your help.

推荐答案

我弄清楚了这一点,并出于内部目的将其记录在案.因此,我将在此处重新打印该文章:

I figured this one out and documented it for internal purposes. So, I'll just reprint that writeup here:

Visual Studio部署项目不直接支持CommonDocuments文件夹,但是我们可以使用具有搜索目标计算机"任务的启动条件编辑器来添加该支持.我们将使用该任务在Windows注册表中搜索公共文档"文件夹的路径,并将结果分配给名为COMDOCFOLDER的安装程序属性(实际上是变量).然后,我们将使用该变量在文件系统编辑器中将路径设置为自定义文件夹.

Visual Studio deployment projects don't support the CommonDocuments folder directly, but we can add that support by using the Launch Conditions Editor, which has a "Search Target Machine" task. We will use the task to search the Windows registry for the path to the Public Documents folder and assign the result to an installer property (actually a variable) called COMDOCFOLDER. We will then use that variable to set the path to a custom folder in the File System Editor.

以下是执行任务的步骤.首先,在Visual Studio部署项目中打开启动条件编辑器":

Here are the steps to perform the task. First, open the Launch Conditions Editor in a Visual Studio deployment project:

右键单击搜索目标计算机",然后从上下文菜单中选择添加注册表搜索".将会出现一个新项目(请参阅上面的1).将其命名为Get Common Documents Folder.在属性窗格中(请参见上面的2),将属性"属性(我们的变量的名称)设置为COMDOCFOLDER,将"Root"属性(要搜索的注册表根键)设置为vsdrrHKLM,然后将将'RegKey'属性(要找到的注册表项)更改为SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders.请注意,我们从"RegKey"属性中省略了根密钥.最后,将'Value'属性(我们在注册表项中搜索的值的名称)设置为Common Documents.现在,COMDOCFOLDER变量将保存公共文档"文件夹的路径.

Right-click 'Search Target Machine' and select 'Add Registry Search' from the Context menu. A new item will appear (see 1 above). Name it Get Common Documents Folder. In the properties pane (See 2 above), set the 'Property' property (the name of our variable) to COMDOCFOLDER, set the 'Root' property (the Registry root key to search) to vsdrrHKLM, and set the 'RegKey' property (The Registry key to find) to SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. Notice that we omitted the root key from the 'RegKey' Property. Finally, set the 'Value' property (The name of the value we are searching for within the registry key) to Common Documents. The COMDOCFOLDER variable will now hold the path to the Public Documents folder.

下一步,转到Visual Studio部署项目中的文件系统编辑器:

Next, go to the File System Editor in the Visual Studio deployment project:

右键单击目标计算机上的文件系统",然后从上下文菜单中选择添加特殊文件夹>自定义文件夹".将会出现一个新项目(请参阅上面的1).重命名项目Common Documents.在属性窗格中(请参见上面的2),将属性"属性设置为COMDOCFOLDER.我将"DefaultLocation"属性设置为Windows Vista及更高版本的CommonDocuments文件夹的硬编码值;仅当COMDOCFOLDER属性返回空值(不应该发生)时,才使用此值.安装程序现在有一个Common Documents文件夹,该文件夹指向Windows注册表中指定的Public Documents文件夹.

Right-click 'File System on Target Machine' and select 'Add Special Folder > Custom Folder' from the context menu. A new item will appear (see 1 above). Rename the item Common Documents. In the properties pane (See 2 above), set the 'Property' property to COMDOCFOLDER. I set the 'DefaultLocation' property to the hard-coded value of the CommonDocuments folder for Windows Vista and later; this value would only be used if the COMDOCFOLDER property returned a null value, which shouldn't happen. The installer now has a Common Documents folder that points to the Public Documents folder, as specified in the Windows Registry.

在此Microsoft支持方法中有更多信息.

There is more information in this Microsoft Support How-To.

这篇关于Visual Studio安装程序:如何定位Windows公共文档文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆