开发者

How to output a timestamp in MSBuild [duplicate]

开发者 https://www.devze.com 2023-01-09 07:35 出处:网络
This question already has answers here: How to add a timestamp to TFSBuild.proj? (2 answers) Closed 8 years ago.
This question already has answers here: How to add a timestamp to TFSBuild.proj? (2 answers) Closed 8 years ago.

I am using MSBuild/yuicompressor to combine and minify JavaScript.

As part of this process, I want to modify my script references so they have a timestamp in the querystring. That way, a user always gets the non-cached version of the file when a new release is published. For example:

<script type="text/javascript" src="/scripts/combined-minified.js?20100727" />

I am using FileUpdate from MSBuildCommunityTasks to update the <script> reference, but it does not have a timestamp:

<FileUpdate
      Files="@(includeFile)"
      Regex="#scriptfiletoken#"
      ReplacementText="&lt;script type='text/javascript' src='/scripts/combined-minified.js' /&gt;"
      />

开发者_StackOverflowWhat is the best way to output this timestamp using MSBuild?


This method worked for me:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

<Target Name="MyTarget">
    <!-- Build timestamp. -->
    <Time>
      <Output TaskParameter="Month" PropertyName="Month" />
      <Output TaskParameter="Day" PropertyName="Day"  />
      <Output TaskParameter="Year" PropertyName="Year" />
    </Time>

    <!-- ....... -->    

    <!-- Add timestamp to includeFile -->
    <FileUpdate
      Files="@(includeFile)"
      Regex="#scriptfiletoken#"
      ReplacementText="&lt;script type='text/javascript' src='/scripts/combined-minified.js?$(Year)$(Month)$(Day)' /&gt;"
      />
</Target>
0

精彩评论

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