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="<script type='text/javascript' src='/scripts/combined-minified.js' />"
/>
开发者_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="<script type='text/javascript' src='/scripts/combined-minified.js?$(Year)$(Month)$(Day)' />"
/>
</Target>
精彩评论