To learn more about Visual Studio 2010 and .NET Framework 4, Kathleen McGrath is highlighting new documentation about these products with a weekly blog post and a daily tweet. If you want to learn more about the new features and scenarios, check out her blog at http://blogs.msdn.com/kathleen and her twitter feed at http://twitter.com/kathleenmcgrath.
Mary Lee, Programming Writer.
Starting in Visual Studio 2010 Beta 1, you can perform additional tasks after an Office solution is installed known as a post-deployment action. For example, you can copy a customized Office document and create registry keys on the end user computer. You can compare these to Windows Installer custom actions.
The Visual Studio Tools for Office runtime supports the ability to perform post-deployment actions after an Office solution is installed. However, Visual Studio does not generate the necessary sections of the ClickOnce application and deployment manifests to perform these actions. To run these post-deployment actions, you must modify the application and deployment manifests. This process is demonstrated in the Walkthrough: Copying a Document to the End User Computer after a ClickOnce Installation topic in the MSDN Library.
The walkthrough uses an Excel workbook project, but this example uses a Word document project for demonstration purposes.
1. Create a new Word document-level project that targets the .NET Framework 3.5 named FabrikamWordDocument.
2. Add code to the FabrikamWordDocument project.
3. Build the project.
1. Create a class library called FileCopyPDA.
2. Add references to Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0 and Microsoft.VisualStudio.ToolsApplications.ServerDocument.v10.0.
3. Rename the class to FileCopyPDA.
4. Replace the FileCopyPDA class with the following code that completes the following tasks:
Copies the Word document file to the user's desktop if the solution is installed or updated.
Changes the _AssemblyLocation property from a relative path to a fully qualified path for the deployment manifest. This is done using the AddCustomization and RemoveCustomization methods.
Deletes the file if the solution is uninstalled.
Public Class FileCopyPDA Implements IAddInPostDeploymentAction Sub Execute(ByVal args As AddInPostDeploymentActionArgs) Implements IAddInPostDeploymentAction.Execute Dim dataDirectory As String = "Data\FabrikamWordDocument.docx" Dim file As String = "FabrikamWordDocument.docx" Dim sourcePath As String = args.AddInPath Dim deploymentManifestUri As Uri = args.ManifestLocation Dim destPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) Dim sourceFile As String = System.IO.Path.Combine(sourcePath, dataDirectory) Dim destFile As String = System.IO.Path.Combine(destPath, file) Select Case args.InstallationStatus Case AddInInstallationStatus.InitialInstall, AddInInstallationStatus.Update File.Copy(sourceFile, destFile) ServerDocument.RemoveCustomization(destFile) ServerDocument.AddCustomization(destFile, deploymentManifestUri) Exit Select Case AddInInstallationStatus.Uninstall If File.Exists(destFile) Then File.Delete(destFile) End If Exit Select End Select End Sub End Class
5. Build the FileCopyPDA project.
6. Add a reference to FileCopyPDA.dll in the FabrikamWordDocument project.
7. Create a directory called “Data” in the FabrikamWordDocument project.
8. Add the FabrikamWordDocument.docx file to the Data folder.
9. In Properties window for the FabrikamWordDocument.docx file, change the Build Action property to Content, and change the Copy to Output Directory property to Copy if newer.
10. Publish the FabrikamWordDocument project. This example uses the c:\publish directory.
1. Open the C:\publish\Application Files\FabrikamWordDocument_1_0_0_0\FabrikamWordDocument.dll.manifest file in the XML Editor in Visual Studio.
2. Add the following XML code after the </vstav3:update> element to run the FileCopy post-deployment action.
<vstav3:postActions> <vstav3:postAction> <vstav3:entryPoint class="FileCopyPDA.FileCopyPDA"> <assemblyIdentity name="FileCopyPDA" version="1.0.0.0" language="neutral" processorArchitecture="msil" /> </vstav3:entryPoint> <vstav3:postActionData> </vstav3:postActionData> </vstav3:postAction> </vstav3:postActions>
To prove that yes, you really meant to make these changes to the application manifest, you must re-sign the application manifest with a certificate. Then, re-sign and update the deployment manifest to point to the new application manifest.
1. Copy your certificate to the C:\publish\Application Files\FabrikamWordDocument_1_0_0_0 directory. In this example, I’m reusing the temporary certificate created by Visual Studio because I’ll be installing this to a test computer. For production deployment, we recommend that you use a certificate obtained from a certificate authority.
2. In a Visual Studio command prompt, change to the C:\publish\Application Files\FabrikamWordDocument_1_0_0_0 directory. (You may have to open the command prompt in Administrator mode to re-sign the files in the c:\publish directory.)
3. Re-sign the application manifest with the following command:
mage -sign FabrikamWordDocument.dll.manifest -certfile FabrikamWordDocument_TemporaryKey.pfx
4. Change to the c:\publish directory
5. Re-sign the deployment manifest with the following command (on one line):
mage -update FabrikamWordDocument.vsto
–appmanifest "Application Files\FabrikamWordDocument_1_0_0_0\FabrikamWordDocument.dll.manifest"
-certfile "Application Files\FabrikamWordDocument_1_0_0_0\FabrikamWordDocument_TemporaryKey.pfx"
6. Copy the c:\publish\FabrikamWordDocument.vsto file to the c:\publish\Application Files\FabrikamWordDocument_1_0_0_0 directory.
1. Copy the c:\publish directory to a test computer.
2. In the c:\publish directory, run the Setup.exe file or double-click FabrikamWordDocument.vsto.
3. Verify that FabrikamWordDocument appears in the Add/Remove Programs list in Windows XP or Programs and Features in Windows Vista.
4. Verify that the FabrikamWordDocument.docx file appears on the desktop.
5. Open the Word document file to verify that your code is running.
Feel free to leave comments and feedback about this new scenario at the bottom of this article.
Happy deployment!
Starting in Visual Studio 2010 Beta 1, you can deploy multiple Office solutions in a single ClickOnce installer. For example, you can develop two Office solutions (one for Outlook and another for Excel) and combine these into a single installer with a single entry in the Add/Remove Programs list in Windows XP and the Programs and Features list in Windows Vista.
The Visual Studio Tools for Office runtime supports the ability to deploy multiple Office solutions in a single installer. However, Visual Studio still generates the ClickOnce application and deployment manifests for individual deployment. To deploy multiple Office solutions in a single installer, you must modify the application and deployment manifests to install multiple assemblies. This process is demonstrated in the Walkthrough: Deploying Multiple Office Solutions in a Single ClickOnce Installer topic in the MSDN Library.
To continue the example mentioned in the introduction, you can develop an Excel workbook project and an Outlook add-in project for .NET Framework 3.5. Then, to deploy both of these, create an installer project, which you can re-use later to add a third or fourth project. By keeping this installer project separate, it’s possible to keep the original files for the individual projects intact. In this example, the installer project is based on a Word document project, but the document isn’t being deployed. The following figure shows Solution Explorer with three projects, one installer project and two projects to deploy to end user computers.
After you add your code to the Excel and Outlook projects, publish the ContosoExcelWorkbook, ContosoOutlookAddIn, and then ContosoInstaller projects (in that order) to a folder on the development computer. You can right-click on the projects in Solution Explorer, and then click Publish. In this example, the publish directory is c:\publish.
Visual Studio generates an application manifest and deployment manifest for each project. The ClickOnce application manifest is a description of all the files included in the project. Additionally, this file describes how the Office application could load the assembly and run your code. By modifying the application manifest, you can describe files from multiple projects and install all specified projects. There are three different sections of the application manifest to modify: install dependencies, entry points, and assemblies.
These changes may appear lengthy, but it really amounts to a few copy-paste operations and adding four words to the application manifest.
1. In the c:\publish\Application Files folder, copy the contents of the ContosoExcelWork_1_0_0_0 and ContosoOutlookAddIn_1_0_0_0 folder into the ContosoInstaller_1_0_0_0 folder.
2. From the c:\publish\Application Files\ContosoInstaller_1_0_0_0 folder, open the three .dll.manifest files in the XML editor in Visual Studio.
3. Copy the <dependency> block for the Office customization assembly from the ContosoOutlookAddIn.dll.manifest and ContosoExcelWorkbook.dll.manifest files into the ContosoInstaller.dll.manifest file. This code specifies that the ContosoOutlookAddIn.dll and ContosoExcelWorkbook.dll files are part of the ContosoInstaller project.
4. Delete the <dependency> block for the ContosoInstaller.dll. This file is not part of the project, because you are only using the ContosoInstaller project to generate the application manifest template.
1. In the ContosoInstaller.dll.manifest file, delete the text between the <vstav3:entryPointsCollection> and </vstav3:entryPointsCollection> elements.
2. In the ContosoOutlookAddIn.dll.manifest and ContosoExcelWorkbook.dll.manifest files, copy the text between the <vstav3:entryPointsCollection> and </vstav3:entryPointsCollection> elements and paste them into the ContosoInstaller.dll.manifest file.
3. Add an id to the <vstav3:entryPoints> elements.
1. In the ContosoInstaller.dll.manifest file, delete the text between the <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> and </vstov4:customizations> elements.
2. In the ContosoOutlookAddIn.dll.manifest and ContosoExcelWorkbook.dll.manifest files, copy the <vstov4:customizations xmlns:vstov4="urn:schemas-microsoft-com:vsto.v4"> and </vstov4:customizations> elements and paste them into the ContosoInstaller.dll.manifest file.
3. Add the id name to the <vstov4:customization> elements.
4. Save the changes in the ContosoInstaller.dll.manifest file, and close the ContosoExcelWorkbook.dll.manifest and ContosoOutlookAddIn.dll.manifest files.
1. Copy your certificate to the c:\publish\Application Files\ContosoInstaller_1_0_0_0 directory. In this example, I’m reusing the temporary certificate created by Visual Studio because I’ll be installing this to a test computer. For production deployment, we recommend that you use a certificate obtained from a certificate authority.
2. In a Visual Studio command prompt, change to the c:\publish\Application Files\ContosoInstaller_1_0_0_0 directory. (You may have to open the command prompt in Administrator mode to re-sign the files in the c:\publish directory.)
mage -sign ContosoInstaller.dll.manifest -certfile ContosoInstaller_TemporaryKey.pfx
mage -update ContosoInstaller.vsto
-appmanifest "Application Files\ContosoInstaller_1_0_0_0\ContosoInstaller.dll.manifest"
-certfile "Application Files\ContosoInstaller_1_0_0_0\ContosoInstaller_TemporaryKey.pfx"
6. Copy the c:\publish\ContosoInstaller.vsto file to the c:\publish\Application Files\ContosoInstaller_1_0_0_0 directory.
2. In the publish directory, run the Setup.exe file or double-click ContosoInstaller.vsto.
3. Verify that ContosoInstaller appears in the Add/Remove Programs list in Windows XP or Programs and Features in Windows Vista.
4. Open the Excel workbook file and Outlook to verify that your code is running.
Eric Carter released a sample and series of articles based on his TechEd demo last week that shows you how to bring bug data from TFS into Excel and Word using VSTO so it can be further analyzed.
If you you went to TechEd but missed the session you can watch it here if you’ve registered:
Advanced Microsoft Office Word and Excel 2007 Development in Microsoft Visual Studio 2008 with Visual Studio Tools for Office
Everyone can download the sample here.
And don’t forget to check the VSTO Dev Center often for more news, articles, videos, and samples.
Enjoy, -Beth Massi, Visual Studio Community
I’m at TechEd in LA, but it seems I could get just as much excitement just watching the Twittersphere today and watching #tela09 tags! And my feet are killing me. So be glad you’re sitting at your computer instead of walking around Los Angeles! Let me give you some highlights for Office developers:
Watch the Keynotes which include Office 2010 demos. Also some interviews on Office and SharePoint on the same TechEd site.
Office 2010 The Movie: Countdown to Awesome is the new site where you can watch a slick video and more importantly, click the Sign up for the Microsoft Office 2010 Technology Preview. When you click the link they show you the “fine print” which I will now print in large font:
“What does that mean?” you ask. Well, it means that Microsoft wants to collect a wide variety of customer-types and ensure that our TechPreview covers all the different types of customers. For example, the sign-up form asks if you will test the Tech Preview at Home or Work. Be honest in your answer because we truly want to get perspectives from all types of Office users. Similarly the survey asks the size of your company and if you read Japanese. There is no trick to get invited.
If you don’t get invited, then don’t fret. We’ll give you some useful information on this blog and other Office blogs to help you prepare your business for the future. For now, I encourage you to build great solutions for Office using all of the resources at Microsoft including Visual Studio, VBA, Open XML SDK, code samples, Forum support, Code Gallery, and the Office Developer Center.
Sincerely, Christin Boyd, Program Manager
If you’re going to TechEd in Los Angeles next week, then don’t miss these four sessions:
DTL03-INT Meet the Microsoft Visual Studio Team Christin Boyd, Eric Carter, Paul Yuknewicz, Jay Schmelzer, Dustin Campbell, Jonathan Aneja, Luke Hoban, Igor Zinkovsky, Faisal Nasir, Harry Pierson, Lisa Feigenbaum Mon 5/11 2:45 PM-4:00 PM | Blue Theater 1
OFC325 Building Custom Applications in Microsoft Office Outlook 2007 Ty Anderson, Damon Armstrong Tue 5/12 2:45 PM-4:00 PM | Room 408A
DTL324 - Microsoft Visual Studio 2010 Overview for the Business Application Developer Jay Schmelzer Tue 5/12 4:30 PM-5:45 PM | Room 515B
OFC324 Advanced Microsoft Office Word and Excel 2007 Development in Microsoft Visual Studio 2008 with Visual Studio Tools for Office Eric Carter Thursday 5/14 1:00PM-2:15PM | Room 515A
Of course, there are a dozen other sessions that appeal to Office developers and SharePoint developers. These are the four that I highly recommend. Originally I was going to list the 3 not-to-be-missed sessions, but then I couldn’t drop any of these from my list, so we have 4 Must See Sessions!
If you’re not going to TechEd, then please click the links on these speakers’ names to read their blogs where the will eventually post some of their demo code. Expect the posts to happen the Monday after their sessions. In the case of Eric Carter, he would probably love it if you’d buy his book, Visual Studio Tools for Office 2007: VSTO for Excel, Word and Outlook. Or you could just download a zip file with all of the of code from the book here. That should keep you busy for a while. The explanations in the book really do add to the overall value. I should credit the co-author, Eric Lippert. Both men are brilliant and funny, and very modest. At the Holiday Party this year, Eric Carter got up to sing karaoke and astounded us all with a bouncy rendition of “Sesame Street.”
-Christin Boyd, Program Manager, Visual Studio
Many customers have reported issues with installing a VSTO project that has been published with Visual Studio 2008 running on the recently released Windows 7 Release Candidate.
If you published your solution using VS2008 on a machine running the Windows 7 RC and then you try to install the solution on any machine you will see the following error: “The required version of the .NET Framework is not installed on this computer”
You will see this error even if you have the right version of .Net Framework installed. The issue occurs due to some differences in the publishing mechanism on the Windows 7 RC caused by a missing file in the .Net Framework 3.5.1 which was included in the RC.
The following file is missing:
%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.5\RedistList\FrameworkList.xml
You can workaround the issue by manually copying this file from an existing non Windows 7 machine which has the .Net Framework 3.5 installed. The file will be available at the exact same location.
Once you have included this file on the Windows 7 RC machine, you will be able to publish and generate the correct manifests. After making this change please republish any solutions that were previously published from the Windows 7 RC machine. These solutions will now be able to install successfully.
We are tracking this issue and plan to address it before Windows 7 RTM. If you are using the RC release please use the workaround mentioned above.
Updates**********
If you have having trouble replacing the file. You need to be an Owner of the file and your user account needs Full Control. To do this:
• Right click the File -> Properties • Select Security Tab • Click the Advanced Button • Click the “Owner” Tab • Click the Change Button • Double Click your User Object • Click Okay • Click Okay, • Ensure you have “Full Control” Permissions to the file by repeating steps above and adding your user account with Full Control permissions.
Also if you are on a 64 bit system:
Note that you need to replace both the architecture specific files on a 64bit bit OS, i.e. [Program Files x86]\Reference Assemblies\Microsoft\Framework\v3.5\RedistList %ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.5\RedistList
We have a team of developers who focus entirely on writing test automation programs for the purpose of covering the huge matrix of test cases that Visual Studio requires. We often configure new installs of Office and our automated tests need to deal with the special things that Office products do when you first run them after a new install. For example, when you first run Microsoft Word after a new install, it prompts you to enter your name and initials in a dialog that looks like this:
Our talented SDET’s (Software Development Engineer in Test) use the following function in their automated tests to suppress this dialog:
using System.IO;
using System.Diagnostics;
public static bool AddOffice12UserInfo()
{
bool passed = false;
string[] commands = new string[5];
commands[0] = @"add HKCU\Software\Microsoft\Office\12.0\Common /v UserData /t REG_DWORD /d 1 /f";
commands[1] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v Company /t REG_SZ /d Microsoft /f";
commands[2] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v UserName /t REG_SZ /d TestRun /f";
commands[3] = @"add HKCU\Software\Microsoft\Office\Common\UserInfo /v UserInitials /t REG_SZ /d t /f";
commands[4] = @"add HKCU\Software\Microsoft\Office\12.0\Common\General /v ShownOptIn /t REG_DWORD /d 00000001 /f";
for (int i = 0; i < commands.Length; i++)
bool temp = StartREG(commands[i]);
if (!temp)
return false;
}
passed = true;
return passed;
public static bool StartREG(string arguments)
int exitcode = -100;
try
string localpath = Path.Combine(System.Environment.GetEnvironmentVariable("SYSTEMROOT"), "system32");
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.EnableRaisingEvents = false;
myProcess.StartInfo.FileName = Path.Combine(localpath, "reg.exe");
myProcess.StartInfo.Arguments = arguments;
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
myProcess.WaitForExit();
exitcode = myProcess.ExitCode;
if (exitcode == 0)
else
Debug.WriteLine("reg exit code is::" + myProcess.ExitCode.ToString());
catch (Exception ex)
Debug.Fail(ex.Message, ex.StackTrace);
Let me know if these Test Automation samples are useful and we will try to publish more of these.
-Christin Boyd, Program Manager, Visual Studio and Bill Robertson, Software Development Engineer in Test, Visual Studio
I hope I didn’t say “I am a doughnut.” For native German speakers, you may already know about Lars Keller, a recent recipient of the Visual Studio MVP Award. When the localized Help files and documentation aren’t enough, it helps to read technical content in your own language. Lars writes a developer blog with quite a few Office development entries:
All about .NET, VSTS, VSTO and more
Lars also co-founded an aggregation of many German language blogs and event announcements about Visual Studio Tools for Office:
Alles zum Thema Visual Studio Tools for Office
You can find more non-English content written and aggregated by two other VSTO MVPs, Ryosuke Uemoto and Pablo Pelaez Aller. You can find a Japanese blog on VSTO, a Japanese blog on VSTO and other Developer topics, and a Spanish blog on VSTO.
If you know of other non-English web sites with great Office development content, then please leave a comment.
I get a lot of questions about the future.
In the coming months you will see a few more blog posts about the future and plenty of blog posts about developing today with Visual Studio 2008. For now, I’d like to review all of the official posts that Microsoft has released about developing SharePoint Server 2010 solutions:
Press Release on SharePoint Server 2010
SharePoint Designer is now FREE
Soma’s blog post “SharePoint tools support in Visual Studio”
Official Visual Studio 2010 home page
PDF of the Official Visual Studio 2010 Product Overview
Channel9 Interview with the Lead Program Manager designing the Office and SharePoint tools in VS 2010
If I’ve forgotten any of the official Microsoft announcements in this post, then please leave a comment with a link. Thanks!
-Christin Boyd, Program Manager