Skip to content
code

GitHub Action

ZyAction: .NET Lint

v1.1.0 Latest version

ZyAction: .NET Lint

code

ZyAction: .NET Lint

A GitHub Action to lint .NET projects

Installation

Copy and paste the following snippet into your .yml file.

              

- name: ZyAction: .NET Lint

uses: zyactions/dotnet-lint@v1.1.0

Learn more about this action in zyactions/dotnet-lint

Choose a version

.NET Lint

License: MIT CI Ubuntu macOS Windows

A GitHub Action to lint .NET projects.

Features

  • Lints .NET projects using the official dotnet format .NET CLI tool
  • Creates pull request annotations for detected code style violations
  • Registers a problem matcher for error output
  • Supports all platforms (Linux, macOS, Windows)

Usage

Lint

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: .NET Lint
    uses: zyactions/dotnet-lint@v1
    with:
      workspace: test
      implicit-restore: true

Note

Unlike the wrapped dotnet format command, this action does not perform an implicit package restore by default. A manual package restore (e.g. using zyactions/dotnet-restore) is required by design.

Set implicit-restore to true to switch back to the original behavior.

Lint a specific Project- or Solution

steps:
steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: .NET Lint
    uses: zyactions/dotnet-lint@v1
    with:
      workspace: test/Test.csproj
      implicit-restore: true

Lint only specific Files using a Glob Pattern

steps:
  - name: Checkout
    uses: actions/checkout@v3

  - name: Glob Match
    id: glob
    uses: zyactions/glob@v2
    with:
      pattern: |
        test/*.cs
        !test/*.AutoGenerated.cs
      return-pipe: true

  - name: .NET Lint
    uses: zyactions/dotnet-lint@v1
    with:
      workspace: test/Test.csproj
      include: '-'
      pipe: ${{ steps.glob.outputs.pipe }}
      implicit-restore: true

Inputs

working-directory

The working-directory for the action.

Defaults to the repository root directory (github.workspace).

Note

If a specific .NET SDK version is to be used, the working directory must point to the directory that contains the global.json or a subdirectory of it.

workspace

The Visual Studio workspace (directory, project- or solution-file).

This path is relative to the working-directory unless an absolute path is used.

The dotnet format command automatically searches for a Visual Studio Solution file (*.sln) in the specified workspace directory, if no explicit solution- or project- file is specified.

Example values:

  • path/to/workspace
  • path/to/Solution.sln
  • path/to/Project.csproj

diagnostics

A newline-separated list of diagnostic IDs to use as a filter when linting code style or third-party issues. Default value is whichever IDs are listed in the .editorconfig file. For a list of built-in analyzer rule IDs that you can specify, see the list of IDs for code-analysis style rules.

severity

The minimum severity of diagnostics to lint. Allowed values are info, warn, and error. The default value is warn.

include

A newline-separated list of relative file or folder paths to include in linting. The default is all files in the solution or project.

Use - to read the list of files from the pipe input.

exclude

A newline-separated list of relative file or folder paths to exclude from linting.

The default is none.

Use - to read the list of files from the pipe input.

report-path

Produces a JSON report in the specified directory.

implicit-restore

Execute an implicit restore before linting.

use-standalone-tool

Uses the standalone version of the dotnet-format tool instead of the version bundled with the .NET SDK.

pipe

An optional pipe input from which the include or exclude filenames are to be read.

This must be set to a valid shell command line (bash) that can be used for piping. The command must output to stdout and separate the individual filenames by line breaks.

Warning

The command passed to this input will be evaluated and should not come from untrusted sources.

Requirements

The .NET CLI needs to be installed on the runner. To be independent from the GitHub defaults, it's recommended to install a specific version of the SDK prior to calling this action.

To install the .NET SDK in your workflow, the following actions can be used:

Dependencies

This action uses the following GitHub Actions dependencies:

Versioning

Versions follow the semantic versioning scheme.

License

.NET Lint Action is licensed under the MIT license.