Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetBranchFromAssemblyInfo(bool isMaster = true)
- {
- var assembly = Assembly.GetExecutingAssembly();
- var location = assembly.Location;
- if (location == null)
- return string.Empty;
- var productVersion = FileVersionInfo.GetVersionInfo(location).ProductVersion;
- if (string.Equals(productVersion, _manualVersionString))
- try
- {
- var solutionPath = string.Empty;
- var path = AppDomain.CurrentDomain.BaseDirectory;
- for (var i = 0; i < 6; i++)
- {
- if (Directory.Exists(path + ".git"))
- {
- solutionPath = path;
- break;
- }
- path += @"..\";
- }
- using (var repository = new Repository(solutionPath))
- {
- var branch = repository.Head.ToString();
- return branch.Replace("refs/heads/", string.Empty);
- }
- }
- catch
- {
- return "default branch";
- }
- var datePattern = @"_[\d]{8}_[\d]{4}";
- var shortBranch = productVersion.Replace("refs/heads/", string.Empty);
- shortBranch = Regex.Replace(shortBranch, datePattern, string.Empty);
- return shortBranch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement