How to associate a file extension to the current executable in C#

后端 未结 9 2224
故里飘歌
故里飘歌 2020-11-22 12:01

I\'d like to to associate a file extension to the current executable in C#. This way when the user clicks on the file afterwards in explorer, it\'ll run my executable with t

9条回答
  •  没有蜡笔的小新
    2020-11-22 12:45

    There may be specific reasons why you choose not to use an install package for your project but an install package is a great place to easily perform application configuration tasks such registering file extensions, adding desktop shortcuts, etc.

    Here's how to create file extension association using the built-in Visual Studio Install tools:

    1. Within your existing C# solution, add a new project and select project type as Other Project Types -> Setup and Deployment -> Setup Project (or try the Setup Wizard)

    2. Configure your installer (plenty of existing docs for this if you need help)

    3. Right-click the setup project in the Solution explorer, select View -> File Types, and then add the extension that you want to register along with the program to run it.

    This method has the added benefit of cleaning up after itself if a user runs the uninstall for your application.

提交回复
热议问题