Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>C# doesn't have the concept of macros; however, you can use other tools in your build script (csproj / NANT / etc) to manipulate the source before it compiles. I use this, for example, to set the revision number to the current SVN revision.</p> <p>A cheap option is a pre-build event (you can do this via the project properties dialog in VS): essentially a bat file that runs before build; you can then script whatever changes you need. A more sophisticated option is build tasks.</p> <p>For example, the utility library <a href="http://msbuildtasks.tigris.org/" rel="nofollow noreferrer">here</a> includes a <code>Time</code> task and a <code>FileUpdate</code> task; it should (in theory) be possible to chain the two together to emulate what you need.</p> <p>Personally, I'd use the <code>[AssemblyVersion]</code> details rather than the time - if you link this to your source-control system, this makes it very easy to find the offending version; so for my SVN version, I then use (in my build proj):</p> <pre><code>&lt;!-- See http://msbuildtasks.tigris.org --&gt; &lt;Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/&gt; ... &lt;SvnInfo LocalPath="."&gt; &lt;Output TaskParameter="Revision" PropertyName="BuildRev" /&gt; &lt;/SvnInfo&gt; ... &lt;FileUpdate Files="Path\To\My\AssemblyInfo.cs" Regex='(\[\s*assembly:\s*AssemblyVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])' ReplacementText='$1.$2.$(BuildRev)$5' /&gt; &lt;FileUpdate Files="Path\To\My\AssemblyInfo.cs" Regex='(\[\s*assembly:\s*AssemblyFileVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])' ReplacementText='$1.$2.$(BuildRev)$5' /&gt; </code></pre> <p>And now my assembly-version is correct, including the file-version that gets reported by the OS.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload