开发者

Find revision information from Production code allowing link to Source code

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.


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.


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).


Some thoughts:

  • Could use a static member on your class just like C
  • Create a custom attribute to contain the data and attach it to the class declaration. Instructions and example here: http://msdn.microsoft.com/en-us/library/84c42s56.aspx

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜