如何在查看文件时复用Visual Studio实例?WPF应用打开.feature文件异常
Hey there, let's tackle this issue you're facing with your WPF app opening .feature files in VS 2015 instead of 2017. Here are a few solid solutions depending on what you need:
1. Update System Default File Association (Simplest Approach)
The most straightforward fix is to set VS 2017 as the default app for .feature files system-wide:
- Right-click any .feature file on your machine
- Select Open with > Choose another app
- Check the box that says "Always use this app to open .feature files"
- Browse to your VS 2017 executable (typical path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe— adjust "Community" to "Professional" or "Enterprise" if you have that version) - Confirm your selection, and moving forward
Process.Start(path)will use VS 2017 by default
2. Force VS 2017 Opening in Code (Bypass System Associations)
If you don't want to mess with system defaults, or need guaranteed control over which VS version opens the file, modify your code to directly call VS 2017's executable:
// Update this path to match your VS 2017 installation var vs2017ExePath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe"; var featureFileFullPath = "YourFullFeatureFilePath.feature"; // Launch VS 2017 with the target file Process.Start(new ProcessStartInfo(vs2017ExePath, $"\"{featureFileFullPath}\""));
- Note: Double-check the path to
devenv.exe— if you're on a 64-bit system and installed VS to the 64-bit directory, it might be underC:\Program Filesinstead ofC:\Program Files (x86). - This method ensures your app always uses VS 2017, regardless of system-level file associations.
3. Reset File Association Cache via Command Line
Sometimes Windows caches file association settings, which can cause unexpected behavior. Here's how to reset it manually:
- Open Command Prompt as Administrator
- Run
assoc .featureto check the registered file type (e.g., it might return.feature=SpecFlowFeatureFile) - Run
ftype SpecFlowFeatureFileto see the current associated program path — if it points to VS 2015, update it with:ftype SpecFlowFeatureFile="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe" "%1" - Restart your WPF app and test again
If you noticed inconsistent behavior when repeating the feature, this cache reset should help stabilize things. If the issue persists, the code-based approach (solution 2) is your safest bet.
内容的提问来源于stack exchange,提问作者C Robinson

