{"id":14667909,"url":"https://github.com/xt0rted/dotnet-run-script","last_synced_at":"2025-04-05T21:06:27.421Z","repository":{"id":37860206,"uuid":"469034236","full_name":"xt0rted/dotnet-run-script","owner":"xt0rted","description":"A dotnet tool to run arbitrary commands from a project's \"scripts\" object","archived":false,"fork":false,"pushed_at":"2025-03-24T19:13:36.000Z","size":632,"stargazers_count":124,"open_issues_count":8,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T20:04:19.303Z","etag":null,"topics":["build-automation","build-automation-tool","build-tool","dotnet","dotnet-tool","dotnet-tools","dotnetcore","hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xt0rted.png","metadata":{"funding":{"github":"xt0rted","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-12T09:14:16.000Z","updated_at":"2025-03-24T19:13:40.000Z","dependencies_parsed_at":"2023-02-16T16:00:58.538Z","dependency_job_id":"b599afff-54a0-40c3-8c72-42c0d5ae5463","html_url":"https://github.com/xt0rted/dotnet-run-script","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xt0rted%2Fdotnet-run-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xt0rted%2Fdotnet-run-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xt0rted%2Fdotnet-run-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xt0rted%2Fdotnet-run-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xt0rted","download_url":"https://codeload.github.com/xt0rted/dotnet-run-script/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399873,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-automation","build-automation-tool","build-tool","dotnet","dotnet-tool","dotnet-tools","dotnetcore","hacktoberfest"],"created_at":"2024-09-12T01:00:35.453Z","updated_at":"2025-04-05T21:06:27.390Z","avatar_url":"https://github.com/xt0rted.png","language":"C#","readme":"# \u003cimg src=\"assets/icon.svg\" align=\"left\" height=\"45\"\u003e dotnet-run-script\n\n[![CI build status](https://github.com/xt0rted/dotnet-run-script/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/xt0rted/dotnet-run-script/actions/workflows/ci.yml)\n[![NuGet Package](https://img.shields.io/nuget/v/run-script?logo=nuget)](https://www.nuget.org/packages/run-script)\n[![GitHub Package Registry](https://img.shields.io/badge/github-package_registry-yellow?logo=nuget)](https://nuget.pkg.github.com/xt0rted/index.json)\n[![Project license](https://img.shields.io/github/license/xt0rted/dotnet-run-script)](LICENSE)\n\nA `dotnet` tool to run arbitrary commands from a project's \"scripts\" object.\nIf you've used `npm` this is the equivalent of `npm run` with almost identical functionality and options.\nIt is compatible with .NET Core 3.1 and newer.\n\nSee [the about page](docs/README.md) for more information on how this tool came to be and why it exists at all.\n\n## Installation\n\nThis tool is meant to be used as a dotnet local tool.\nTo install it run the following:\n\n```console\ndotnet new tool-manifest\ndotnet tool install run-script\n```\n\n\u003e [!WARNING]\n\u003e Installing this tool globally is not recommended.\n\u003e PowerShell defines the alias `r` for the `Invoke-History` command which prevents this from being called.\n\u003e You'll also run into issues calling this from your scripts since global tools don't use the `dotnet` prefix.\n\n## Keeping current\n\nTools like [Dependabot](https://github.com/github/feedback/discussions/13825) and [Renovate](https://github.com/marketplace/renovate) don't currently support updating dotnet local tools.\nOne way to automate this is to use a [GitHub Actions workflow](https://github.com/xt0rted/dotnet-tool-update-test) to check for updates and create PRs when new versions are available, which is what this repo does.\n\n## Options\n\nName | Description\n-- | --\n`--if-present` | Don't exit with an error code if the script isn't found\n`--script-shell` | The shell to use when running scripts (cmd, pwsh, sh, etc.)\n`-v`, `--verbose` | Enable verbose output\n`--version` | Show version information\n`--help` | Show help and usage information\n\nArguments passed after the double dash are passed through to the executing script.\n\n```console\ndotnet r build --verbose -- --configuration Release\n```\n\n### Color output\n\nThis tool supports the `DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION` environment variable.\nSetting this to `1` or `true` will force color output on all platforms.\nDue to a limitation of the `Console` apis this will not work on Windows when output is redirected in environments such as GitHub Actions.\n\nThere is also support for the `NO_COLOR` environment variable.\nSetting this to any value will disable color output.\n\n### GitHub Actions\n\nOn GitHub Actions you need to set the environment values `DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION` and `TERM`.\n`TERM` should be `xterm` or `xterm-256color`.\n\n## Configuration\n\nIn your project's `global.json` add a `scripts` object:\n\n```jsonc\n{\n  \"sdk\": {\n    \"version\": \"8.0.203\",\n    \"rollForward\": \"latestPatch\"\n  },\n  \"scriptShell\": \"pwsh\", // Optional\n  \"scripts\": {\n    \"build\": \"dotnet build --configuration Release\",\n    \"test\": \"dotnet test --configuration Release\",\n    \"ci\": \"dotnet r build \u0026\u0026 dotnet r test\",\n  }\n}\n```\n\n\u003e [!NOTE]\n\u003e The shell used depends on the OS.\n\u003e On Windows `CMD` is used, on Linux, macOS, and WSL `sh` is used.\n\u003e This can be overridden by setting the `scriptShell` property or by passing the `--script-shell` option with the name of the shell to use.\n\nThe `env` command is a special built-in command that lists all available environment variables.\nYou can override this with your own command if you wish.\n\n## Usage\n\nUse `dotnet r [\u003cscripts\u003e...] [options]` to run the scripts.\nAnything you can run from the command line can be used in a script.\nYou can also call other scripts to chain them together such as a `ci` script that calls the `build`, `test`, and `package` scripts.\n\nTo help keep your configuration easy to read and maintain `pre` and `post` scripts are supported.\nThese are run before and after the main script.\n\nThis is an example of a `pre` script that clears the build artifacts folder, and a `post` script that writes to the console saying the command completed.\n\n```json\n{\n  \"scripts\": {\n    \"prepackage\": \"del /Q ./artifacts\",\n    \"package\": \"dotnet pack --configuration Release --no-build --output ./artifacts\",\n    \"postpackage\": \"echo \\\"Packaging complete\\\"\"\n  }\n}\n```\n\n### Multiple script execution\n\nMultiple scripts can be called at the same time like so:\n\n```console\ndotnet r build test\n```\n\nThis will run the `build` script and if it returns a `0` exit code it will then run the `test` script.\nThe `--if-present` option can be used to skip scripts that don't exist.\n\n```json\n{\n  \"scripts\": {\n    \"build\": \"dotnet build\",\n    \"test:unit\": \"dotnet test\",\n    \"package\": \"dotnet pack\"\n  }\n}\n```\n\n```console\ndotnet r build test:unit test:integration package --if-present\n```\n\nArguments passed after the double dash are passed through to each executing script.\nIn this example both the `--configuration` and `--framework` options will be passed to each of the four scripts when running them.\n\n```console\ndotnet r build test:unit test:integration package -- --configuration Release --framework net8.0\n```\n\n### Globbing or wildcard support\n\nMultiple scripts can be run at the same time using globbing.\nThis means `dotnet r test:*` will match `test:unit` and `test:integration` and run them in series in the order they're listed in the `global.json` file.\n\nGlobbing is handled by the [DotNet.Glob](https://github.com/dazinator/DotNet.Glob) library and currently supports all of its patterns and wildcards.\n\n### Working directory\n\nThe working directory is set to the root of the project where the `global.json` is located.\nIf you need to get the folder the command was executed from you can do so using the `INIT_CWD` environment variable.\n\n## Common build environments\n\nWhen using this tool on a build server, such as GitHub Actions, you might want to use a generic workflow that calls a common set of scripts such as `build`, `test`, and `package`.\nThese might not be defined in all of your projects and if a script that doesn't exist is called an error is returned.\nTo work around this you can call them with the `--if-present` flag which will return a `0` exit code for not found scripts.\n\nExample shared GitHub Actions workflow:\n\n```yaml\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v3\n\n      # Always runs\n      - name: Run build\n        run: dotnet r build\n\n      # Only runs if `test` script is present\n      - name: Run test\n        run: dotnet r test --if-present\n\n      # Only runs if `package` script is present\n      - name: Run package\n        run: dotnet r package --if-present\n```\n","funding_links":["https://github.com/sponsors/xt0rted"],"categories":["Alternatives"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxt0rted%2Fdotnet-run-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxt0rted%2Fdotnet-run-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxt0rted%2Fdotnet-run-script/lists"}