Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change VS reload files behaviour

I am having one VSIX project, which will made some changes in Project.json file of ASPNET5 project. am using the following to edit .json file.

ProjectJson jsonObj = JsonConvert.DeserializeObject<ProjectJson>(jsonContents);
jsonObj = JsonConvert.DeserializeObject<ProjectJson>(jsonContents);

var resultJson = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

JsonSerializer serializer = new JsonSerializer();
using (StreamWriter sw = new StreamWriter(projectObjects.ProjectJsonPath))
{
     var writer = new JsonTextWriter(sw);
     serializer.Serialize(writer, resultJson);
}

// File.WriteAllText(projectObjects.ProjectJsonPath, resultJson);

by using both stream writer and writealltext am getting the following message in ASPNET 5 project

The file has unsaved changes inside this editor and has been changed externally. do you want to reload it?

how to edit .json file without getting the above message?

like image 615
user3610920 Avatar asked Nov 15 '15 16:11

user3610920


2 Answers

Its actually the opposite. Since the environment thinks that the file wants to reload with unsaved changes.

You should uncheck the detect file changes. And when you do, it won't detect the external changes and will not warn you, beware though, that if you try to save the file after it has been modified you will lose the external change.(not a problem in your case I guess) and in order to see the changes you will have to close, not save the file and reopen it.

Source : VS2008: Disable asking whether to reload files changed outside the IDE

Disable file change detection

like image 179
lkn2993 Avatar answered Sep 28 '22 03:09

lkn2993


This is the option you want to check programmatically. I don't know how exactly you can do that but you can find topics about settings at MSDN (Creating an option page and Creating a setting category). Using those topics you can have a sense of how options are created.

Basically what you need to do is to load VS settings file (VS.vssettings) and inject another Xml line. (Have a look at Examining the Settings File section on MSDN)

Option to deselect

Update

To be extremely clear the VS settings file is located under

Documents\Your_VS_Version\Settings\CurrentSettings.vssettings

and you need to load the xml and change 'AutoloadExternalChanges' to value 'true'. Setting section

like image 36
Botea Bogdan Avatar answered Sep 28 '22 04:09

Botea Bogdan