Specifying a Product Name, Publisher Name and other properties for VSTO solutions (Saurabh Bhatia)

 


Many customers have requested how to specify options like a Product or Publisher Name for Office 2007 VSTO solutions deployed from Visual Studio 2008. However, you cannot specify these properties in the Visual Studio IDE. In this post, I will describe the various other options you have to specify these properties.


Specifically we will be looking at the following properties:


Product Name – This is what the VSTO solution will be called in the Programs and Features (Add Remove Programs Entry)


Publisher Name – The name of the Publisher as displayed in Programs and Features


clip_image002[11]


Figure 1 : Programs and Features Dialog in Vista showing Product Name and Publisher Name


Friendly Name – This is the name of the VSTO solution as it is displayed in the Office Add-ins dialog, the same value is also used in the VSTO trust prompt. Usually this value should be the same as the Product Name.


Office Application Description – The description of the Office Add-in.


clip_image004[9]


Figure 2 : Excel Add-ins Dialog showing Friendly Name and Office Application Description


SupportURL – End Users can click on the product name on the Trust Prompt dialog and visit a custom website related to the Solution.


clip_image006[12]


Figure 3 : VSTO Trust Prompt with Friendly Name and link to SupporURL


The easiest way to specify these properties is to modify the Deployment and Application manifests for the VSTO solution (.vsto and .dll.manifest files).


To specify the Product, Publisher and SupportURL properties


The product name, publisher name and support url properties can all be specified in the deployment manifest, the .vsto file that is generated after publishing the solution. You can open the deployment manifest in a text editor and change the <description> tag to include the properties you want to specify.


<description asmv2:publisher=”Visual Studio (BizApps)” asmv2:product=”My VSTO Solution” asmv2:supportUrl=”http://www.microsoft.com/” xmlns=”urn:schemas-microsoft-com:asm.v1″ />


Once you have modified the deployment manifest you need to resign it. This can be done using the Manifest Generation and Editing Tool (mage.exe) in the .NET Framework SDK, Windows SDK, or Visual Studio 2008.


Start the Visual Studio command prompt and use mage.exe to resign the deployment manifest:


mage –sign deploymentmanifest.vsto –Certfile Certificate.pfx


Example:


mage –sign MyExcelAddin.vsto –CertFile MyCert.pfx


To specify Friendly Name and Office Application Description:


The Friendly Name and Office Application Description properties can be found in the application manifest under the VSTOV3 namespace.


The application manifest (the MySolution.dll.manifest file) will typically be found under the Application Files\MySolution_X_X_X_X\ folder where the X’s describe the latest published version of the solution.


You can open the application manifest and change these properties:



<vstov3:customization xmlns:vstov3=”urn:schemas-microsoft-com:vsto.v3″>
<vstov3:appAddIn application=”Excel” loadBehavior=”3″ keyName=”ExcelAddIn9″>
<vstov3:friendlyName>My VSTO Solution</vstov3:friendlyName>
<vstov3:description>A Sample Add-in created to show the add-in properties work</vstov3:description>
</vstov3:appAddIn>
</vstov3:customization>


After you have changed the application manifest, you need to re-sign the application manifest itself. In addition you will also need to refresh the deployment manifest so that it has the new hash for the application manifest. Lastly you need to re-sign the deployment manifest.


The three steps after editing the application manifest can be performed using mage:


Resign application manifest:



Mage –sign applicationmanifest.dll.manifest –Certfile certfile.pfx
Example:
Mage –sign “Application Files\MyVsto_1_0_0_0\myvsto.dll.manifest” –Certfile ..\myvsto.pfx


Update deployment manifest:



Mage –update deploymentmanifest.vsto -AppManifest applicationmanifest.manifest
Example:
Mage –update myvsto.vsto -AppManifest “Application Files\MyVsto_1_0_0_0\myvsto.dll.manifest”


Resign deployment manifest:



Mage –sign deploymentmanifest.vsto –Certfile Certificate.pfx
Example:
Mage –sign MyExcelAddin.vsto –CertFile MyCert.pfx


Your VSTO solution will now have these properties. The downside of this approach is that you will have to perform these manual steps after every publish. If you want to avoid these manual steps, you can make some changes to the VSTO build targets such that these properties are picked up by Visual Studio during publish. The general idea is that you can specify these properties in your Visual Studio project file (the .vbproj or .csproj) which will in turn be picked up by the build tasks so that they are automatically inserted into the manifest for every publish.


Changing your targets file is a risky scenario; if you change something incorrectly, none of your projects will build. So to be safe, the first thing you should do is make backups of the files that you are going to change.


Also to be safe, we will not be editing the main target file but a copy of it. Any VSTO project that you want to specify the publish properties for will use this new modified targets file.


One more thing to consider before modifying the targets file is that your project may not build correctly if you use the modified targets file and later update the Visual Studio version. If you update Visual Studio, you will have to make the corresponding changes in the new Visual Studio targets file.


Creating a backup and modifying the targets file


The file we will be modifying is: Microsoft.VisualStudio.Tools.Office.Office2007.targets,which can be found in the following directory: %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v9.0\OfficeTools


To open the targets file



  1. Create a backup. Copy the file to a safe location (cannot emphasize this enough).

  2. Create another copy that you will be editing.


    • Create a copy of the file and save it to your Visual Studio 2008 folder under Documents. On Vista : C:\Users\username\Documents\Visual Studio 2008
      On XP: C:\My Documents\Visual Studio 2008

    • Rename the filename to : Microsoft.VisualStudio.Tools.Office.Office2007_Properties.targets

    • You will be modifying this file for the remaining steps.

3. Open the Microsoft.VisualStudio.Tools.Office.Office2007_Properties.targets file in your favorite text editor.



To change the targets file to support Product Name


In this example, we treat Friendly Name to be the same as Product Name.



  1. Find the comment for Add-in Options section: <!– Add-In options –>
    The comment is usually followed by the LoadBehavior tag: <LoadBehavior>3</LoadBehavior>

  2. In the Add-in Options section before the LoadBehavior tag add the following line:
    <ProductName Condition=” ‘$(ProductName)’ == ” “>$(TargetName)</ProductName>
    Quote sequence:
    Condition = <doublequote><singlequote> $(ProductName) <singlequote> == <singlequote><singlequote><doublequote>

  3. Find all instances of FriendlyName. Usually the FriendlyName is assigned to $TargetName: FriendlyName=”$(TargetName)”
    Change all instances to: FriendlyName = “$(ProductName)”
    There will be three places in all where you need to update FriendlyName.

  4. Search for Target GenerateDeploymentManifestForPublishing:
    <Target Name=”GenerateDeploymentManifestForPublishing”>

  5. Inside this target there is a GenerateDeploymentManifest task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />

  6. Add a Product attribute to this task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    Product=”$(ProductName)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />


To change the targets file to support Publisher Name



  1. Search for Target GenerateDeploymentManifestForPublishing:
    <Target Name=”GenerateDeploymentManifestForPublishing”>

  2. Inside this target there is a GenerateDeploymentManifest task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    Product=”$(ProductName)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />

  3. Add a Publisher attribute to this task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    Product=”$(ProductName)”
    Publisher=”$(PublisherName)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />


To changing the targets file to support SupportURL



  1. Search for Target InitializePublishProperties :
    <Target Name=”InitializePublishProperties”>
    It is followed by a CreateProperty task:
    <CreateProperty Value=”Application Files”>
         <Output PropertyName=”ApplicationFilesFolderName” TaskParameter=”Value”/>
    </CreateProperty>

  2. After the CreateProperty task add the following:
    <FormatUrl InputUrl=”$(SupportUrl)”> 
    <Output TaskParameter=”OutputUrl” PropertyName = “_DeploymentFormattedSupportUrl”/>
    </FormatUrl>

  3. Search for Target GenerateDeploymentManifestForPublishing:
    <Target Name=”GenerateDeploymentManifestForPublishing”>

  4. Inside this target there is a GenerateDeploymentManifest task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    Product=”$(ProductName)”
    Publisher=”$(PublisherName)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />

  5. Add a Publisher attribute to this task:
    <GenerateDeploymentManifest
    EntryPoint=”@(ApplicationManifestWithPathForPublishingCollection)”
    AssemblyName=”$(DeploymentManifestFileName)”
    AssemblyVersion=”$(PublishVersion)”
    Product=”$(ProductName)”
    Publisher=”$(PublisherName)”
    SupportUrl=”$(_DeploymentFormattedSupportUrl)”
    MapFileExtensions=”$(MapFileExtensions)”
    OutputManifest=”@(DeploymentManifestWithPathForPublishingCollection)”
    Platform=”$(PlatformTarget)”
    Install=”false”
    />

To change the targets file to support Office application description



  1. Search the text file for “OfficeApplicationDescription”

  2. You will find a line as follows:
    <OfficeApplicationDescription Condition=”‘$(VSTO_ProjectType)’ == ‘Application'”>$(TargetName) – $(OfficeApplication) add-in created with Visual Studio Tools for Office</OfficeApplicationDescription>

  3. Modify it to:
    <OfficeApplicationDescription Condition=”‘$(OfficeApplicationDescription)’ == ” and ‘$(VSTO_ProjectType)’ == ‘Application'”>$(TargetName) – $(OfficeApplication) add-in created with Visual Studio Tools for Office</OfficeApplicationDescription>
    Note the correct quotes are as follows:
    Condition = <doublequote> <singlequote> $(OfficeApplicationDescription) <singlequote> == <singlequote><singlequote>

  4. The very next line after this also needs to be modified:
    <OfficeApplicationDescription Condition=”‘$(VSTO_ProjectType)’ == ‘Document'”>$(TargetName) – $(OfficeApplication) document created with Visual Studio Tools for Office</OfficeApplicationDescription>

  5. Modify it to:
    <OfficeApplicationDescription Condition=”‘$(OfficeApplicationDescription)’ == ” and ‘$(VSTO_ProjectType)’ == ‘Document'”>$(TargetName) – $(OfficeApplication) document created with Visual Studio Tools for Office</OfficeApplicationDescription>
    Note the correct quotes are as follows:
    Condition = <doublequote> <singlequote> $(OfficeApplicationDescription) <singlequote> == <singlequote><singlequote>

You are done modifying the targets file. The next step is to modify your project file and specify values for these properties. You will have to modify any project that you want to specify these properties for. The Visual Studio projects file is the .vbproj or .csproj file associated with your project. You can open up this file in a text editor.


You will have to modify the project so that it starts using the new targets file which you have created:


Modify project to use new target file



  1. Find the following comment in the projects file:
    <!– Include additional build rules for an Office application add-in. –>

  2. Replace the existing pointer to the targets file:
    <Import Project=”$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.Office2007.targets” />
    With the path to the new targets file:
    <Import Project=”c:\users\username\documents\Visual Studio 2008\ Microsoft.VisualStudio.Tools.Office.Office2007_Properties.targets” />

Specify Properties in project file


Inside the first <PropertyGroup> tag you can add the following properties:


<ProductName>My VSTO Solution</ProductName>


<PublisherName>Visual Studio (BizApps)</PublisherName>


<OfficeApplicationDescription>A Sample Add-in created to show the add-in properties work</OfficeApplicationDescription>


<SupportUrl>http://www.microsoft.com</SupportUrl>


Once you have added these properties to the project file you can save the project and open it in Visual Studio. When you open this project you will get a warning stating that the project has been modified to use custom build steps. Choose the option to Load the project normally and proceed. From now onwards, these properties will be automatically be inserted into the manifest during publish. Any updates you make to these properties will also automatically be picked up by the publish system.


Modifying the targets file is a rather long and elaborate procedure, but once you complete it successfully you have the benefit of being able to specify these properties easily for any project.


Hope you find this post useful. Please let us know your comments.


Saurabh Bhatia, Program Manager