.TT – add more informations(.NET version , build ) – part 6 of 7

As you can see from the previous chapter, we have added to the AssemblyDescription more informations – like .NET version, build configuration , and more

You can see those with an explorer add-on http://www.codeproject.com/Articles/118909/Windows-7-File-properties-Version-Tab-Shell-Extens

Video : http://youtu.be/A_qSdVV93qk

Demo project here : https://traceabilitydemo.codeplex.com/releases/view/132231

Source code here : https://traceabilitydemo.codeplex.com/SourceControl/changeset/view/110446

Traceability in .NET–.tt files–add changeset – part 5 of 7

We wish to add , from the .tt file , the id of the last TFS checkin. For this purpose we will connect to TFS and we will investigate in the current project the latest change.

We will use the facility of .tt file to connect to the host and ask for various features ( such as TFS )

The .tt file code is:

  

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="EnvDTE80" #>


<#@ assembly name="Microsoft.VisualStudio.TeamFoundation.VersionControl" #>
<#@ assembly name="Microsoft.TeamFoundation.Client"#>
<#@ assembly name="Microsoft.TeamFoundation.Common"#>
<#@ assembly name="Microsoft.TeamFoundation"#>
<#@ assembly name="Microsoft.TeamFoundation.WorkItemTracking.Client"#>
<#@ assembly name="Microsoft.TeamFoundation.VersionControl.Client"#>
<#@ assembly name="Microsoft.TeamFoundation.ProjectManagement"#>


<#@ import namespace="Microsoft.TeamFoundation.Client"#>
<#@ import namespace="Microsoft.TeamFoundation.VersionControl.Client"#>


<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="EnvDTE80" #>
<#@ output extension=".cs" #>
<#
DTE dte=null;
var serviceProvider = Host as IServiceProvider;
    if (serviceProvider != null) {
        dte = serviceProvider.GetService(typeof(DTE)) as DTE;
    }
	if (dte == null) {
        throw new Exception("generate build number can only execute through the Visual Studio IDE");
		}
ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
int netVersion=0;

var proj=projectItem.ContainingProject;
var configmgr = proj.ConfigurationManager;
var config = configmgr.ActiveConfiguration;
string regex=@"^.+?Version=v(?<version>\-?\d+\.\d+).*?$";
var options = RegexOptions.Multiline;
string input= proj.Properties.Item("TargetFrameworkMoniker").Value.ToString();
	
MatchCollection matches = Regex.Matches(input,regex,options);
foreach (Match match in matches)
{
		
    netVersion = (int)(double.Parse(match.Groups["version"].Value)*100);
		
}


string filePath = proj.FullName;
string dirPath = System.IO.Path.GetDirectoryName(filePath);
var wsInfo = Microsoft.TeamFoundation.VersionControl.Client.Workstation.Current.GetLocalWorkspaceInfo(filePath );
 
 // Get the TeamProjectCollection and VersionControl server associated with the
 // WorkspaceInfo
 var tpc = new TfsTeamProjectCollection(wsInfo.ServerUri);
 var vcServer = tpc.GetService<VersionControlServer>();
 
 // Now get the actual Workspace OM object
 var ws = vcServer.GetWorkspace(wsInfo);
 
 // We are interested in the current version of the workspace
 var versionSpec = VersionSpec.Latest;
 
 var historyParams = new QueryHistoryParameters(dirPath, RecursionType.Full);
 historyParams.ItemVersion = versionSpec;
 historyParams.VersionEnd = versionSpec;
 historyParams.MaxResults = 1;
 
 var changeset = vcServer.QueryHistory(historyParams).FirstOrDefault();


 var dt = DateTime.Now;
var userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
userName = userName.Split('\\').Last();

 #>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BuildTraceabilityDemo")]
//http://www.codeproject.com/Articles/118909/Windows-7-File-properties-Version-Tab-Shell-Extens
[assembly: AssemblyDescription("BuildDate,<#=dt.ToString("yyyyMMdd_HHmmss")#>\r\n<#=proj.Properties.Item("TargetFrameworkMoniker").Value.ToString()#>\r\nBuild by,<#=userName#>\r\nConfig,<#=config.ConfigurationName#>,\r\nChangeset,<#=changeset.ChangesetId#>")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BuildTraceabilityDemo")]
[assembly: AssemblyCopyright("Copyright ©  <#= dt.Year#>")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("75ff7863-cb83-4d9b-80de-4a0de2781918")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.<#=dt.Year#>.<#=dt.Month#>.<#=dt.Day#>")]


   

Video : http://youtu.be/A_qSdVV93qk

Demo project here : https://traceabilitydemo.codeplex.com/releases/view/132231

Source code here : https://traceabilitydemo.codeplex.com/SourceControl/changeset/view/110446

Traceability in .NET–.tt files–add build date– part 4 of 7

Firstly we propose that build can automatically put the data in AssemblyVersion. For this you will need somehow to generate the current date.

We can do this in several ways – for example, a post build event. We will use a .tt file that will automatically generate this date. We will use for other things – for example, last checkin of TFS.

Running .tt files can be done either via command Build => Transform all T4 templates or in a before build event solution here . The solution is taken from http://stackoverflow.com/questions/1646580/get-visual-studio-to-run-a-t4-template-on-every-build – run in pre-build event the .tt file.

You can download demo project from here: https://traceabilitydemo.codeplex.com/releases/view/132229

Source code: https://traceabilitydemo.codeplex.com/SourceControl/changeset/view/110438

Video : https://www.youtube.com/watch?v=lZJ1NCIDejU

Next time we will add the TFS checkin id

Tracebility in .NET -source control – part 3 of 7

Adding version with Source Control

This depends on what source control do you use . We will not discuss this in details – it is enough to searchAssemblyVersion. For TFS or SVN you can use https://github.com/loresoft/msbuildtasks : TfsVersion si SvnVersion

You can use command line too : http://www.woodwardweb.com/vsts/determining_the.html

Full tutorial with powershell you can find at http://blogs.msdn.com/b/visualstudioalm/archive/2013/07/24/basic-tfbuild-scripts.aspx http://msdn.microsoft.com/en-us/library/dn376353.aspx#env_vars http://curah.microsoft.com/8047/run-scripts-in-your-team-foundation-build-process

I have made a video at : https://www.youtube.com/watch?v=teiSgEYZXog

I can send source code –it is on visualstudio.com

Traceability in .NET–1.0.*–part 2 of 7

Traceability in NET

Each project in Visual Studio contains a file named AssemblyInfo.cs that contains summary information about the component. We will discuss these lines:

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

As seen the traceability already exists in .NET .The difference between AssemblyVersion and AssemblyFileVersion is detailed here: http://support.microsoft.com/kb/556041

What we want to achieve is that after a change of the source code and recompile, the AssemblyVersion (or AssemblyFileVersion) to show us how we can "recover" source code

It is obvious that if we change the source code will remain all AssemblyVersion 1.0.0.0.

So if we want to have control over versions then we can modify the version manually .

In the following tutorials we will show various ways to automatically change the version, as well as to add other details in AssemblyDescription.

Official Way (1.0. *)

The easiest way is to put

[assembly: AssemblyVersion("1.0.*")]

In AssemblyInfo.cs and comment

//[assembly: AssemblyFileVersion("1.0.0.0")]

In this way, the version will increment every time.

The code on AssemblyInfo.cs will look as following:

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
// [assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]


Video: https://www.youtube.com/watch?v=jq6Uu64md1s

You can download the demo project here: http://traceabilitydemo.codeplex.com/releases/view/130512

The source code you can download from here:
https://traceabilitydemo.codeplex.com/SourceControl/changeset/view/110330

What is disturbing is not incremented so that we can see, for example, build on site.

Next time we will make same increment from Source control( TFS)

Traceability in .NET – 1 of 7

What is traceability?

From Wikipedia, http://en.wikipedia.org/wiki/Traceability :
Traceability is the ability to verify the history, location, or application of an item by means of documented recorded identification.
We define traceability in software tracking capabilities and implementation of software components to know exactly:
1 The date the component was done (so that we can reproduce the source code)
2 Details of the production (version frameworks, other components, compilation debug / release, other data) so as to have the ability to distinguish between different versions
Assume that we have already answered yes to step 1 (Do you use source control?) from http://www.joelonsoftware.com/articles/fog0000000043.html
Also (although we do not use;)) is good to study and Semantic Version http://semver.org/

Why we need traceability in software

Suppose we have a source code that you distribute one to several customers. Suppose we modify the code for version two. Some of his old clients make software upgrades – others not. If a customer reports a bug, how do we know which version of the source code had problems?

Friday links 84

  1. GCompris Free Educational Software
  2. 40 Maps That Will Help You Make Sense of the World «TwistedSifter
  3. 8 Mistakes Our Brains Make Every Day And How To Prevent Them – Business Insider
  4. Presentation Skills Considered Harmful — Serious Pony
  5. The New Science of Who Sits Where at Work – WSJ.com
  6. Four Dangerous Navigation Approaches that Can Increase Cognitive Strain
  7. A New Way To Measure Happiness Finds The True Happiest Countries In The World | Co.Exist | ideas + impact
  8. GoodUI
  9. Web Developer Checklist – ASP.NET Performance
  10. 33 Meticulous Cleaning Tricks For The OCD Person Inside You
  11. Cool life hacks : theCHIVE
  12. Morning Awesomeness : theCHIVE
  13. 40 Must-See Historical Photos | DeMilked
  14. Asda supermarket launches 3D printing service
  15. Introducing TogetherJS ✩ Mozilla Hacks – the Web developer blog
  16. The Positive Power of Negative Thinking | LinkedIn
  17. 30 Creative Facebook Timeline Cover Photos | DeMilked
  18. The No Whining Rule for Managers – Ron Ashkenas – Harvard Business Review
  19. Hovering | Fabric.js Demos
  20. free-programming-books/free-programming-books.md at master · vhf/free-programming-books
  21. C# versus C++ performance – Stack Overflow
  22. 101 Important Questions To Ask Yourself | Personal Excellence
  23. Keith Barry executa magia mintii | Video on TED.com
  24. What are the most spectacular NASA photos ever taken? – Quora
  25. Marius Ursache’s answer to Productivity: What are the best day to day time saving hacks? – Quora
  26. Confirmation Bias « You Are Not So Smart
  27. ASP.NET Web API 2 is out! Overview of features – StrathWeb
  28. Troy Hunt: Essential reading for Visual Studio 2013, MVC 5 and Web API 2
  29. Creating Facebook Template in Visual Studio 2013 Preview
  30. How Microsoft helped this bar figure out that vodka was costing it a fortune | CITEworld
  31. GitLab.com | Features
  32. 6 dirty secrets of the IT industry
  33. Two Dozen Insanely Essential Programmer Utilities* | Jesse Liberty
  34. AutoHotkey
  35. Bossie Awards 2013: The best open source application development tools – InfoWorld
  36. How a Radical New Teaching Method Could Unleash a Generation of Geniuses | Wired Business | Wired.com
  37. Colophon for GOV.UK at launch | Government Digital Service

Friday links 82

  1. Core Coding Standard | Insomniac Games
  2. World’s Biggest Data Breaches & Hacks | Information Is Beautiful
  3. Caught In A Stress Spiral? Innovate Your Day With 8 Minutes Of "Ready, Set, Pause" | Fast Company | Business + Innovation
  4. 10 Ways Our Minds Warp Time — PsyBlog
  5. 10 Brilliant Social Psychology Studies — PsyBlog
  6. HistomapFinal.jpg.CROP.article920-large.jpg (920×4192)
  7. Things You Should Never Do, Part I – Joel on Software
  8. Pages – Surveys
  9. Translation table explaining the truth behind British politeness becomes internet hit – Telegraph
  10. JExcelApi
  11. Licensing iText | iText Software Info
  12. Attribute Routing in Web API v2
  13. ASP.NET MVC 5 Authentication Filters — Visual Studio Magazine
  14. How to Turn Your Pile of Code into an Open Source Project
  15. 25 Steps To Edit The Unmerciful Suck Out Of Your Story « terribleminds: chuck wendig
  16. WATCH NOW: What Gamers Can Teach Us | Jane McGonigal
  17. C# Performance Benchmark Mistakes, Part One – Tech.Pro
  18. C# Performance Benchmark Mistakes, Part Two – Tech.Pro
  19. 10 YouTube Videos Every Entrepreneur Should Watch | Inc.com
  20. Debugging Optimized Code–New in Visual Studio 2012 | Random ASCII
  21. Portable House ÁPH80 by Ábaton Arquitectura | URDesign Magazine
  22. Wall Street needs an MFA – Salon.com
  23. The Habits of the World’s Smartest People (Infographic) | Entrepreneur.com
  24. 5 Crazy New Man-Made Materials That Will Shape the Future
  25. 7 cutting-edge programming experiments worth trying
  26. Can Building Great Products Help You Build Great Teams? – Deep Nishar – Harvard Business Review
  27. Timed array processing in JavaScript | NCZOnline
  28. Understanding ECMAScript 6 arrow functions | NCZOnline

Friday links 81

  1. Weird & Exotic Places on Earth
  2. three.js – JavaScript 3D library
  3. Margaret Heffernan: Dare to disagree | Video on TED.com
  4. Playing video games can boost brain power
  5. Google Chromecast Review – The race is on to wirelessly throw video to your TV – Scott Hanselman
  6. Entity Framework Code-First Performance Issue with String Queries | Brian Sullivan
  7. The Psychology of Video Games | It’s Not So Bad: Cognitive Dissonance and Cheap Games
  8. Math Experts Split the Check | Math with Bad Drawings
  9. How to Work with Designers — The Year of the Looking Glass — Medium
  10. How to Work with PMs — The Year of the Looking Glass — Medium
  11. Implement Kanban: Implement Virtuous Cycle of Ongoing Improvement » MPUG
  12. Getting a distinct list of changed files from TFS using PowerShell | HackedBrain
  13. Functionally Similar – Comparing Underscore.js to LINQ
  14. Amy Cuddy: Your body language shapes who you are | Video on TED.com
  15. 4 Things I Wish I Would Have Known When I Started My Software Development Career | Javalobby
  16. Weekend Scripter: Use PowerShell to Explore an RSS Feed from a Blog – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs
  17. Dark Patterns – User Interfaces Designed to Trick People
  18. 10+ years of designing games in public | opensource.com
  19. Using T4 to Create an AppSettings Wrapper, Part 3 – P3.NET
  20. Windows 8 — Disappointing Usability for Both Novice and Power Users
  21. code journey: Using bind prefix in ASP.NET MVC with overlays
  22. Prefixing Input Elements Of Partial Views With ASP.NET MVC – That Extra Mile
  23. hall of api shame: boolean trap

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.