Exemplo n.º 1
0
        internal override void SetVersionInfo()
        {
            string tfsAssemblyVersion;

            // TFS 2010 is default for backward compatibility
            switch (TfsVersion)
            {
                case "2012":
                    tfsAssemblyVersion = "11.0.0.0";
                    break;
                default:
                    tfsAssemblyVersion = "10.0.0.0";
                    break;
            }

            _clientAssembly = Assembly.Load(
                String.Format("Microsoft.TeamFoundation.Client, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", tfsAssemblyVersion)
                );
            _versionAssembly = Assembly.Load(
                String.Format("Microsoft.TeamFoundation.VersionControl.Client, Version={0}, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", tfsAssemblyVersion)
                );

            try
            {
                VersionControlServer versionControlServer = new VersionControlServer(
                    _clientAssembly,
                    _versionAssembly,
                    new Workstation(_versionAssembly).GetLocalWorkspaceInfo(WorkingDirectory).ServerUri.ToString(),
                    CredentialCache.DefaultNetworkCredentials
                    );

                // 1234
                Changeset = GetChangeset(versionControlServer, WorkingDirectory).ToString();
                // 1234
                ChangesetShort = Changeset;
                // true/false
                DirtyBuild = GetDirtyBuild(versionControlServer);
            }
            catch (TfsException ex)
            {
                // TeamCity build server check outs are not associated with a local TFS workspace, so we will get the
                // error 'The local path is not associated with a TFS Workspace'. We want to swallow this exception
                // here so the $CHANGESET$ token will be still initialized with it default value '0'.
                Log.LogWarningFromException(ex);
            }
        }
Exemplo n.º 2
0
        private static int GetChangeset(VersionControlServer versionControlServer, string workingDirectory)
        {
            int changesetId = 0;

            WorkspaceVersionSpec workspaceVersionSpec = new WorkspaceVersionSpec(
                _versionAssembly,
                versionControlServer.GetWorkspace(workingDirectory)
                );

            IEnumerable history = versionControlServer.QueryHistory(
                workingDirectory,
                new VersionSpec(_versionAssembly).Latest,
                new RecursionType(_versionAssembly).Full,
                workspaceVersionSpec
                );

            IEnumerator historyEnumerator = history.GetEnumerator();
            Changeset changeset = new Changeset(_versionAssembly);

            if (historyEnumerator.MoveNext())
                changeset = new Changeset(_versionAssembly, historyEnumerator.Current);

            if (changeset.Instance != null)
                changesetId = changeset.ChangesetId;

            return changesetId;
        }
Exemplo n.º 3
0
        private static bool GetDirtyBuild(VersionControlServer versionControlServer)
        {
            dynamic pendingSets = versionControlServer.GetPendingSets(new RecursionType(_versionAssembly).Full);

            foreach (var pendingSet in pendingSets)
            {
                // compare pending sets with local machine name
                if (String.Equals(pendingSet.Computer, Environment.MachineName, StringComparison.InvariantCultureIgnoreCase))
                    return true;
            }

            return false;
        }