GitVersion.GitVersionFinder.FindVersion C# (CSharp) Method

FindVersion() public method

public FindVersion ( GitVersionContext context ) : SemanticVersion
context GitVersionContext
return SemanticVersion
        public SemanticVersion FindVersion(GitVersionContext context)
        {
            Logger.WriteInfo(string.Format(
                "Running against branch: {0} ({1})",
                context.CurrentBranch.FriendlyName,
                context.CurrentCommit == null ? "-" : context.CurrentCommit.Sha));
            EnsureMainTopologyConstraints(context);

            var filePath = Path.Combine(context.Repository.GetRepositoryDirectory(), "NextVersion.txt");
            if (File.Exists(filePath))
            {
                throw new WarningException("NextVersion.txt has been deprecated. See http://gitversion.readthedocs.org/en/latest/configuration/ for replacement");
            }

            return new NextVersionCalculator().FindVersion(context);
        }

Usage Example

Example #1
0
    public static Tuple<CachedVersion, GitVersionContext> GetVersion(string gitDirectory, Config configuration)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var versionFinder = new GitVersionFinder();
            var context = new GitVersionContext(repo, configuration);
            var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);

            Tuple<CachedVersion, GitVersionContext> result;
            if (versionCacheVersions.TryGetValue(key, out result))
            {
                if (result.Item1.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    result.Item1.SemanticVersion = versionFinder.FindVersion(context);
                }
                return result;
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return versionCacheVersions[key] = Tuple.Create(new CachedVersion
            {
                SemanticVersion = versionFinder.FindVersion(context),
                Timestamp = ticks
            }, context);
        }
    }
All Usage Examples Of GitVersion.GitVersionFinder::FindVersion