msbuild脚本中的日期格式?

发布于 2024-08-18 09:50:14 字数 555 浏览 3 评论 0原文

在我的 msbuild 脚本中,我正在创建一个 zip 文件,其文件名中包含年/月/日,但月份和日期始终不带前导零。

有没有办法在我的 zip 文件名中添加前导零?

<Time>
  <Output TaskParameter="Year" PropertyName="Year" />
  <Output TaskParameter="Month" PropertyName="Month" />
  <Output TaskParameter="Day" PropertyName="Day" />
</Time>

<PropertyGroup>
  <ZipOutDir>C:\output</ZipOutDir>
  <ZipFileName>Application_$(Year)$(Month)$(Day).zip</ZipFileName>
</PropertyGroup>

结果是:“Application_2010122.zip”(一月份没有前导零,如您所见)

In my msbuild script I'm creating a zip file with year/month/day in the zip filename, but month and day are always written with no leading zero.

Is there a way to add leading zero to my zip filename?

<Time>
  <Output TaskParameter="Year" PropertyName="Year" />
  <Output TaskParameter="Month" PropertyName="Month" />
  <Output TaskParameter="Day" PropertyName="Day" />
</Time>

<PropertyGroup>
  <ZipOutDir>C:\output</ZipOutDir>
  <ZipFileName>Application_$(Year)$(Month)$(Day).zip</ZipFileName>
</PropertyGroup>

And the result is: 'Application_2010122.zip' (with no leading zero for january, as you can see)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

停顿的约定 2024-08-25 09:50:14

在 msbuild 4 中,您现在可以

$([Namespace.Type]::Method(..parameters…))
$([Namespace.Type]::Property)
$([Namespace.Type]::set_Property(value))

所以我

$([System.DateTime]::Now.ToString(`yyyy.MMdd`))

在格式周围使用这些刻度反引号不是 '

In msbuild 4 you can now

$([Namespace.Type]::Method(..parameters…))
$([Namespace.Type]::Property)
$([Namespace.Type]::set_Property(value))

so I am using

$([System.DateTime]::Now.ToString(`yyyy.MMdd`))

those ticks around the format are backticks not '

彼岸花ソ最美的依靠 2024-08-25 09:50:14

您可以使用 MSBuild 扩展包:

http://www.msbuildextensionpack.com/help/3.5.3.0/html/9c5401ed-6f55-089e-3918-2476c186ca66.htm

或者使用社区任务中的时间任务的格式参数[您可以使用似乎正在使用]

MSBuild MSBuildCommunityTasks 任务时间

You could use the MSBuild extension pack a la:

http://www.msbuildextensionpack.com/help/3.5.3.0/html/9c5401ed-6f55-089e-3918-2476c186ca66.htm

Or use the format param to the Time task from community tasks [which you appear to be using]

MSBuild MSBuildCommunityTasks Task Time

疯狂的代价 2024-08-25 09:50:14

这是因为 MSBuild 仅使用字符串进行操作。您必须修改现有任务,以便所有属性都返回 string 而不是 int(或它们返回的任何整数值),或者创建一个单独的任务将根据您的需要格式化年、月和日。

It's because MSBuild operates solely with strings. You'll have to either modify existing tasks so that all properties will return strings instead of ints (or whatever integer value they return), or create a separate task which will format year, month and day according to your needs.

乄_柒ぐ汐 2024-08-25 09:50:14

这是添加前导零的廉价而肮脏的方法

$([System.UInt16]::Parse($(Month)).ToString('00'))

Here's a cheap and dirty way to add a leading zero

$([System.UInt16]::Parse($(Month)).ToString('00'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文