Editare

Partajați prin


Create file associations for a ClickOnce application

ClickOnce applications can be associated with one or more file name extensions, so that the application will be started automatically when the user opens a file of those types. Adding file name extension support to a ClickOnce application is straightforward.

Note

To create file associations in a .NET ClickOnce app (instead of .NET Framework), see Access ClickOnce activation data for .NET on Windows.

To create file associations for a ClickOnce application

  1. Create a ClickOnce application normally, or use your existing ClickOnce application.

  2. Open the application manifest with a text or XML editor, such as Notepad.

  3. Find the assembly element. For more information, see ClickOnce application manifest.

  4. As a child of the assembly element, add a fileAssociation element. The fileAssociation element has four attributes:

    • extension: The file name extension you want to associate with the application.

    • description: A description of the file type, which will appear in the Windows shell.

    • progid: A string uniquely identifying the file type, to mark it in the registry.

    • defaultIcon: An icon to use for this file type. The icon must be added as a file resource in the application manifest. For more information, see How to: Include a Data File in a ClickOnce Application.

      For an example of the file and fileAssociation elements, see <fileAssociation> Element.

  5. If you want to associate more than one file type with the application, add additional fileAssociation elements. Note that the progid attribute should be different for each.

  6. Once you have finished with the application manifest, re-sign the manifest. You can do this from the command line by using Mage.exe.

    mage -Sign WindowsFormsApp1.exe.manifest -CertFile mycert.pfx

    For more information, see Mage.exe (Manifest Generation and Editing Tool).

    Note

    In ClickOnce for .NET Core 3.1 and .NET 5 or later, use dotnet-mage.exe instead of Mage.exe. For more information, see ClickOnce for .NET.