none
Stop Visual Studio 2013 from changing the file encoding?

    Question

  • Hello,

    I use Visual Studio to edit python scripts (.py files). When I do this, I prefer to use a particular file encoding. However, my VS seems to set the encoding to UTF-8 all the time. Here's what I am seeing:

    1. Open a file, and check its encoding via "File; Advanced Save Options...". This would show "UTF-8 with signature" is the encoding.
    2. Change the encoding to my preferred one.
    3. An asterisk appears next to the filename in the VS editor tabs, indicating that the file has changed, and needs saving.
    4. Save the file. A warning comes up to say I'm about to change encoding, which might cause problems for file diff. Say OK to this warning.
    5. Close the file. Check the encoding in Notepad++. All is fine.
    6. Reopen the file. Add a trivial change, say, a space.
    7. Save the file again. The warning about changing encoding appears again. Say OK to that too.
    8. Check Advanced Save Options to see that encoding is once again UTF-8. Notepad++ reports encoding is UTF-8 as well.

    Does anyone know what settings I can change to avoid this behavior, please? This is driving me crazy!

    Thank you very much.
    Friday, January 08, 2016 12:50 PM

Answers

  • Hello Jack,

    Thank you very much for following up on the issue. I had been side-tracked by other matters, but I have just submitted a connect report.

    While submitting the report, I took the opportunity to refine the description of the problem, incorporating in our discussion here. Hopefully this formulation is clearer. I've removed the comment about warnings, as it was triggered by the version control and mentioning it only causes distraction. The issue exists even for files not in version control.

    Regards,

    T-Tran





    Thursday, January 28, 2016 8:14 AM
  • I have the same problem that only began after upgrading to a newer build of PVTS. Then I saw this PTVS issue https://github.com/Microsoft/PTVS/issues/74 which implies that it is PVTS and not VS that now automatically changes the encoding to UTF-8 every time a .py file is re-opened and saved.
    • Marked as answer by T-Tran Thursday, January 05, 2017 7:58 AM
    Tuesday, May 17, 2016 3:16 PM

All replies

  • Hi T-Tran,

    I test it in my side using the VS2013 and VS2015, I couldn't get the warning like yours.

    Could you test it again using the default settings?

    TOOLS->Import and Export Settings Wizard->Reset all settings->select “No, just reset settings, overwriting my current settings”->Choose a Default Collection of settings, and then create a new file, check the result.

    One issue is that I just create this file in my VS2015 like the following screen shot 1, I didn't find this item like the following screen shot in my VS2013, so I use the same file in my VS2013, maybe I need to install the specific python package in my VS2013, am I right?

    But I test it in my VS2015, it really works well, and then use the same .py file in my VS2013, it still has no warning messages. So I afraid that it is related to the VS settings.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 12, 2016 2:30 AM
    Moderator
  • Thanks for your reply, Jack. Unfortunately, resetting the settings did not fix the problem, I think.

    Before saying this conclusively, I need to double check one step with you. When I went to the Choose a Default Collection of Settings screen, I was given several choices. You did not specify which collection I should use. I chose the "General" collection of settings. Hope that was the correct one. None of the other ones seem to fit.

    The file I originally used was under the Team Foundation Server version control. That's why I got the warning about problem with diffs, which you did not get. I have since verified that a brand new file, not under version control, has the same issue with automatic UTF-8 encoding.

    Regards.



    • Edited by T-Tran Tuesday, January 12, 2016 8:38 AM
    Tuesday, January 12, 2016 8:01 AM
  • Hi  T-Tran,

    Thanks for your friendly response.

    >>When I went to the Choose a Default Collection of Settings screen, I was given several choices. You did not specify which collection I should use. I chose the "General" collection of settings. Hope that was the correct one. None of the other ones seem to fit.

    Actually I just select the C# language, but my understanding, if it doesn't work using the general settings, it would also have the same issue even if you select the C# language settings, maybe you could test it in your side.

    >>The file I originally used was under the Team Foundation Server version control. That's why I got the warning about problem with diffs, which you did not get. I have since verified that a brand new file, not under version control, has the same issue with automatic UTF-8 encoding.

    Whether I need to install the specific package for the python scripts in my VS2013? Maybe you could share me the download link, it seems that it has no that item in my default VS2013. But I test it in my side using the VS2015, it worked normally, I didn't get any warning. If you have the VS2015 machine, please test it in your side.

    You could share me a simple  python script/file, I will check it in my side using the VS2015 or VS2013. Of course, I will check that whether I forget to install any packages in my default VS2013. Of course, if you install any packages singly, please feel free to tell me, so I could really set up the same VS2013 Environment and repro this issue in my side.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 12, 2016 12:36 PM
    Moderator
  • Hi Jack,

    >>Whether I need to install the specific package for the python scripts in my VS2013? Maybe you could share me the download link, it seems that it has no that item in my default VS2013. But I test it in my side using the VS2015, it worked normally, I didn't get any warning. If you have the VS2015 machine, please test it in your side.

    The main VS2013 add-in I am using is Python Tools for Visual Studio (http://microsoft.github.io/PTVS/). The version control system is part of MS Team Foundation Server. We have version 12.0.30324.0. I don't know if any of these components is causing the problem.

    >>You could share me a simple  python script/file, I will check it in my side using the VS2015 or VS2013.

    I believe it does not matter what I have in the python file. In any case, I have a file called "testsave.py" with the following lines:

    class my_class(object):
        pass 
    
    Wednesday, January 13, 2016 11:44 AM
  • Hi T-Tran,

    One issue is that whether the code was garbled after you re-open it in your VS IDE.

    >>Change the encoding to my preferred one.

    Could you tell me the real Encoding option you have changed in your side? So I could really test it again.

    Actually I test it in a clean VS2013 machine.

    For example, I will get the warning if I open it in my VS IDE after I change it in my notepad.

    Click Ok, The previous file code will be garbled like the screen shot 2:

    >>step 4 Save the file. A warning comes up to say I'm about to change encoding, which might cause problems for file diff. Say OK to this warning.

    But like your step 4, I really didn't get the warning. Maybe you could share me a screen shot about this result, please also tell me the real Encoding option.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 15, 2016 7:55 AM
    Moderator
  • Hi Jack,

    Sorry for the slow response.

    My perferred encoding is Western European (Windows) - Codepage 1252.

    Sorry, the forum isn't allowing me to post an image yet. However, I am not sure if the warning in step 4 is relevant. It appeared for files under version control; however, even for a file not under version control, I still have the automatic UTF-8 encoding problem (and no warning).

    Tuesday, January 19, 2016 12:16 PM
  • Hi T-Tran,

    Please check that whether it is related to the VS settings under TOOLS->Options->Environment->Documents. Please disable "Save documents as Unicode when data cannot be saved in codepage".

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 20, 2016 8:13 AM
    Moderator
  • That's not it, I think, because this box is already unchecked for me.

    Wednesday, January 20, 2016 10:47 AM
  • Hi T-Tran,

    >>Sorry, the forum isn't allowing me to post an image yet. However, I am not sure if the warning in step 4 is relevant.

    Maybe you could verify your account here:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=reportabug

    I use the same VS and the same Python file code, I really didn't get the warning information as yours.

    But one issue is that it still uses the UTF-8 with signature even if I change it to be Western European (Windows) - Codepage 1252 after I change it in notepad and re-open it in my VS2013.

    It seems that the file was use the Unicode by design, we couldn't change it, or the real issue was related to the Notepad which use this format.

    Sorry for that I couldn't repro this issue, to get the issue confirmed and diagnose by product team, would you please create connect report for it? You will get email notification for update.http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx

    You could upload your screen shot in the connect report, and share us the connect report link here, I will pay more attentions to the report. Thanks for your feedback.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 21, 2016 6:56 AM
    Moderator
  • Thanks for trying to help, Jack, and thanks for the link to verify my account.

    I must confess I do not understand your message completely. In any case, I will try the connect report as you suggested.

    Regards,

    T-Tran


    • Edited by T-Tran Friday, January 22, 2016 7:56 AM
    Friday, January 22, 2016 7:51 AM
  • Thanks for your friendly response, but sorry for that I didn't describe this issue clearly. T-Tran.

    Like your previous steps:

    I repro this issue using the same steps, but I didn't get the warning like the step 4 and step 7.

    Before step 6, I change it to be Western European (Windows) - Codepage 1252 in VS IDE, close the VS, and then edit this file in Notepad, re-open it in my VS IDE, and then check the advaced save options change, it still was the "UTF-8".

    >>I use Visual Studio to edit python scripts (.py files). When I do this, I prefer to use a particular file encoding. However, my VS seems to set the encoding to UTF-8 all the time.

    I think I get the same result (VS set the encoding to UTF-8 all the time) even if I don't get the warning message like step 4 and 7. That's the reason I suggest you submit a feedback for this issue.

    >>In any case, I will try the connect report as you suggested.

    If you submit it, please share me the link here, I will help you vote your connect report.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 22, 2016 8:51 AM
    Moderator
  • Hi T-Tran,

    What about this issue? Do you get any information from the report team?

    Could you share us the connect link if you submitted it? So we could also help you vote it, and get the latest information from the connect team experts.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 27, 2016 6:16 AM
    Moderator
  • Hello Jack,

    Thank you very much for following up on the issue. I had been side-tracked by other matters, but I have just submitted a connect report.

    While submitting the report, I took the opportunity to refine the description of the problem, incorporating in our discussion here. Hopefully this formulation is clearer. I've removed the comment about warnings, as it was triggered by the version control and mentioning it only causes distraction. The issue exists even for files not in version control.

    Regards,

    T-Tran





    Thursday, January 28, 2016 8:14 AM
  • Hi T-Tran,

    I help you vote your connect report since I get the same result as yours.

    As you already submit one feedback on the Microsoft Connect site, let's focus on the case on that channel, may our senior members can provide more professional support.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 29, 2016 3:14 AM
    Moderator
  • Thanks again for your help, Jack. It is good that you're able to confirm the problem.

    I might be upgrading to VS 2015 soon. Hope this is fixed in that version. I will report back here if that were the case.

    Regards,

    T-Tran

    Monday, February 01, 2016 10:01 AM
  • Thanks again for your help, Jack. It is good that you're able to confirm the problem.

    I might be upgrading to VS 2015 soon. Hope this is fixed in that version. I will report back here if that were the case.

    Regards,

    T-Tran

    If you get any latest information in your side, please feel free to share it here.

    Thanks,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 02, 2016 4:53 AM
    Moderator
  • I just noticed this problem does not occur if I am editing a file with extension ".sql".

    To test, I created an empty file named "test.sql", and went through the step of opening, changing file encoding, reopening, checking file encoding again. The file encoding does not switch to UTF-8.

    The problem does not occur with a ".c" file either!

    Maybe this is an issue with the Python Tools for Visual Studio addin?

    Jack, would  you mind testing this on your computer for me please? I do not have the ability to install/uninstall the Python Tools for VS easily. Perhaps you could check the problem with ".py" files with PTVS installed, and without PTVS.

    Thank you so much.

    Tuesday, March 01, 2016 8:16 AM
  • I have the same problem that only began after upgrading to a newer build of PVTS. Then I saw this PTVS issue https://github.com/Microsoft/PTVS/issues/74 which implies that it is PVTS and not VS that now automatically changes the encoding to UTF-8 every time a .py file is re-opened and saved.
    • Marked as answer by T-Tran Thursday, January 05, 2017 7:58 AM
    Tuesday, May 17, 2016 3:16 PM
  • Thanks for that, Anthony. I believe that PTVS was indeed problematic. I have upgraded my PTVS to version 2.2, and the problem went away.
    Thursday, January 05, 2017 7:58 AM