# Fix ENDOFLINE Build Error in your Continuous Integration

> dotnet format passes locally but fails with ENDOFLINE errors in CI? Mismatched line endings across operating systems are the cause, and .gitattributes is the fix.

- URL: https://blog.nimblepros.com/blogs/end-of-line-snafu/
- Author: [Scott DePouw](https://blog.nimblepros.com/authors/scott/)
- Published: 2024-05-13
- Updated: 2026-11-06
- Categories: [Software Development](https://blog.nimblepros.com/categories/software-development/)
- Publisher: [NimblePros](https://blog.nimblepros.com/)

---

You're being responsible! You want to ensure that merges into your stable source control branch are safe, so you gate any merges with a build, establishing [continuous integration](https://deviq.com/practices/continuous-integration) to validate changes. You build and test your code, and validate your code style guidelines are followed with `dotnet format`. You run this locally prior to your pull request and find no errors. You open a pull request, but there's an error! What gives? Line endings are missing? You have them though!

## Validating Your Build Across Multiple Environments

It's not uncommon for you to develop in one environment or operating system, while your Continuous Integration builds in a different one entirely. I stumbled across this very situation, and error, when developing a GitHub Action for a new application, where my local `dotnet format` identified no changes, but the build was failing anyway. Let's delve into why it happened, and how I fixed it. Shout out to Alex Sikilinda's [blog post](https://sikilinda.com/posts/error-endofline-fix-end-of-line-marker/) that inspired this one, that I have visited on multiple occasions, based on the purple link in my searches.

## Configurations for Editor and Continuous Integration

My `.editorconfig` has a snippet defining line ending rules:

```editorconfig
# New line preferences
end_of_line = crlf
insert_final_newline = true
```

My GitHub Action that gates pull requests into our stable branch runs `dotnet format` to verify that any changes follow the style rules established in `.editorconfig`. Here's a snippet of my GitHub Action's `yaml` file:

```yaml
name: Build and Test Application

on:
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - name: Format
      run: dotnet format --verify-no-changes
```

When this build runs, despite my files having proper line endings, I see a bunch of errors like this:

![GitHub Action Failure Example](https://blog.nimblepros.com/blogs/end-of-line-snafu/github-action-fail-example.png 'GitHub Action Failure Example')

```
/home/runner/work/demo/src/Demo.UI/Program.cs(1,15): error ENDOFLINE: Fix end of line marker. Replace 2 characters with '\r\n\r\n'. [/home/runner/work/demo/src/Demo.UI/Demo.UI.csproj]
```

Note that we use `ubuntu-latest`, so the line endings are different! I'm developing in Windows. We could change our GitHub Action to use `windows-latest`, but that's just a workaround. What if we can't change the build environment? How do we tell our CI to use the same line endings?

## .gitattributes to the Rescue

One line solves the problem! Include a `.gitattributes` file in the root of your repository's files, and instruct it to use the line endings you desire. Recall inside our `.editorconfig` we specified line endings to be `crlf`. We'll do the same in `.gitattributes`:

```editorconfig
* text eol=crlf
```

With this in place, the GitHub action now successfully validates our changes with `dotnet format --verify-no-changes`.

## Resources

- [Alex Sikilinda's blog post](https://sikilinda.com/posts/error-endofline-fix-end-of-line-marker/)
- [Git documentation on gitattributes](https://git-scm.com/docs/gitattributes)
- [How to enforce .NET format using EditorConfig and GitHub Actions (Microsoft Learn)](https://learn.microsoft.com/en-us/community/content/how-to-enforce-dotnet-format-using-editorconfig-github-actions)
