### Get Version Example Source: https://github.com/adamralph/minver/blob/main/_autodocs/summary.md Demonstrates how to use the Versioner.GetVersion method to retrieve the project version with various configuration options. ```csharp using MinVer.Lib; var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "v", minMajorMinor: new MajorMinor(2, 0), buildMeta: "ci.123", autoIncrement: VersionPart.Minor, defaultPreReleaseIdentifiers: new[] { "alpha", "0" }, ignoreHeight: false, log: new ConsoleLogger()); Console.WriteLine(version); ``` -------------------------------- ### minver-cli Options Example Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md An example demonstrating various command-line options for minver-cli, including auto-increment, build metadata, and version overrides. ```bash minver-cli /path/to/repo \ --auto-increment minor \ --build-metadata build.123 \ --default-pre-release-identifiers rc.0 \ --ignore-height \ --minimum-major-minor 2.0 \ --tag-prefix v \ --verbosity detailed \ --version-override 1.2.3 ``` -------------------------------- ### GetVersion Example Usage Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/versioner.md An example demonstrating how to call the GetVersion method with various parameters to calculate a semantic version. ```csharp var log = new ConsoleLogger(); var version = await Versioner.GetVersion( workDir: "/path/to/repo", tagPrefix: "v", minMajorMinor: new MajorMinor(1, 0), buildMeta: "ci.123", autoIncrement: VersionPart.Minor, defaultPreReleaseIdentifiers: new[] { "alpha", "0" }, ignoreHeight: false, log: log); Console.WriteLine(version); // e.g., "1.2.3-alpha.0.5+ci.123" ``` -------------------------------- ### Install minver-cli Globally Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Installs the minver-cli tool globally using the .NET CLI. Use `minver-cli --help` to verify the installation. ```bash dotnet tool install -g minver-cli minver-cli --help ``` -------------------------------- ### Example MinVer Configuration in .NET Project File Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md This example demonstrates a typical .NET project file configuration for MinVer, including settings for auto-increment, build metadata, pre-release identifiers, minimum version, tag prefix, and verbosity. ```xml net8.0 latest minor $(BUILD_NUMBER) rc.0 false 2.0 v detailed ``` -------------------------------- ### Install minver-cli Locally Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Installs the minver-cli tool locally for the current project using the .NET CLI. Use `dotnet minver-cli --help` to verify the installation. ```bash dotnet tool install minver-cli dotnet minver-cli --help ``` -------------------------------- ### CLI Usage Examples for MinVer Source: https://github.com/adamralph/minver/blob/main/_autodocs/overview.md Provides examples of using the minver-cli command-line tool with various options for version calculation and configuration. ```bash # Basic version calculation minver-cli . # With tag prefix minver-cli . --tag-prefix v # With custom pre-release identifiers minver-cli . --default-pre-release-identifiers rc.0 # With minimum version constraint minver-cli . --minimum-major-minor 2.0 # With verbose logging minver-cli . --verbosity diagnostic # Multiple options minver-cli /repo/path \ --tag-prefix release- \ --auto-increment minor \ --build-metadata build.789 ``` -------------------------------- ### Get Version using MinVer CLI Source: https://github.com/adamralph/minver/blob/main/_autodocs/README.md Demonstrates how to get the version using the MinVer command-line interface. ```bash minver-cli . --tag-prefix v --minimum-major-minor 2.0 ``` -------------------------------- ### minver-cli with Multiple Options Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md An example combining several minver-cli options, including tag prefix, minimum version, auto-increment, verbosity, and build metadata. ```bash minver-cli /path/to/repo \ --tag-prefix release- \ --minimum-major-minor 3.0 \ --auto-increment minor \ --verbosity detailed \ --build-metadata build.789 ``` -------------------------------- ### Get Version using C# Library Source: https://github.com/adamralph/minver/blob/main/_autodocs/README.md Demonstrates how to get the version using the MinVer C# library. Requires importing the MinVer.Lib namespace. ```csharp var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "v", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: new MyLogger()); ``` -------------------------------- ### Scenario: Using Defaults in Versioner.GetVersion Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md This example shows MinVer using its default pre-release identifiers when calculating a version. It highlights the expected output with and without Git tags, demonstrating how the height and default identifiers are incorporated. ```csharp // MinVer with default identifiers var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "v", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: new ConsoleLogger()); // With Git history: no tags → "0.0.0-alpha.0.{height}" // With Git history: tag v1.0.0 at current commit → "1.0.0" // With Git history: tag v1.0.0 3 commits back → "1.0.1-alpha.0.3" ``` -------------------------------- ### MinVer CLI Scripting Examples Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Shows how to capture the MinVer output into a variable for use in scripts, Docker builds, or Git operations. The `--tag-prefix` option can be used to include a prefix in the version string. ```bash VERSION=$(minver-cli .) echo "Building version $VERSION" ``` ```bash # In Docker docker build -t myapp:$(minver-cli .) . ``` ```bash # In scripts VERSION=$(minver-cli . --tag-prefix v) git tag $VERSION git push --tags ``` -------------------------------- ### Install MinVer NuGet Package Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md Add the MinVer NuGet package to your project file. Use PrivateAssets="All" to prevent MinVer from becoming a transitive dependency. ```xml ``` -------------------------------- ### Example: Throwing NoGitException on Git Failure Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/no-git-exception.md Illustrates catching a Win32Exception from a failed Git command and re-throwing it as a NoGitException. ```csharp try { // Git command fails var output = await GitCommand.TryRun("log --pretty=format:\"%H\"", ".", logger); } catch (Win32Exception ex) { throw new NoGitException("\"git\" is not present in PATH.", ex); } ``` -------------------------------- ### Pre-release Identifier Format Examples Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md Illustrates how collections of pre-release identifiers are formatted into version strings. Each element in the collection becomes a dot-separated segment in the final version. ```text - Collection: ["alpha", "0"] → Version string: "1.2.3-alpha.0" - Collection: ["beta", "1", "2"] → Version string: "1.2.3-beta.1.2" - Collection: ["rc"] → Version string: "1.2.3-rc" ``` -------------------------------- ### Docker Build with MinVer Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Use MinVer to determine the version and tag Docker images. Requires MinVer CLI to be installed in the build stage. ```dockerfile FROM mcr.microsoft.com/dotnet/sdk:8.0 as builder WORKDIR /build COPY . . # Calculate version RUN dotnet tool install -g minver-cli RUN VERSION=$(minver-cli .) && \ dotnet publish -c Release -o /app -p:InformationalVersion=$VERSION FROM mcr.microsoft.com/dotnet/runtime:8.0 WORKDIR /app COPY --from=builder /app . ENTRYPOINT ["dotnet", "MyApp.dll"] ``` -------------------------------- ### Consistent Git Tagging Example Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Demonstrates consistent Git tagging using a prefix (e.g., 'v') versus inconsistent tagging without a prefix. Consistent tagging is crucial for MinVer accuracy. ```bash git tag v1.0.0 # Consistent format git tag 1.0.0 # vs. inconsistent ``` -------------------------------- ### Scenario: Custom RC Identifiers in Versioner.GetVersion Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md This example demonstrates using custom release candidate ('rc') identifiers with `Versioner.GetVersion`. It shows the resulting version string when no tags exist and when a tag is present, illustrating the application of custom pre-release suffixes. ```csharp // MinVer with custom RC identifiers var customIdentifiers = new[] { "rc", "0" }; var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: customIdentifiers, ignoreHeight: false, log: new ConsoleLogger()); // With Git history: no tags → "0.0.0-rc.0.{height}" // With Git history: tag 1.0.0 3 commits back → "1.0.1-rc.0.3" ``` -------------------------------- ### Calculate Version in C# Source: https://github.com/adamralph/minver/blob/main/_autodocs/README.md Use the MinVer.Lib library to programmatically get the version. Ensure a logger is provided. ```csharp using MinVer.Lib; var log = new ConsoleLogger(); var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: log); Console.WriteLine($"Version: {version}"); ``` -------------------------------- ### Using ILogger with Versioner.GetVersion Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/ilogger.md Example of passing an ILogger implementation to the Versioner.GetVersion method to receive diagnostic output during version calculation. ```csharp var logger = new MyLogger(); var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: logger); // The logger receives messages throughout the process: // Info: "Calculated version 1.2.3-alpha.0.5." // Debug: "123 commits checked." // etc. ``` -------------------------------- ### minver-cli Output on NoGitException Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/no-git-exception.md Shows the expected output and exit code when the minver-cli tool encounters a NoGitException, such as when Git is not installed. ```bash $ minver-cli . Error: "git" is not present in PATH. Exit code: 1 ``` -------------------------------- ### Use MinVer CLI Tool via Path Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md If the MinVer CLI tool is installed but not in the PATH, you can execute it directly using its path. This is an alternative to global reinstallation. ```bash # Or use via path dotnet $(~/.dotnet/tools/minver-cli) . ``` -------------------------------- ### Configure MinVer Input Properties Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md Set these properties in your project file to configure MinVer's version calculation behavior. Examples include auto-increment, build metadata, default pre-release identifiers, and version overrides. ```xml minor build.123 rc.0 false 2.0 v detailed 1.2.3 ``` -------------------------------- ### MinVer CLI Exit Code Examples Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Demonstrates the exit codes returned by the minver-cli for success, Git errors, and configuration errors. Check the exit code using `echo $?` immediately after the command. ```bash # Success $ minver-cli . 1.2.3 $ echo $? 0 ``` ```bash # Git error (Git not installed) $ minver-cli . Error: "git" is not present in PATH. $ echo $? ``` ```bash # Invalid option $ minver-cli . --auto-increment invalid Error: Invalid auto-increment option: invalid. Valid values: major, minor, or patch (default). $ echo $? ``` -------------------------------- ### Set Dynamic MinVer Build Metadata Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md Reference environment variables or other properties to set MinVer build metadata. This example sets the build metadata to the BuildNumber environment variable, falling back to 'local' if BuildNumber is not set. ```xml $(BuildNumber) local ``` -------------------------------- ### Tag a Commit for Versioning Source: https://github.com/adamralph/minver/blob/main/README.md Use this command to tag a commit and initiate versioning within a specific MAJOR.MINOR range. This tag is for internal use to guide MinVer and is not intended for release. ```shell git tag 1.0.0-alpha.0 ``` -------------------------------- ### Handle NoGitException in C# Source: https://github.com/adamralph/minver/blob/main/_autodocs/errors.md Catch NoGitException when Git is not installed or not in the system's PATH. This example shows basic error logging and exiting with a non-zero status code. ```csharp try { var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: new ConsoleLogger()); } catch (NoGitException ex) { Console.WriteLine($"Error: Git is not installed or not in PATH"); Console.WriteLine($"Details: {ex.Message}"); return 1; } ``` -------------------------------- ### MinVer CLI with Multiple Options Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Demonstrates complex configuration using multiple command-line options for tag prefix, minimum version, auto-increment, build metadata, and verbosity. ```bash $ minver-cli /path/to/repo \ --tag-prefix release- \ --minimum-major-minor 3.0 \ --auto-increment minor \ --build-metadata build.456 \ --verbosity detailed ``` -------------------------------- ### Basic minver-cli Usage Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Demonstrates the most basic usage of the minver-cli tool with default settings, specifying only the current directory. ```bash minver-cli . ``` -------------------------------- ### Get Version in GitHub Actions Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Sets the version as a GitHub Actions output variable using minver-cli. ```yaml - name: Get version id: minver run: | VERSION=$(minver-cli .) echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Build run: dotnet build -p:AssemblyVersion=${{ steps.minver.outputs.version }} ``` -------------------------------- ### Correct SDK-style Project Configuration Source: https://github.com/adamralph/minver/blob/main/_autodocs/errors.md This is a correct SDK-style project configuration that allows MinVer to operate. It includes the 'Microsoft.NET.Sdk' Sdk attribute and specifies a target framework. ```xml net8.0 ``` -------------------------------- ### Display Minver CLI Help Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Use this command to view all available options and commands for the Minver CLI. This is useful for understanding the full capabilities of the tool. ```bash minver-cli --help ``` -------------------------------- ### MinVer CLI with Tag Prefix Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Specify a tag prefix to filter Git tags, matching only those that start with 'v'. ```bash $ minver-cli . --tag-prefix v 2.0.0-alpha.0.5 ``` -------------------------------- ### Basic Library Usage in C# Source: https://github.com/adamralph/minver/blob/main/_autodocs/overview.md Demonstrates how to use the MinVer library in C# to calculate a version. Ensure you have a compatible ILogger implementation. ```csharp using MinVer.Lib; // Create a logger var log = new ConsoleLogger(); // Your ILogger implementation // Calculate version var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: log); Console.WriteLine(version); // e.g., "1.2.3-alpha.0.5" ``` -------------------------------- ### minver-cli with Build Metadata Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Illustrates adding build metadata, like 'ci.456', to the version string using the --build-metadata option in minver-cli. ```bash minver-cli . --build-metadata ci.456 ``` -------------------------------- ### Get Version in Bash Script Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Calculates the version using minver-cli in a Bash script and extracts major and minor components. ```bash #!/bin/bash set -euo pipefail VERSION=$(minver-cli .) echo "Calculated version: $VERSION" # Extract components MAJOR=$(echo $VERSION | cut -d. -f1) MINOR=$(echo $VERSION | cut -d. -f2) echo "Major: $MAJOR, Minor: $MINOR" ``` -------------------------------- ### Create Default Version Object Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md Shows how to create a `Version` object using the default pre-release identifiers. This is a straightforward way to instantiate a version with MinVer's standard pre-release suffix. ```csharp // Create default version 0.0.0-alpha.0 var defaultVersion = new Version(PreReleaseIdentifiers.Default); Console.WriteLine(defaultVersion); // "0.0.0-alpha.0" ``` -------------------------------- ### Get Version in PowerShell Script Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Retrieves the version using minver-cli in a PowerShell script and extracts version components using regex. ```powershell $version = & minver-cli . Write-Host "Version: $version" # Extract using regex if ($version -match '(\d+)\.(\d+)\.(\d+)') { $major = $matches[1] $minor = $matches[2] $patch = $matches[3] } ``` -------------------------------- ### minver-cli with Tag Prefix Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Shows how to use the --tag-prefix option to specify a prefix for version tags when running minver-cli. ```bash minver-cli . --tag-prefix v ``` -------------------------------- ### Ensure Minimum Major.Minor Version Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/version.md Use Satisfying to get a version that meets a minimum major.minor requirement, potentially bumping the version. ```csharp public Version Satisfying( MajorMinor minMajorMinor, IReadOnlyCollection defaultPreReleaseIdentifiers) ``` ```csharp var version = new Version(1, 2, 3, new[] { "rc", "1" }, 0, ""); var satisfied = version.Satisfying( new MajorMinor(2, 0), new[] { "alpha", "0" }); // Returns 2.0.0-alpha.0 (bumped to satisfy minimum 2.0) ``` -------------------------------- ### minver-cli with Custom Pre-Release Identifiers Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Demonstrates how to specify custom pre-release identifiers, such as 'beta.1', using the --default-pre-release-identifiers option. ```bash minver-cli . --default-pre-release-identifiers beta.1 ``` -------------------------------- ### Specify Tag Prefix Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Sets a prefix that version tags must start with. This is useful for filtering tags that are not part of the versioning scheme. ```bash minver-cli . --tag-prefix v minver-cli . -t "release-" ``` -------------------------------- ### GetVersion with Default Identifiers Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md Demonstrates how to implicitly use the default pre-release identifiers by passing `PreReleaseIdentifiers.Default` to the `GetVersion` method. This is useful when you want to ensure MinVer uses its standard pre-release naming convention. ```csharp // Using the default identifiers implicitly var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, // Explicitly pass Default ignoreHeight: false, log: new ConsoleLogger()); // Result (e.g., if no tags exist): "0.0.0-alpha.0.{height}" ``` -------------------------------- ### Restore and Build .NET Project Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Restore project dependencies and build the project. The MinVer target runs automatically during the build process. ```bash dotnet restore dotnet build ``` -------------------------------- ### MSBuild Integration for MinVer Source: https://github.com/adamralph/minver/blob/main/_autodocs/overview.md Shows how to configure MinVer properties within a .csproj file for automatic versioning. Includes necessary package reference. ```xml minor ci.123 v 2.0 ``` -------------------------------- ### Disable MinVer for Debug Builds Source: https://github.com/adamralph/minver/blob/main/README.md Set MinVerSkip to true to disable MinVer. This example shows how to disable it specifically for debug builds using a condition. ```xml true ``` -------------------------------- ### Basic MinVer CLI Usage Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Calculate the version from the current directory using all default settings. ```bash $ cd /path/to/repo $ minver-cli 1.2.3 ``` -------------------------------- ### Version Constructor Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/version.md Creates a default version (0.0.0) with the specified pre-release identifiers. ```APIDOC ## Constructor ### Signature ```csharp public Version(IReadOnlyCollection defaultPreReleaseIdentifiers) ``` ### Description Creates a default version (0.0.0) with the specified pre-release identifiers. ### Parameters #### Path Parameters - **defaultPreReleaseIdentifiers** (IReadOnlyCollection) - Required - Pre-release identifiers to use in the default version. Usually ["alpha", "0"]. ### Request Example ```csharp var version = new Version(new[] { "alpha", "0" }); Console.WriteLine(version); // "0.0.0-alpha.0" ``` ``` -------------------------------- ### minver-cli with Minimum Version Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Illustrates setting a minimum major.minor version constraint using the --minimum-major-minor option in minver-cli. ```bash minver-cli . --minimum-major-minor 2.0 ``` -------------------------------- ### minver-cli with Detailed Logging Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Shows how to enable detailed logging output from the minver-cli tool by using the --verbosity detailed option. ```bash minver-cli . --verbosity detailed ``` -------------------------------- ### Configure MinVer in MSBuild Project Source: https://github.com/adamralph/minver/blob/main/_autodocs/README.md Shows how to configure MinVer by adding properties to your MSBuild project file. ```xml v 2.0 ``` -------------------------------- ### MinVer Warning 1001 Example Source: https://github.com/adamralph/minver/blob/main/_autodocs/errors.md This C# code demonstrates how MinVer emits warning 1001 when the provided 'workDir' is not a valid Git repository. The log will receive a message indicating the issue and the use of a default version. ```csharp var log = new ConsoleLogger(); // If workDir is not a Git repo var version = await Versioner.GetVersion( workDir: "/non/git/directory", // ... other parameters log: log); // Log receives warning with code 1001 // Message: "'/non/git/directory' is not a valid Git working directory. Using default version 0.0.0-alpha.0." ``` -------------------------------- ### Initialize Git Repository for MinVer CLI Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Ensure your project has a Git repository initialized and committed before using the MinVer CLI. ```bash git init git add . git commit -m "Initial commit" ``` -------------------------------- ### Recommended Default Pre-Release Identifiers Configuration Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Illustrates the recommended way to configure default pre-release identifiers using `--default-pre-release-identifiers`. This is the modern approach to setting pre-release phases. ```bash # New way (recommended) minver-cli . --default-pre-release-identifiers alpha.0 ``` -------------------------------- ### Version.WithHeight Method Source: https://github.com/adamralph/minver/blob/main/_autodocs/summary.md Creates a new Version with a specified height, auto-increment part, and pre-release identifiers. ```csharp WithHeight(int, VersionPart, IReadOnlyCollection) → Version ``` -------------------------------- ### Set Minimum Major Minor Version in MSBuild Source: https://github.com/adamralph/minver/blob/main/README.md Configure MinVer to use a default version starting with a specific MAJOR.MINOR range by setting the MinVerMinimumMajorMinor property in your MSBuild project file. This is useful for interim builds before the first official tag. ```xml 1.0 ``` -------------------------------- ### Tagging for Multiple Release Branches Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Demonstrates how to use different tag prefixes for main and maintenance release branches. This strategy allows for distinct versioning tracks. ```bash # Main branch releases git tag release/1.0.0 # Maintenance branch releases git tag maint-0.9/0.9.5 ``` ```xml # In project: release/ # On maintenance branch: maint-0.9/ ``` -------------------------------- ### MinVer CLI Arguments Source: https://github.com/adamralph/minver/blob/main/_autodocs/summary.md Shows the available command-line arguments for the minver-cli tool, including shorthand options. These arguments allow direct configuration of MinVer's behavior when run from the command line. ```bash minver-cli [workingDirectory] \ [--auto-increment | -a] VALUE \ [--build-metadata | -b] VALUE \ [--default-pre-release-identifiers | -p] VALUE \ [--ignore-height | -i] \ [--minimum-major-minor | -m] VALUE \ [--tag-prefix | -t] VALUE \ [--verbosity | -v] VALUE \ [--version-override | -o] VALUE ``` -------------------------------- ### MinVer CLI with Build Metadata Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Append build metadata, such as 'ci.789', to the calculated version. ```bash $ minver-cli . --build-metadata ci.789 1.2.3-alpha.0.5+ci.789 ``` -------------------------------- ### Configure MinVer in Project File Source: https://github.com/adamralph/minver/blob/main/_autodocs/README.md Configure MinVer settings directly within your project file for build-time integration. Include the MinVer NuGet package. ```xml minor v 2.0 ``` -------------------------------- ### Checking MinVer Option Values Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/options.md Demonstrates how to check if specific MinVer options have been set and how to access their values. This is useful for conditional logic based on configuration. ```csharp if (options.AutoIncrement.HasValue) { // Use options.AutoIncrement.Value } if (options.BuildMeta != null) { // Use options.BuildMeta } if (options.MinMajorMinor != null) { // Use options.MinMajorMinor } ``` -------------------------------- ### GitHub Actions CI/CD with MinVer Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Automate build and release using GitHub Actions. Fetches full history for version calculation and sets the version as an output. ```yaml name: Build and Release on: push: tags: - 'v*' jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Full history for version calculation - uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - run: dotnet build -c Release - name: Get version id: version run: | VERSION=$(dotnet minver-cli .) echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Create NuGet package run: dotnet pack -c Release -o ./artifacts - name: Publish to NuGet run: | dotnet nuget push ./artifacts/*.nupkg \ -k ${{ secrets.NUGET_API_KEY }} \ -s https://api.nuget.org/v3/index.json ``` -------------------------------- ### GitLab CI with MinVer for Packaging and Release Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Utilize GitLab CI to build, test, package, and release NuGet packages using MinVer for versioning. Requires NUGET_API_KEY to be set as a CI/CD variable. ```yaml stages: - build - test - package - release variables: DOTNET_VERSION: "8.0" build: stage: build image: mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} script: - dotnet build -c Release artifacts: paths: - bin/Release/ test: stage: test image: mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} script: - dotnet test -c Release --no-build package: stage: package image: mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} script: - dotnet tool install -g minver-cli - export VERSION=$(minver-cli .) - echo "Version: $VERSION" - dotnet pack -c Release -o ./artifacts -p:PackageVersion=$VERSION artifacts: paths: - artifacts/ release: stage: release image: mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} script: - export VERSION=$(minver-cli .) - export NUGET_KEY=$NUGET_API_KEY - dotnet nuget push artifacts/*.nupkg -k $NUGET_KEY -s https://api.nuget.org/v3/index.json only: - tags ``` -------------------------------- ### Environment Variables for MinVer CLI Source: https://github.com/adamralph/minver/blob/main/_autodocs/overview.md Illustrates how to configure minver-cli behavior using environment variables. These settings override defaults and can be combined with command-line arguments. ```bash export MinVerAutoIncrement=minor export MinVerBuildMetadata=ci.123 export MinVerDefaultPreReleaseIdentifiers=rc.0 export MinVerIgnoreHeight=false export MinVerMinimumMajorMinor=2.0 export MinVerTagPrefix=v export MinVerVerbosity=detailed minver-cli . ``` -------------------------------- ### Create Default Version Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/version.md Creates a default version (0.0.0) with specified pre-release identifiers. Use this to initialize a version object with custom pre-release tags. ```csharp public Version(IReadOnlyCollection defaultPreReleaseIdentifiers) ``` ```csharp var version = new Version(new[] { "alpha", "0" }); Console.WriteLine(version); // "0.0.0-alpha.0" ``` -------------------------------- ### MinVer CLI with Custom Pre-Release Identifiers Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Use custom pre-release identifiers like 'rc.0' instead of the default 'alpha.0' for untagged versions. ```bash $ minver-cli . --default-pre-release-identifiers rc.0 1.2.3-rc.0.4 ``` -------------------------------- ### Configure MinVer Tag Prefix in Project File Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md For large repositories, use a tag prefix to improve performance by filtering out non-version tags. This reduces the number of candidates MinVer needs to evaluate. ```xml v ``` -------------------------------- ### GetVersion with Custom Identifiers Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/pre-release-identifiers.md Illustrates how to override the default pre-release identifiers by providing a custom array of strings to the `GetVersion` method. This allows for flexible version naming, such as using 'beta.1' instead of 'alpha.0'. ```csharp // Use custom identifiers instead of alpha.0 var customVersion = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: new[] { "beta", "1" }, // Custom identifiers ignoreHeight: false, log: new ConsoleLogger()); // Result (e.g., if no tags exist): "0.0.0-beta.1.{height}" ``` -------------------------------- ### Calculate Version with MinVer CLI Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Calculate the project's version using the minver-cli tool. ```bash minver-cli . # Output: 1.0.0 ``` -------------------------------- ### Create Version Tag for MinVer CLI Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Create a Git tag for your project's version before calculating the version with MinVer CLI. ```bash git tag 1.0.0 ``` -------------------------------- ### Configure MinVer in .NET Project Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Optionally, add configuration properties to your project file to customize MinVer's behavior, such as auto-increment, tag prefix, and minimum major.minor version. ```xml minor v 1.0 ``` -------------------------------- ### Ensure SDK-Style Project for MinVer Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md MinVer requires projects to be SDK-style. Ensure your project file includes the 'Sdk="Microsoft.NET.Sdk"' attribute to resolve MINVER0001 errors. ```xml ``` -------------------------------- ### Basic minver-cli Syntax Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md The basic syntax for the minver-cli command, specifying an optional working directory and options. ```bash minver-cli [workingDirectory] [options] ``` -------------------------------- ### Create Git Tag for Release Source: https://github.com/adamralph/minver/blob/main/README.md Use this command to create a Git tag for a release. Ensure the tag name is a valid SemVer 2.x version. Push the tags to your remote repository. ```shell git tag 1.2.3 git push --tags ``` -------------------------------- ### Non-SDK-style Project Configuration Source: https://github.com/adamralph/minver/blob/main/_autodocs/errors.md This configuration triggers MINVER0001 because it lacks the 'Microsoft.NET.Sdk' Sdk attribute. Ensure your project is SDK-style for MinVer to function correctly. ```xml ``` -------------------------------- ### CLI Auto-Increment Configuration Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/versionpart.md Shows how to configure auto-increment behavior using the `minver-cli` tool with the `--auto-increment` or `-a` option, and also via the `MinVerAutoIncrement` environment variable. ```bash # Increment patch (default) minver-cli . --auto-increment patch # Increment minor minver-cli . --auto-increment minor # Increment major minver-cli . --auto-increment major # Also available as environment variable export MinVerAutoIncrement=minor minver-cli . ``` -------------------------------- ### Version.AddBuildMetadata Method Source: https://github.com/adamralph/minver/blob/main/_autodocs/summary.md Adds build metadata to the current Version object, returning a new Version instance. ```csharp AddBuildMetadata(string) → Version ``` -------------------------------- ### Deprecated Default Pre-Release Phase Configuration Source: https://github.com/adamralph/minver/blob/main/_autodocs/configuration.md Shows the deprecated method for setting the default pre-release phase using `--default-pre-release-phase`. This method is no longer recommended. ```bash # Old way (deprecated) minver-cli . --default-pre-release-phase alpha ``` -------------------------------- ### Verify MinVer Version Properties Source: https://github.com/adamralph/minver/blob/main/_autodocs/integration-guide.md Check that the MinVer version properties are set after building the project. ```bash dotnet build --getProperty:MinVerVersion dotnet build --getProperty:InformationalVersion ``` -------------------------------- ### Enforcing Minimum Version with MajorMinor Source: https://github.com/adamralph/minver/blob/main/_autodocs/api-reference/majorminor.md Demonstrates how MajorMinor is used to enforce a minimum version floor during version calculation. Versions below the constraint are automatically bumped. ```csharp // With minimum major.minor of 2.0 var minConstraint = new MajorMinor(2, 0); // A calculated version of 1.5.0 would be bumped to 2.0.0 // A calculated version of 2.1.3 would remain unchanged ``` -------------------------------- ### Enable Detailed Logging in .NET Build Source: https://github.com/adamralph/minver/blob/main/_autodocs/msbuild-integration.md Use the /verbosity:detailed flag when running 'dotnet build' to see more detailed output from MSBuild, which can include MinVer's diagnostic messages. ```bash dotnet build /verbosity:detailed ``` -------------------------------- ### Set Default Pre-Release Identifiers Source: https://github.com/adamralph/minver/blob/main/README.md Configure MinVer to use custom default pre-release identifiers, such as 'preview.0', instead of the default 'alpha.0'. This affects the format of post-RTM versions. ```xml preview.0 ``` -------------------------------- ### Handling NoGitException in Versioner Usage Source: https://github.com/adamralph/minver/blob/main/_autodocs/types.md Demonstrates how to use the Versioner.GetVersion method and catch a NoGitException if Git command execution fails. This is useful when the Git executable is not found or returns a non-zero exit code. ```csharp try { var version = await Versioner.GetVersion( workDir: ".", tagPrefix: "", minMajorMinor: MajorMinor.Default, buildMeta: "", autoIncrement: VersionPart.Patch, defaultPreReleaseIdentifiers: PreReleaseIdentifiers.Default, ignoreHeight: false, log: new ConsoleLogger()); } catch (NoGitException ex) { Console.WriteLine($"Git error: {ex.Message}"); } ``` -------------------------------- ### Command-line Override Environment Variable Source: https://github.com/adamralph/minver/blob/main/_autodocs/cli-reference.md Demonstrates how command-line arguments take precedence over environment variables for MinVer configuration. ```bash export MinVerTagPrefix=v # Set in environment minver-cli . --tag-prefix release- # Command-line overrides # Uses "release-", not "v" ```