असेंबली में संशोधन जानकारी को स्वचालित रूप से अपडेट करने के लिए यहां और सी # उदाहरण है। यह विल डीन के जवाब पर आधारित है, जो बहुत विस्तृत नहीं है।
उदाहरण :
- Copy AssemblyInfo.cs to AssemblyInfoTemplate.cs in the project's
folder Properties.
- Change the Build Action to None for AssemblyInfoTemplate.cs.
Modify the line with the AssemblyFileVersion to:
[assembly: AssemblyFileVersion("1.0.0.$WCREV$")]
Consider adding:
[assembly: AssemblyInformationalVersion("Build date: $WCNOW=%Y-%m-%d %H:%M:%s$; Revision date: $WCDATE=%Y-%m-%d %H:%M:%s$; Revision(s) in working copy: $WCRANGE$$WCMODS?; WARNING working copy had uncommitted modifications:$.")]
,
which will give details about the revision status of the source the assembly was build from.
Add the following Pre-build event to the project file properties:
subwcrev "$(SolutionDir)." "$(ProjectDir)Properties\AssemblyInfoTemplate.cs" "$(ProjectDir)Properties\AssemblyInfo.cs" -f
Consider adding AssemblyInfo.cs to the svn ignore list. Substituted revision numbers and dates will modify the file, which results in insignificant changes and revisions and $WCMODS$ will evaluate to true. AssemblyInfo.cs must, of course, be included in the project.
विम कोएनेन द्वारा आपत्तियों के जवाब में, मैंने देखा कि, डेरिल द्वारा सुझाए गए सुझावों के विपरीत, असेंबलीफाइलवर्जन भी नहीं समर्थन संख्या 2 ^ 16 से ऊपर करता है। निर्माण पूरा हो जाएगा, लेकिन वास्तविक असेंबली में फ़ाइल संस्करण संपत्ति असेंबलीफाइलवर्सन मॉड्यूलो 65536 होगी। इस प्रकार, 1.0.0.65536 के साथ-साथ 1.0.0.131072 1.0.0.0, आदि उत्पन्न होगा। इस उदाहरण में, विधानसभा सूचनात्मक संपत्ति में हमेशा सही संशोधन संख्या होती है। यदि आप इसे एक महत्वपूर्ण मुद्दा मानते हैं तो आप चरण 3 छोड़ सकते हैं।
संपादित करें: थोड़ी देर के लिए इस समाधान का उपयोग करने के बाद कुछ अतिरिक्त जानकारी।
- It now use AssemblyInfo.cst rather than AssemblyInfoTemplate.cs, because it will automatically have Build Action option None, and it will not clutter you Error list, but you'll loose syntax highlighting.
I've added two tests to my AssemblyInfo.cst files:
#if(!DEBUG)
$WCMODS?#error Working copy has uncommitted modifications, please commit all modifications before creating a release build.:$
#endif
#if(!DEBUG)
$WCMIXED?#error Working copy has multiple revisions, please update to the latest revision before creating a release build.:$
#endif
Using this, you will normally have to perform a complete SVN Update, after a commit and before you can do a successful release build. Otherwise, $WCMIXED will be true. This seems to be caused by the fact that the committed files re at head revision after the commit, but other files not.
- I have had some doubts whether the first parameter to subwcrev, "$(SolutionDir)", which sets the scope for checking svn version info, does always work as desired. Maybe, it should be $(ProjectDir), if you are content if each individual assembly is in a consistent revision.
Addition
To answer the comment by @tommylux.
SubWcRev का उपयोग आपके प्रोजेक्ट में किसी भी फाइल के लिए किया जा सकता है। यदि आप किसी वेब पेज में संशोधन जानकारी प्रदर्शित करना चाहते हैं, तो आप इस VersionInfo टेम्पलेट का उपयोग कर सकते हैं:
public class VersionInfo
{
public const int RevisionNumber = $WCREV$;
public const string BuildDate = "$WCNOW=%Y-%m-%d %H:%M:%s$";
public const string RevisionDate = "$WCDATE=%Y-%m-%d %H:%M:%s$";
public const string RevisionsInWorkingCopy = "$WCRANGE$";
public const bool UncommitedModification = $WCMODS?true:false$;
}
AssemblyInfo.cst के लिए एक प्री-बिल्ड इवेंट जोड़ें और आपके पास सभी प्रासंगिक सबवर्सन जानकारी तक आसानी से पहुंच होगी।