Giter Site home page Giter Site logo

fabriziobagala / dotnet-bulk-package-updater Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 24 KB

A Bash script designed to streamline the process of updating NuGet packages in .NET projects.

License: MIT License

Shell 100.00%
bash devtools dotnet nuget terminal unix automation developers

dotnet-bulk-package-updater's Introduction

dotnet-bulk-package-updater

A Bash script designed to streamline the process of updating NuGet packages in .NET projects.

Features

  • Update packages in multiple .csproj files at once
  • Selectively update specific packages
  • Include pre-release package versions in updates
  • Provide summary of the update process

Prerequisites

To use this script, you need:

  • Bash shell (Unix/Linux/macOS or Windows with WSL/Git Bash)
  • .NET SDK

Installation

  1. Clone the repository or download the script.

  2. Make the script executable:

    chmod +x dotnet-bulk-package-updater.sh
  3. To ensure that the line endings in the script file are in Unix format, follow the dos2unix command on the script:

    dos2unix dotnet-bulk-package-updater.sh
  4. Place the script in the root directory of your .NET solution to ensure it can find .csproj files recursively.

Usage

To use the script, you have the following options:

./dotnet-bulk-package-updater.sh [-p <projects>] [-k <packages>] [-r]
  • -p: Specify one or multiple project files separated by semicolons (;). If omitted, all .csproj files will be considered.
  • -k: Specify one or multiple packages separated by semicolons (;). If omitted, all outdated packages will be updated.
  • -r: Include pre-release versions in the update process.

Examples

  • Update all packages in all projects:

    ./dotnet-bulk-package-updater.sh
  • Include pre-release versions in updates:

    ./dotnet-bulk-package-updater.sh -r
  • Update all packages in a specific project:

    ./dotnet-bulk-package-updater.sh -p "MyProject.csproj"
  • Update all packages in specific projects:

    ./dotnet-bulk-package-updater.sh -p "MyProject.csproj;MyProject.Tests.csproj"
  • Update a specific package in all projects:

    ./dotnet-bulk-package-updater.sh -k "Newtonsoft.Json"
  • Update specific packages in all projects:

    ./dotnet-bulk-package-updater.sh -k "Dapper;Newtonsoft.Json"
  • Update specific packages in a specific project:

    ./dotnet-bulk-package-updater.sh -p "MyProject.csproj" -k "Dapper;Newtonsoft.Json"
  • Update specific packages in a specific project including pre-release versions:

    ./dotnet-bulk-package-updater.sh -p "MyProject.csproj" -k "Dapper;Newtonsoft.Json" -r

Output

The script provides a succinct output for each action it performs. Upon completion, it presents a summary like the following:

3 packages updated, 1 project not found, 2 packages not found, 1 package not outdated

Detailed script walkthrough

Script structure

  1. Shebang declaration and temporary file: At the beginning of the script, the shebang (#!/bin/bash) is defined, which informs the system that this script should be executed in a Bash environment. Right after, a temporary file is created to track the number of updated packages.

  2. Variables: A variable include_prerelease is defined to determine whether or not to include pre-release versions of packages in the update process.

  3. Function update_package: This function is responsible for updating a specific package within a .csproj file. It accepts as arguments the path to the .csproj file, the package name, version, and a flag indicating whether to consider pre-release versions.

  4. Option parsing: Option parsing is performed using the getopts construct. The options are -p to specify projects, -k for packages, and -r to include pre-release versions. These options allow users to specify exactly which projects and packages should be updated.

  5. Counters: Several counters are initialized to track the number of not found projects and packages, and non-outdated packages.

  6. Project selection: The case where no specific projects have been provided as input is handled. In this case, the script will consider all .csproj files.

  7. Splitting inputs: The inputs for projects and packages are split into arrays to facilitate processing.

  8. Main loop: The script loops through each specified project. For each project, it checks for .csproj files and then proceeds to loop through them.

  9. Package updating: For each project file found, the script updates all outdated packages if no individual packages have been specified. If specific packages have been provided, it updates only those.

  10. Summary and cleanup: At the end, the script reads the total count of updated packages from the temporary file, then removes the temporary file and provides a summary of the operation, including counters for not found projects and packages, and non-outdated packages.

Additional functions

  • Function pluralize: A small utility function that pluralizes a word based on the count provided, to make the output more readable.

  • Construction of summary message: A summary message is constructed that lists the number of updated packages, the number of projects and packages not found, and the number of non-outdated packages.

Error handling considerations

  • Success operation check: After each attempt to update a package, the script checks if the operation succeeded and increments the counter accordingly. If it fails, it provides an error message.

  • Handling of not found files and non-outdated packages: If a project script or a package is not found, or if a package is not outdated, the script handles these cases without interrupting execution, providing an informative message.

Troubleshooting

If you encounter any issues while running the script, ensure that:

  • You have the correct permissions to modify the .csproj files.
  • The .NET Core SDK is properly installed and the dotnet CLI is accessible from your terminal.
  • You are running the script in the correct directory or providing the right paths to your .csproj files.

License

This project is licensed under the MIT License. See the LICENSE file for details.

dotnet-bulk-package-updater's People

Contributors

fabriziobagala avatar

Stargazers

Marco Minerva avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.