Normalize encoding of an entire solution

0

I was working with GitLab and noticed that it serves all the files on your front end with UTF-8.

I have a solution that has source files with several encodings. Files in UTF-8 are displayed correctly in GitLab. However there are files with encoding Codepage 1252 and for these the accented characters are not displayed in GitLab.

This does not cause me any problems in the IDE, but it is a nuisance when reviewing code. Is there any functionality in Visual Studio to normalize the encoding of files?

In the absence of such functionality, is there any technique or good practice for file normalization? (In addition to setting your encoding from scratch)

    
asked by anonymous 03.05.2017 / 20:28

1 answer

0

There is no built-in solution for this, but as Paul said in the comments ... We are programmers, we can solve this ourselves.

Here's my solution, adapted from posted on Stack Overflow :

foreach (FileInfo arquivo in new DirectoryInfo(caminho).GetFiles("*.cs", SearchOption.AllDirectories)) {
    string conteudoArquivo = File.ReadAllText(arquivo.FullName);
    File.WriteAllText(arquivo.FullName, conteudoArquivo, Encoding.UTF8);
}

Where caminho is the root of the solution.

    
29.06.2017 / 16:28