Search code examples
matlabvisual-studiovisual-studio-2015tfsfile-association

MATLAB File Association in Visual Studio 2015 / TFS


I'm using TFS in Visual Studio 2015, and have a question about MATLAB file associations. For .m files, there is no association to MATLAB, as seen here:

Function

Confusingly, there is an association for .fig and .mat files, so VS must recognise that MATLAB "exists". If I double click one of these file types, it opens it in MATLAB as it would from within an Explorer window. This is the behaviour I want for .m files.

Figure

As a minimum, I'd like to have the MATLAB icon for .m files so that they're easy to spot in a directory. As an ideal solution, these files would also open in MATLAB (not the VS text editor) from TFS.

I have tried the "File Extension" option inside of Options > Text Editor, but MATLAB isn't an option for me in the Editor list.

Options

It's worth noting that my work network is pretty strict on software installs, so the fewer external add-ins the better (ideally none). Suggestions appreciated.


Solution

  • So after a long time, I've found a reasonable workaround for this.

    You can set the "Open With" default for .m files, but this seems to open a new instance of MATLAB for every file - not ideal! Suggested by SACn below their answer.


    A better option is to use Visual Studio's "External Tools".

    Go to Tools > External Tools, then as this documentation shows, create a new tool. Use the following parameters:

    Title:     Your Title Here
    Command:   cmd.exe
    Arguments: /c "$(ItemPath)"
    

    Tick "Close on exit". This opens the command prompt with the /c (terminate after command) flag, and runs the file name of the file which you have open in VS. On Windows systems, this will open the file in an open instance of MATLAB, or launch a new one if none exist.


    This can be run many ways... Assign a keyboard shortcut, run from the Tools menu, add it to the Toolbar, add it to the context menu.

    Now there is one click / key press to launch an open .m file as desired. It still lacks the MATLAB file association (and corresponding icon in the file browser) but does the main job!