public static bool TryGetVersion(string directory, out SemanticVersion versionAndBranch)
        {
            var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory);

            if (string.IsNullOrEmpty(gitDirectory))
            {
                var message =
                    "No .git directory found in provided solution path. This means the assembly may not be versioned correctly. " +
                    "To fix this warning either clone the repository using git or remove the `GitVersion.Fody` nuget package. " +
                    "To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`." +
                    "If it is detected that this build is occurring on a CI server an error may be thrown.";
                Logger.WriteWarning(message);
                versionAndBranch = null;
                return(false);
            }

            var arguments = new Arguments();

            foreach (var buildServer in BuildServerList.GetApplicableBuildServers(arguments))
            {
                Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name));
                buildServer.PerformPreProcessingSteps(gitDirectory);
            }
            versionAndBranch = VersionCache.GetVersion(gitDirectory);
            return(true);
        }
        private string GetDllVersion(FileInfo asm)
        {
            if (VersionCache.ContainsKey(asm.FullName))
            {
                return(VersionCache[asm.FullName]);
            }

            var version = FileVersionInfo.GetVersionInfo(asm.FullName);

            VersionCache.Add(asm.FullName, version.FileVersion);
            return(version.FileVersion);
        }
        public override bool Execute()
        {
            var gitFolder = GitDirFinder.TreeWalkForGitDir(ProjectFolder);

            if (string.IsNullOrEmpty(gitFolder))
            {
                if (TeamCity.IsRunningInBuildAgent()) //fail the build if we're on a TC build agent
                {
                    this.LogError("Failed to find .git directory on agent. Please make sure agent checkout mode is enabled for you VCS roots - http://confluence.jetbrains.com/display/TCD8/VCS+Checkout+Mode");
                    return(false);
                }

                var message = string.Format("No .git directory found in solution path '{0}'. This means the assembly may not be versioned correctly. To fix this warning either clone the repository using git or remove the `GitFlowVersion.Fody` nuget package. To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`.", ProjectFolder);
                this.LogWarning(message);

                return(true);
            }

            var versionAndBranch = VersionCache.GetVersion(gitFolder);

            WriteTeamCityParameters(versionAndBranch);
            var semanticVersion = versionAndBranch.Version;

            Version      = string.Format("{0}.{1}.{2}", semanticVersion.Major, semanticVersion.Minor, semanticVersion.Patch);
            FileVersion  = string.Format("{0}.{1}.{2}", semanticVersion.Major, semanticVersion.Minor, semanticVersion.Patch);
            InfoVersion  = versionAndBranch.ToLongString();
            NugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);

            this.LogInfo(String.Format("Version number is {0} and InfoVersion is {1}", Version, InfoVersion));
            if (Files == null)
            {
                return(true);
            }
            var task = new UpdateAssemblyInfo(Files, Version, FileVersion);

            task.Execute();
            return(true);
        }
Esempio n. 4
0
 private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
 {
     await Task.Factory.StartNew(() => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None, TaskCreationOptions.None, ForegroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
 }
 private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
 {
     await ProjectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
         () => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
 }