Normalize encoding of an entire solution

Asked

Viewed 48 times

-1

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

I have a solution that has source files with various encodings. UTF-8 files are displayed correctly in Gitlab. But there are files with encoding Codepage 1252 and for these accented characters are not displayed in Gitlab.

This does not cause me any problems in the IDE, but it is a nuisance when it comes to 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 the normalization of files? (In addition to defining your encoding from the beginning)

  • 1

    You can create a p/ code to do this http://stackoverflow.com/questions/279673/save-all-files-in-visual-studio-project-as-utf-8/2633313

1 answer

0


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

Follow my solution, adapted from one posted to Stack Overflow in English:

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.