Search code examples
c#windows-installervstovisual-studio-2017setup-deployment

Visual Studio Setup Project to target Public Documents folder


I'm using the extension Visual Visual Studio 2017 Installer Projects from Microsoft team to create an MSI Installer for a Visual Studio's desktop appliction. I've successfully created a SetUp Project and set all the necessary properties in the File System Editor of the SetUp project (Short Cut to dekstop, Program File's menu etc). The installer need to deploy an XML file to the Public Documents folder on the target computer. Question: how to target the Public Document Folder on the user's computer where the installer will install the app?

Background: This installer is built for an MS Office VSTO Add-In for WORD and it's deployment is done through Windows Installer (not through ClickOnce). And according to a licensing management system their XML Configuration file need to be deployed to the application directory that will not be our add-in's directory, but the directory of the application that loads the add-in. A recommended location for the XML file in this case would be a public folder such as the Public Documents folder on Vista and later versions of Windows.


Solution

  • I just clicked through the UI of VS2017 installer projects. I don't see a way to specify the public documents folder. You can add a user-defined folder (right click "file system" > add special folder > user defined folder) but it's limited to predefined properties of Windows Installer which doesn't include the public documents folder.

    If you only need to install into a common folder but don't require it to be the public documents folder, you could use the CommonAppDataFolder as an alternative. Specify that for DefaultLocation of user-defined folder.

    Otherwise you could possibly write a custom action that calls SHGetKnownFolderPath(FOLDERID_PublicDocuments,...) and assigns the result to a property. Then specify that property for DefaultLocation of user-defined folder. Here is a tutorial for writing a VB custom action for installer projects.

    Though I strongly suggest to get rid of installer projects altogether and use the WiX toolset instead which provides much more flexibility. It comes with a nice Visual Studio extension too. WiX already defines the property WIX_DIR_COMMON_DOCUMENTS that is initialized to the path of public documents folder. Example.