简体   繁体   中英

Visual studio 2015 solution explorer doesn't refresh files?

My Visual studio 2015 solution explorer doesn't refresh when I change files on disk and there is (as far as I can see) no refresh button anymore.

In explorer everything looks as it should and after performing my "refresh"-methods below all files shows again.

My solutions so far:

  1. Unload and reload project
  2. Refresh Visual Studio

This is especially annoying when running builds with gulp which is adding, changing and removing files.

Am I missing something obvious?

Ps. It does not have to do with option "Show All Files". The doesn't show as "transparen" not-included-files either.

Click on the show all files icon on the top of the solution explorer. You can then choose the files you want to include in the project.

Solution Explorer截图

See the answer here:

Refresh button in Visual Studio Solution Explorer not working

I've banged my head quite a lot for figuring out how to do this as well and the answer is that I don't think Visual Studio handles this kind of scenario.

What I've done is a workaround and not an optimal one, but I'll post it here in case it might help others.

You can trigger Visual Studio to notice file changes like this:

  • When the files are added or deleted outside of Visual Studio, touch the project file
  • Visual Studio notices this and pops up a confirmation dialog asking do you want to reload the project
  • Click Reload/Reload All, and the project is reloaded, and the file modifications show now on the Solution Explorer

I use two node packages. Chokidar to watch file system events and touch to touch project file

Chokidar is nice, you can set which files and folders to watch, what to ignore and so on. And touch offers very easy way to change the timestamp of the file.

Here's a working code sample which you can tune to suit your needs:

var chokidar = require('chokidar');
var touch = require("touch");

console.log("Starting - Initial files are ignored");

var projectFile = "C:\\projects\\GitHub\\testing-touch\\TestingTouch\\TestingTouch.csproj";                   

var watcher = chokidar.watch('C:\\projects\\GitHub\\testing-touch\\TestingTouch\\tests', {
  ignored: /[\\/\\]\./,
  ignoreInitial: true,
  persistent: true  
});

var log = console.log.bind(console);

watcher
  .on('add', function(path) {
    log('File', path, 'has been added');
    touch.sync(projectFile, { time: new Date(), force: false });
  })
  .on('change', function(path) { log('File', path, 'has been changed'); })
  .on('unlink', function(path) { log('File', path, 'has been removed'); })
  // More events.
  .on('addDir', function(path) { log('Directory', path, 'has been added'); })
  .on('unlinkDir', function(path) { log('Directory', path, 'has been removed'); })
  .on('error', function(error) { log('Error happened', error); })
  .on('ready', function() { log('Initial scan complete. Ready for changes.'); })
  .on('raw', function(event, path, details) { log('Raw event info:', event, path, details); })

// 'add', 'addDir' and 'change' events also receive stat() results as second
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats
watcher.on('change', function(path, stats) {
  if (stats) console.log('File', path, 'changed size to', stats.size);
});

The negative sides of this workaround are that you'll have to setup the file watcher, and you'll need to click the annoying confirmation dialogue.

I was also in a similar situation whilst trying to add my pre-existing 'assets' folder to a Web Project in Visual Studio 2015.

  1. Right click on your Project item in the Solution Explorer and create a New Folder eg 'assets'

  2. In Windows Explorer, drag the contents of the folder you wish to transfer into the new 'assets' folder in the VS Solution Explorer window and wait for the copying process to complete.

  3. Click on the 'Show All Files' icon on the toolbar at the top of the Solution Explorer. You should see your folder structure including the files you need.

  4. Highlight the files/folders, right click and select 'Include In Project'.

This worked for me and I hope it helps anyone with the same issue.

“视图”标签底部有一个刷新选项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM