I'm trying to save the compilation time of a project on a text file every time a project is compiled/built, so I've tried to put the following command in the project's options Post-Build Action:

echo %date% %time% > "$(PROJECTDIR)\$(PROJECTNAME).txt"

But Cmd-style %date% variables won't work. I've also tried the following:

  • MSBuild-style $(date)
  • MSBuild 4-style $([System.DateTime]::Now.ToString(yyyy.MMdd))
  • Calling cmd:

    cmd.exe /C echo %date% %time% > "$(PROJECTDIR)\$(PROJECTNAME).txt"
    

But none of those options work. I know there are Community Tasks that enable this sort of thing but I'm trying to avoid the need to install them in every developer's PC.

有帮助吗?

解决方案

You can pull the date/time from the project you just built and send it to a text file, with the date and time on a single line. Add this to the post-build commands:

for /f "tokens=1,2,3 delims= " %%i in ('dir "$(OUTPUTDIR)$(OUTPUTFILENAME)" ^| find "$(OUTPUTFILENAME)"') do echo %%i %%j %%k > "$(PROJECTDIR)$(PROJECTNAME).txt"

其他提示

Use the date and time commands to output the time and date. Pass the /t switch to tell these commands just to output the current value.

C:\>date /t
25/09/2013

C:\>time /t
15:06

So, to put these values into a file do this:

date /t > "$(PROJECTDIR)\$(PROJECTNAME).txt"
time /t >> "$(PROJECTDIR)\$(PROJECTNAME).txt"

Perhaps writing this information to a file isn't the best solution to your problem. The compiler will write the build date into the output file. TOndrej's answer to this question shows how to retrieve it:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top