Using environment variable in VSTO 2007 Deploy Manifest PathI would like to deploy a document-level customization to each end user's computer. I found an article about this <a href="http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx">http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx</a>  <div>This article refers to u<span style="line-height:15px">pdating the embedded application manifest so that it uses an environment variable to point to the assembly. It says that instead of using a specific drive letter and path, use %ProgramFiles% or %UserProfile% to begin the path. However, there is no example with code which use environment variables.</span></div> <div><span style="line-height:15px"><br/></span></div> <div><span style="line-height:15px">I found few threads where people tried to do this, but their methods didn't help.</span></div> <div><span style="line-height:15px">I'm asking for help.</span></div> <div><span style="line-height:15px"><br/></span></div> <div><span style="line-height:15px">I use such part of code for updating manifest path in the document</span></div> <div><span style="line-height:15px"> <pre lang="x-c#">string targetLocation = &quot;C:\\Program Files\\DEV\\Reporter\\Report.docx&quot;; string assemblyLocation = @&quot;%ProgramFiles%\DEV\Reporter\BSReportTemplate.dll&quot;; Uri deploymentManifestLocation = new Uri(@&quot;%ProgramFiles%\DEV\Reporter\BSReportTemplate.vsto&quot;, UriKind.Relative); if (ServerDocument.IsCustomized(targetLocation)) { ServerDocument.RemoveCustomization(targetLocation); } ServerDocument.AddCustomization( targetLocation, assemblyLocation, SolutionID, deploymentManifestLocation, false, out nonpublicCachedDataMembers);</pre> <span style="line-height:normal"> <div>When i run my code the DirectoryNotFoundException occurred with such error: The system cannot find the path specified. (Exception from HRESULT: 0x80070003).</div> <div>I checked everything, all files really exist in this directory, but i think %ProgramFiles% variable doesn't want to work.</div> <div><br/></div> <div>I don't know what to do, please help.</div> <div><br/></div> <div>Thanks in advance.</div> <div><br/></div> <div><br/></div> <div><br/></div> <div><br/></div> </span></span></div>© 2009 Microsoft Corporation. All rights reserved.Sat, 04 Jul 2009 20:59:42 Zf09c5513-b4c9-41b3-b99c-a31fefac71f3http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f09c5513-b4c9-41b3-b99c-a31fefac71f3http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f09c5513-b4c9-41b3-b99c-a31fefac71f3Stanislav Kroschenkohttp://social.msdn.microsoft.com/Profile/en-US/?user=Stanislav%20KroschenkoUsing environment variable in VSTO 2007 Deploy Manifest PathI would like to deploy a document-level customization to each end user's computer. I found an article about this <a href="http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx">http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx</a>  <div>This article refers to u<span style="line-height:15px">pdating the embedded application manifest so that it uses an environment variable to point to the assembly. It says that instead of using a specific drive letter and path, use %ProgramFiles% or %UserProfile% to begin the path. However, there is no example with code which use environment variables.</span></div> <div><span style="line-height:15px"><br/></span></div> <div><span style="line-height:15px">I found few threads where people tried to do this, but their methods didn't help.</span></div> <div><span style="line-height:15px">I'm asking for help.</span></div> <div><span style="line-height:15px"><br/></span></div> <div><span style="line-height:15px">I use such part of code for updating manifest path in the document</span></div> <div><span style="line-height:15px"> <pre lang="x-c#">string targetLocation = &quot;C:\\Program Files\\DEV\\Reporter\\Report.docx&quot;; string assemblyLocation = @&quot;%ProgramFiles%\DEV\Reporter\BSReportTemplate.dll&quot;; Uri deploymentManifestLocation = new Uri(@&quot;%ProgramFiles%\DEV\Reporter\BSReportTemplate.vsto&quot;, UriKind.Relative); if (ServerDocument.IsCustomized(targetLocation)) { ServerDocument.RemoveCustomization(targetLocation); } ServerDocument.AddCustomization( targetLocation, assemblyLocation, SolutionID, deploymentManifestLocation, false, out nonpublicCachedDataMembers);</pre> <span style="line-height:normal"> <div>When i run my code the DirectoryNotFoundException occurred with such error: The system cannot find the path specified. (Exception from HRESULT: 0x80070003).</div> <div>I checked everything, all files really exist in this directory, but i think %ProgramFiles% variable doesn't want to work.</div> <div><br/></div> <div>I don't know what to do, please help.</div> <div><br/></div> <div>Thanks in advance.</div> <div><br/></div> <div><br/></div> <div><br/></div> <div><br/></div> </span></span></div>Mon, 29 Jun 2009 19:20:24 Z2009-06-29T19:20:24Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c9e24a35-f704-40c6-9be0-65800eb6564ahttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c9e24a35-f704-40c6-9be0-65800eb6564aMary Lee - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Mary%20Lee%20-%20MSFTUsing environment variable in VSTO 2007 Deploy Manifest Path<pre lang="x-c#"> string assemblyLocation = @&quot;DEV\Reporter\BSReportTemplate.dll&quot;; string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string targetLocation = System.IO.Path.Combine(programFilesPath, assemblyLocation); </pre> <p>i think the problem is that you put the environment variable into a string, so the path never gets expanded to the full directory path.<br/><br/>instead of using the environment variable with % signs, try using the Environment.GetFolderPath method to retrieve the actual Program Files directory path. then use System.IO.Path.Combine to create your fully qualified path.<br/><br/>m.</p>Tue, 30 Jun 2009 16:47:02 Z2009-06-30T16:47:02Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f3474aad-5983-420d-8eb8-21093f1c0719http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f3474aad-5983-420d-8eb8-21093f1c0719Stanislav Kroschenkohttp://social.msdn.microsoft.com/Profile/en-US/?user=Stanislav%20KroschenkoUsing environment variable in VSTO 2007 Deploy Manifest PathThe reason why i would like to use environment variable is that for example windows can be installed on different partitions, and their letters will be different, for example on one PC it will be &quot;C:\Program Files\&quot; on another &quot;D:\Program Files\&quot;. <div><br/></div> <div>For this reason i want to put environment variable inside embedded assembly path, and it will be retrieved when document will be opened. I hope that in such way all should work, but I don't know how to do it correctly.</div>Tue, 30 Jun 2009 16:59:59 Z2009-06-30T16:59:59Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c7182d11-26fa-4447-a566-b58cf86c8044http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c7182d11-26fa-4447-a566-b58cf86c8044Mary Lee - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Mary%20Lee%20-%20MSFTUsing environment variable in VSTO 2007 Deploy Manifest Pathone problem is that <a href="http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx">http://msdn.microsoft.com/en-us/library/xbys5fef(VS.80).aspx</a> refers to Office 2003 and the VSTO 2005 SE runtime.  VSTO 3.0solutions for Office 2007 don't use embedded manifest paths.  which version of the VSTO runtime and Visual Studio are you using?<br/><br/>m.Tue, 30 Jun 2009 19:17:50 Z2009-06-30T19:17:50Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#2602b385-487d-4b5a-b8e6-c1950500a7f0http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#2602b385-487d-4b5a-b8e6-c1950500a7f0Stanislav Kroschenkohttp://social.msdn.microsoft.com/Profile/en-US/?user=Stanislav%20KroschenkoUsing environment variable in VSTO 2007 Deploy Manifest PathI'm using Visual Studio 2008 and VSTO runtime v9.0 for Office 2007. <div>And what do you mean, that new version of runtime doesn't support environment variables? </div>Wed, 01 Jul 2009 17:16:55 Z2009-07-01T17:16:55Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#ee22bc7f-aa51-4ed5-a62c-3a437dd4d698http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#ee22bc7f-aa51-4ed5-a62c-3a437dd4d698Mary Lee - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Mary%20Lee%20-%20MSFTUsing environment variable in VSTO 2007 Deploy Manifest Path<p>the link that you are reading has a box in the upper right that says the following:</p> <div>This page is specific to <span><strong>Microsoft Visual Studio 2005/.NET Framework 2.0 </strong></span></div> <div class=title> <div>Other versions are also available for the following: <a href="http://msdn.microsoft.com/en-us/library/xbys5fef(VS.90).aspx"><span style="color:#0033cc">Microsoft Visual Studio 2008/.NET Framework 3.5</span></a></div> </div> <p>if you look at the VS2008 version of the link, the topic is marked for apply to Office 2003 only. in the VSTO 2005 SE runtime, customized documents have an embedded application manifest that points to a deployment manifest somewhere else.<br/><br/>in the VSTO 3.0 runtime, the customized document has a link to a deployment manifest.  the link must be a file path that can be relative (OfficeSolution.vsto) or fully qualified (c:\OfficeSolution.vsto).  see <a href="http://msdn.microsoft.com/en-us/library/ds87aeyf.aspx">Custom Document Properties Overview</a> for more information.<br/><br/>if you run the GetFolderPath method on the end user's computer, that will retrieve and evaluate environment variables for you.  the only difference is that it's not represented as %.<br/><br/>i have some questions about your scenario. ClickOnce installation is a per-user install, and on newer OSes (Vista, Win7), user accounts don't have access to the program files directory.  is the DLL being installed there with an MSI?  if you are deploying a DLL and a document, ClickOnce will automatically put the DLL into the ClickOnce cache, a hidden directory in each user's profile directory.  this way, you don't have to re-attach the assembly to the document after you deploy this Office solution and you can avoid using ServerDocument.  can you store your assembly on a network file share or web site with address does not change drive letters?  the users will have to be networked when they install the VSTO solution, but afterwards, they can be offline.<br/><br/>m.</p>Wed, 01 Jul 2009 17:47:25 Z2009-07-01T17:47:25Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c8f73fd6-1344-42b1-b365-2e5fef022043http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#c8f73fd6-1344-42b1-b365-2e5fef022043Stanislav Kroschenkohttp://social.msdn.microsoft.com/Profile/en-US/?user=Stanislav%20KroschenkoUsing environment variable in VSTO 2007 Deploy Manifest PathI didn't understand you when you said about GetFolderPath, where i should run GetFolderPath on end user's computers. Could you explain, please. <div><br/></div> <div>I use VSTO 3.0 runtime and as you said, the customized document has a link to a deployment manifest which can be relative, can i use there environment variables?</div> <div><br/></div> <div>The DLL is being installed with an MSI, you are right. So you mean that on newer OSes it won't work, if I install them to the program files directory?</div> <div><br/></div> <div>Can you tell me please, why ClickOnce will put the DLL into the ClickOnce cache, not to the program files? Is there any articles about this?</div> <div><br/></div> <div>Yes, I can store my assembly on a web site, but i didn't know that I will need to download assembly only once, why?<br/> <div><br/></div> <div><br/></div> </div>Wed, 01 Jul 2009 18:25:17 Z2009-07-01T18:25:17Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#2722f438-8544-4e4c-8f36-eac914c0f682http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#2722f438-8544-4e4c-8f36-eac914c0f682Mary Lee - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Mary%20Lee%20-%20MSFTUsing environment variable in VSTO 2007 Deploy Manifest Pathyou can use ServerDocument in a console app and call GetFolderPath on the end user computer.<br/><br/>i am not sure if you can use environment variables in the deployment manifest path.<br/><br/>on newer OSes, installing to the Program Files directory requires elevated privileges for the MSI.  if the user is not an administrator, the installer will not work.  ClickOnce always installs to the user's profile directory, so files never have to go into the Program Files directory. for more information about the ClickOnce cache, see <a href="http://msdn.microsoft.com/en-us/library/267k390a.aspx">ClickOnce Cache Overview</a>.  if you store the assembly on a website, the assembly is installed into the ClickOnce cache.  this enables an offline experience for your customers, and also allows you to update the assembly on the website.  at specified intervals, the application can go to the website and install the latest assembly.<br/><br/>m.<br/>Thu, 02 Jul 2009 21:15:04 Z2009-07-02T21:15:04Zhttp://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f780ef2a-75ca-4ba7-a5dc-68ebcf4cb6e7http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/f09c5513-b4c9-41b3-b99c-a31fefac71f3#f780ef2a-75ca-4ba7-a5dc-68ebcf4cb6e7Stanislav Kroschenkohttp://social.msdn.microsoft.com/Profile/en-US/?user=Stanislav%20KroschenkoUsing environment variable in VSTO 2007 Deploy Manifest PathThanks a lot.<br/>I solved my problem with ClickOnce installation.Sat, 04 Jul 2009 20:59:42 Z2009-07-04T20:59:42Z