Search code examples
c#visual-studio-2008carriage-return

Changing CR/LF output type in Visual Studio


I have a c# project in my Visual studio 2008 which when built, outputs a bunch of files in a temp directory for other programs to use i.e. JsTestDriver, JsCoverage, etc (all a bit Unix-related).

Trouble is, everytime when the files were generated, they seem to contain weird return carriage/line feed which upsets the programs that would use them next.

What I'm currently doing is manually create a notepad file, rename it to a different name, then copy and paste the entire content of the generated file (and save) to solve this problem. This is, of course, tedious and not something I enjoy doing (ultimately I want this whole process to be automated).

So my question is: how do I get Visual Studio to output the correct/proper CR/LF so I no longer need to go through the manual process?

If the above is too vague, I'll be happy to clarify. Thanks in advance.


Solution

  • Yes, it's a bit too vague at the moment - you should provide:

    • More details about how you're writing out the files
    • More details about exactly what's in the files afterwards. Use a hex editor to find this out.

    The simplest way of changing what happens in terms of line endings is probably to just be explicit about it in the code. For example, instead of:

    output.WriteLine(foo);
    

    write

    output.Write(foo);
    // Here LineTerminator would be a constant - or you could make
    // it a variable somewhere
    output.Write(LineTerminator);
    

    ... possibly encapsulating this in your own class to make it easier (so you can have your own WriteLine method which does the right thing, perhaps).

    EDIT: I've been assuming that it's your own code writing out the files. If that's not the case, the easiest solution is probably to find or write a tool to convert the files, and put it as a postbuild step. I'm sure such tools exist (I think there was one called dos2unix a while ago) but it may be as easy to write your own as to find one which does exactly what you want.