MSBuild: get previous version from msbuild script - tfs

Is there a posible to get previous version of code in TFS Build script?
I need to get curren version of config file and version from previous check-in, compare them, check if some files in other folders have the same changes and save the results to log.

We have a similar situation, where we need to get data from a file before getting the latest version. I don't know how much of this is applicable to you, but here's how we do it:
Since we're using CruiseControl.Net for build management, we turn off the autogetsource control in our configurations.
We have built a MSBuild Custom Task (if it's a fairly simple task, you can do it in-line) that retrieves the information we require prior to Get Latest.
"Manually" perform the tf get operation (as an MSBuild task)
Re-run our custom task to retrieve the new information, and act upon differences (for example, use as condition for later tasks)
Both in our case and yours I guess that a method for retrieving/comparing with the "previous" version of an item would have been preferred, but I was stumped there; I couldn't find any relatively easy way to retrieve the previous change set for an item. If anyone has any good ideas there, I'd like to hear these as well :).

Related

Can Jenkins jobs be configured to ignore certain check ins?

I am not using ANT at all so the proposed duplicate does answer this question about Jenkins.
I am working on a build script that will increment the version number of the program. To do this the version file will be checked out, next version number computed and written back, and then checked in.
It occurs to me that this will trigger yet another build in an endless cycle. When we used TFS builds we could put a string in the check in comment like ***NOCI*** or something and that check in would be ignored and not trigger a new build.
Is there any such option for Jenkins or a technique I can apply myself to solve this?
I am using the TFS plugin to access my SCM.
The Subversion SCM plugin allows you to specify paths that will be excluded when polling for new versions. Git SCM also can be configured to exclude some regions.
By excludng the file that contains the version number you will be able to avoid the vicious circle that you observed.
Since you cannot cloak or .tfignore your versioning file...you can use the NOCIOption property, and pass in the flag for it, in your comments.
You would setup the NOCIOption property of the SyncWorkspace workflow activity in TFS, and during your version change, pass "****NO_CI***" flag in the comments of the checkin. This is kind of hackish and could be avoided if you used GlobalAssemblyInfo.cs versioning, linked throughout your project instead.
I suggest not using your "versioning" file, as it's fundamentally wrong for the reason of cyclic checkins. I would suggest using the GlobalAssemblyInfo.cs linked throughout your .NET solution and stamping that prior to calling MSBuild. It works like a champ for setting and linking versioning throughout your .NET projects in your solution. You implement Global Assembly Info in your solution as described in this answer here.
You can understand more of it here, at "What are the best practices for using assembly attributes". You could simply stamp this file (via Powershell or whatever) and call MSBuild and your version will be present in all .DLLs.

TFS tool to show file changes when getting latest?

I know I can look at the "Source Control - Team Foundation" output in the Output window but it's hard to tell where the results from the current request begin and the last request ended sometimes, and any files that I want to compare that are in the list I have to go look up.
In the past when I used subversion, I had a tool (I think tortoise) that did an awesome job showing me all the files that were changed and I could click directly on them to compare with latest version. I would often use this to do quick code reviews, and it made it much easier to make sure I wasn't about to get an updated project file that had been improperly merged.
Are there any extensions/plugins or anything that can help with this for TFS when getting latest?
Unfortunately there isn't such a tool can exactly achieve that, there is a user voice submitted here, and it's ARCHIVED.
Based on my experience, the best thing to do is a folder comparison before you get the latest version. In Source Control Explorer, you can compare the differences between two server folders, two local folders, or a server folder and a local folder. Right click on the target folder and select Compare. Read more here.
To see the changes block you can introduce the third compare tools. (e.g BeyondCompare, ExamDiff, Code Compare etc, you can reference my answer in another thread : Visual Studio TFVC Merge Lines Misaligned). In short you can get the change list from Output window, then compare each file accordingly.
Besides, you can also try using the Tf Command Line Utility and the Visual Studio extension Diff All Files for VS2013. Reference this thread for details : TFS Shortcut to do a diff on all modified files with latest version

Pull version label from TFS in TeamCity

I need to pull from a specific label in TFS and then build it in TeamCity. Is there any way to do this? I've done it before in SVN with custom steps, I was trying to avoid this. I assume a custom step like the below would work, but wanted to avoid it if possible.
Any ideas? Maybe a way through the fetch URL or appended to the collection URL that I don't know about.
tf get * /r /version:Lyourlabelname
See https://youtrack.jetbrains.com/issue/TW-7370
You can run a build on a specified change[set] manually using Run
Custom Build dialog.
Edit:
Another way is to run tf.exe using the Get command.
See https://msdn.microsoft.com/en-us/library/fx7sdeyf.aspx
Synchronize a workspace to match a labeled version of the team’s codebase
c:\code\SiteApp\Main>tf get /v:LLastKnownGood
Synchronizes the workspace to match the items in the codebase that are labeled LastKnownGood
Edit 2
Also see https://teamcity-support.jetbrains.com/hc/en-us/community/posts/207091635-Checkout-TFS-Label
TeamCity does not support getting labeled sources at this time. The feature request is addressed by TW-5061, please vote for it.

Send notification to be received on TFS Get Latest Version

We are using TFS on Visual Studio 2013. When our developers Get Latest Version (GLV) and there is a new db script file received, it is stored under a specific folder, to be run using our custom update app.
What I want is that upon doing a GLV, they get a notification (in Visual Studio) that there are new scripts to run to update the db (generically speaking, that a new file has been added under a certain path).
Is there a way to achieve this with TFS?
It will not give you exactly what you want, but you can use built in TFS alerts to notify you or the team when a file is checkedin under a folder with a specific name/specified path/file extension.
You could write a visual studio extension, to be triggered on Get Latest, which would check a certain path within source control, you would have to roll this to all of your developers and would either have to store the lookup paths centrally or redeploy the app if the look up paths changed.
Alternatively you could add a bat / powershell script to your source control. within this script you could do the get latest and also run any scripts that you would like to run. you would then get the developers to get the latest against this script and then run it, which would get the rest of the files and would also run the db scripts.
If I understand correctly, you want your users to be running their locally built solutions against the latest database version to keep everyone in sync. Why not just use the usual workflow to procure 'notifications' in the form of build output?
I've dealt with this in the past, and the best solution I've come up with is to write a custom MSBuild target for 'BeforeBuild' into each of the projects that rely on the database being updated. The MSBuild target checks the version of the database installed (You would have to come up with a means for doing so, it can be tricky!).
If the currently deployed database does not match the version in the scripts you have just synced to, a build event could be raised. When the versions match the target would output a success message (or maybe nothing at all), and if the versions do not match the target would issue a build Warning or build Error depending on the severity of change observed (it might depend for you insofar as Major/Minor version variance is considered).

How to use TFS Build Process: LabelSources?

I'm attempting to modify my build process file for TFS 2010. I have a flag that is set when queuing the build, and when said flag is set, I want to create a Label, and add all the source files in the compiled project to that label.
On sequential builds, with the flag set, I than want to replace older source files in said label with anything new in the changeset being compiled.
I've been attempting to do this with LabelSources with no luck, and there is but vary poor documentation on either LabelSources or LabelWorkspace (whats the difference?).
Here's what I currently have:
<mtbwa:LabelSources
Child="[LabelChildOption.Replace]"
Comment="Published to Container"
DisplayName="Create Container Label"
sap2010:WorkflowViewState.IdRef="LabelSources_1"
Items="[{"$/Foo/LabelTest/Sandbox/"}]"
Name="[String.Format("{0}-{1}", LabelName, Version_Container)]"
Recursion="[RecursionType.Full]"
Scope="$/Foo"
mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
Version="T" />
It definitely hits the action, but no labels can be found after the fact.
Any help would be much appreciated. and Any tangible documentation, other than Class Documentation with sparse definitions would also be greatly appreciated
Edit 1: Tried to clear up my goal.
What you are trying to do is built into the existing template. There should be an option in the process definition that refers to Clean Sources which will be set to True.
This option controls wither the build sources get cleaned, deleted and start afresh. Or if a differential is done.
If you have a lot of source code you can set clean sources to false and save a bunch of time getting the code.
You can also speed the build by placing a TFS Proxy on the build box which will cache the files and make a clean build quicker.
In my experience, Most of the built-in activities are poorly-documented for a reason - their only well-tested use case is their use inside TFS' built-in templates (DefaultTemplate.11.0.xaml, etc.). I'm afraid you're going to have to write some custom code, in the form of a custom activity, powershell script or something, to achieve other goals.
That said, I don't really understand the process you're trying to set up. Do you just want to have a label set as your latest-successfully-built sources? Why not use the one created automatically by the build itself?

Resources