|
■No81282 (倍子 さん) に返信 > VB2010Expressだと、[ビルド イベント]や「ビルド前イベント」という項目が存在しないのですが。
Express なのであれば、ビルドイベントは使えないですね。 .vbproj ファイルを直接編集して、 <PropertyGroup><PreBuildEvent>ECHO %25DATE%25 %25TIME%25 > "$(SolutionDir)TextFile1.txt"</PreBuildEvent></PropertyGroup> を加えれば動作するかもしれませんが…。
> どうすればよいですか? No81280 の方法を試してみては如何でしょう。
'【VB2005 以降向け】 Imports System.Runtime.InteropServices Imports System.Reflection Imports System.IO Module Module1 Public Function GetBuildDateTime() As Nullable(Of Date) Dim filePath As String = Assembly.GetExecutingAssembly().Location Return GetBuildDateTime(filePath) End Function Public Function GetBuildDateTime(ByVal filePath As String) As Nullable(Of Date) Const MZ As Short = &H5A4DS Const PE As Integer = &H4550I Try Using r As New BinaryReader(File.OpenRead(filePath)) 'IMAGE_DOS_HEADER Dim dos = r.ReadBytes(64) If dos.Length < 64 Then Return Nothing If BitConverter.ToInt16(dos, 0) <> MZ Then Return Nothing Dim e_lfanew As Integer = BitConverter.ToInt32(dos, 60)
'IMAGE_NT_HEADER (IMAGE_FILE_HEADERまで) r.BaseStream.Seek(e_lfanew, SeekOrigin.Begin) Dim nt = r.ReadBytes(24) If nt.Length < 24 Then Return Nothing If BitConverter.ToInt32(nt, 0) <> PE Then Return Nothing Dim timeDateStamp As Integer = Marshal.ReadInt32(nt, 8) Return New Date(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timeDateStamp).ToLocalTime() End Using Catch Return Nothing End Try End Function End Module
'【.NET Framework 4.6 以上向け(VB2012以降)】 Imports System.Runtime.InteropServices Imports System.Reflection Imports System.IO Module Module1 Public Function GetBuildDateTime() As Date? Dim filePath As String = Assembly.GetExecutingAssembly().Location Return GetBuildDateTime(filePath) End Function Public Function GetBuildDateTime(ByVal filePath As String) As Date? Const MZ As Short = &H5A4DS Const PE As Integer = &H4550I Try Using r As New BinaryReader(File.OpenRead(filePath)) 'IMAGE_DOS_HEADER Dim dos = r.ReadBytes(64) If dos.Length < 64 Then Return Nothing If BitConverter.ToInt16(dos, 0) <> MZ Then Return Nothing Dim e_lfanew As Integer = BitConverter.ToInt32(dos, 60)
'IMAGE_NT_HEADER (IMAGE_FILE_HEADERまで) r.BaseStream.Seek(e_lfanew, SeekOrigin.Begin) Dim nt = r.ReadBytes(24) If nt.Length < 24 Then Return Nothing If BitConverter.ToInt32(nt, 0) <> PE Then Return Nothing Dim timeDateStamp As Integer = Marshal.ReadInt32(nt, 8) Return DateTimeOffset.FromUnixTimeSeconds(timeDateStamp).ToLocalTime().DateTime End Using Catch Return Nothing End Try End Function End Module
|