tags:

views:

85

answers:

3

In Java, we can declare a static string with the value of $HeadURL:$ that is updated by every Subversion commit. This can then be extracted from a produced class file to find the source file that corresponds to the class file(and revision information).

In C we can declare a static char[] to do the same thing.

What is the recommended way to accomplish this goal in C#?

Basically, I'm looking for best practice to use $HeadURL:$ information, that has been updated by Subversion, to match production code with source code.

I'm familiar with Assembly version and the like, but that does not provide us the granularity we are looking for.

A: 

Some thoughts:

Gets a little messy when a class is declared in more than one source file e.g. partial class? :)

Benefit of the custom attributes is non-intrusion into the regular programming model, intellisense etc. while still being programmatically discoverable through type reflection in Type.GetCustomAttributes. (http://msdn.microsoft.com/en-us/library/kff8s254.aspx)

stephbu
Partial classes are my largest concern. Any ideas on how to handle that?
Lucas B
No *great* ideas, beyond generating more complex code and logic. Are partial classes really a big problem?Almost all instances that I've seen them in are tool generated with a user contributed aspect. Having the attribute in the user edited side of the house would be correct behaviour.
stephbu
+1  A: 

With subversion you can use svn info to get the latest revision number, repository url, last changed date, etc of the current repository. You can then stamp that information into your assembly with whatever build tool you are using to create it.

The asminfo task in Nant for example creates an AssemblyInfo which you can stamp with arbitrary version info (the attribute elements).

serg10
+1  A: 

If I understand you correctly, you're trying to do this per source file, which is just making things hard for yourself :) If you tag before you build, then the revision number associated with the tag is an unambiguous reference to every source file used in the executable, and gives you precisely the granularity you're after.

You can include the revision number using SVN's Revision keyword instead of HeadURL. You need only include this revision number in one source file per EXE/DLL (usually in a string value passed to an appropriate version-related attribute in AssemblyInfo.cs), which is what @serg10 is referring to.

Doing this per-file in C# is (unnecessarily) painful because the language has no notion of "module"-level data. And adding an attribute to at least one type in every file is tedious, and prone to being forgotten or mistyped.

shambulator
Yeah agreed, attribution isn't any different than headers in the 1st place, both need either 1) diligent programmers, or 2) decent templates.
stephbu