VS.NET 에서 Build Number 자동 증가 (1)
빌드 넘버 자동 증가
Build number automatic increasement
VS 6.0 이용자들은 다음 링크 사용
For VS 6.0 users
http://www.support.microsoft.com/default.aspx?scid=kb;en-us;237870
VS.NET 2003, 2005 이용자들은 여기 적힌대로 적용한다.
현재 몇몇 매크로들이 제대로 작동을 하지 않아서 직접 약간 수정을 했다.
기본적인 방법은 대부분 같다. MFC 프로젝트를 기준으로 설명한다.
For VS.NET 2003, 2005 users, you just need to follow the explaination below.
프로젝트명은 MyProject라고 했다고 가정한다.
Let us assume the project name as MyProject.
MFC 프로젝트로 생성했다면 프로젝트 폴더에 MyProject.rc 와 \res 폴더에
MyProject.rc2 라는 파일을 연다. 그냥 Win32 Application으로 생성했다면
다른 MFC 프로젝트 폴더에서 \res 폴더를 그대로 카피해와서 MyProject.rc2
파일만 남기고 모두 지운다.(파일명을 바꾸어야 할 것이다.)
If you create MFC project, open up the MyProject.rc and
\res\MyProject.rc2 files. If you create Win32 Application project,
just copy the \res\xxxx.rc2 file from another MFC project folder and
rename it.
MyProject.rc 파일에서 다음 부분을 cut 한다.
Cut next section from MyProject.rc
////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
.
.
.
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
Win32App 프로젝트라면 MyProject.rc 파일에 다음 부분을 추가해야 한다.
Add next line if your project is Win32App.
...
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""res\\ProjectName.rc2"" // <------- Here
"\0"
END
...
MyProject.rc2 파일의 다음 위치에 paste 한다.
Paste the copied text in the MyProject.rc2.
...
////////////////////////////////////////////////////////
// Add manually edited resources here...
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//
// Version
//
#include "VersionNo.h" // <------- Here
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILEVER // <------- Here
PRODUCTVERSION PRODUCTVER // <------- Here
FILEFLAGSMASK 0x3fL
...
BEGIN
VALUE "FileDescription", "MyProject Application"
VALUE "FileVersion", STRFILEVER
// <------- Here
VALUE "InternalName", "MyProject"
VALUE "LegalCopyright", "Copyright (C) 2003"
VALUE "OriginalFilename", "MyProject.exe"
VALUE "ProductName", " MyProjectApplication"
VALUE "ProductVersion", STRPRODUCTVER
// <------- Here
END
...
VersionNo.h 라는 파일을 만들고 다음과 같은 내용으로 채운다. 일단 여기에
있는 내용을 그대로 옮기기 바란다.
Create a VersionNo.h file and copy and paste next 4 lines.
#define FILEVER 1,0,0,1
#define PRODUCTVER 1,0,0,1
#define STRFILEVER "1, 0, 0, 1"
#define STRPRODUCTVER "1, 0, 0, 1"
Tools->Macros->New Macro Project 를 실행한다.
Select Tools->Macros->New Macro Project
Macro Explorer 창이 나타날 것이다. "+" 키를 누르면 기본적으로 "Module1"
이라는 마크로가 있을 것이다. 이것을 원하는 이름으로 변경한다.
그것을 더블클릭하면 Macro IDE가 나타날 것이다.
It will open up "Macro Explorer" window. Press "+" in the macro project
and it displays "Module1". You can rename it to whatever you want.
Double click the module to open Macro IDE.
에디터 창에 있는 모든 내용을 지우고 다음으로 채워 넣는다.
Delete all existing code and copy and paste next code.
======= FROM NEXT ================================================
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module IncreaseBuildNo
Function GetProjectDir(ByVal FullName)
Dim proj_path
proj_path = Split(StrReverse(FullName), "\", -1, 1)
Dim count
count = UBound(proj_path)
Dim full_path
full_path = ""
Dim i
For i = 1 To count
full_path = full_path & "\" & proj_path(i)
Next
GetProjectDir = StrReverse(full_path)
End Function
Sub ReplaceText(ByVal objSel As TextSelection, ByVal count As Integer, ByVal incrementby As Integer, ByVal Type As Integer)
'selection represents the TextSelection object
'count represents the position of the version number
'to be incremented
'incrementally represents a number that will be added
'to the existing version number
Dim strTemp As String
Dim i
strTemp = ""
objSel.EndOfLine()
If Type = 0 Then
For i = 1 To count
If strTemp.StartsWith(",") = True Then
Exit For
Else
objSel.CharLeft(True, 1)
strTemp = objSel.Text
End If
Next
strTemp = strTemp.Remove(0, 1)
strTemp = strTemp + incrementby
objSel.Text = "," & strTemp
Else
For i = 1 To count
If strTemp.StartsWith(" ") = True Then
Exit For
Else
objSel.CharLeft(True, 1)
strTemp = objSel.Text
End If
Next
strTemp = strTemp.Remove(0, 1)
strTemp = strTemp.Remove(strTemp.Length - 1, 1)
strTemp = strTemp + incrementby
objSel.Text = " " & strTemp & """"
End If
End Sub
Dim WithEvents bldevents As BuildEvents
Dim applicationObject As EnvDTE.DTE
Sub BuildDoneEvents()
Dim addInInstance As EnvDTE.AddIn
applicationObject = CType(Application, EnvDTE.DTE)
bldevents = CType(applicationObject.Events. _
BuildEvents, EnvDTE.BuildEvents)
End Sub
Private Sub bldevents_OnBuildDone(ByVal _
Scope As EnvDTE.vsBuildScope, _
ByVal Action As EnvDTE. _
vsBuildAction) Handles _
bldevents.OnBuildDone
'This event will be triggered after every build
'of a project
'Obtain the full path of the active project
Dim full_path
full_path = GetProjectDir(DTE.ActiveDocument.Path)
full_path = full_path & "VersionNo.h"
'Open the VersionNo.h file
Dim doc As Document
DTE.ItemOperations.OpenFile(full_path)
Dim objDoc As TextDocument
'Obtain the TextSelection object
objDoc = DTE.ActiveDocument.Object("TextDocument")
Dim objSel As TextSelection = _
DTE.ActiveDocument.Selection
objSel.StartOfDocument()
'Increment the version information
ReplaceText(objSel, 5, 1, 0)
objSel.LineDown()
objSel.StartOfLine()
ReplaceText(objSel, 5, 1, 0)
objSel.LineDown()
objSel.StartOfLine()
ReplaceText(objSel, 7, 1, 100)
objSel.LineDown()
objSel.StartOfLine()
ReplaceText(objSel, 7, 1, 100)
ActiveDocument.Save()
ActiveDocument.Close()
End Sub
End Module
======= TO HERE ==========================================
매크로를 저장하고 VS.NET으로 돌아 와서 Macro Explorer 에서 해당 모듈을
오른클릭해서 "Run" 을 선택해서 실행시킨다.
Save the macro and in the VS.NET, in the "Macro Explorer",
right-click it and choose "Run".
따라 하기만 하면 빌드할 때마다 VersionNo.h 파일의 Build 번호가 자동으로
증가할 것이다.
If nothing wrong, you can see the build number is increased after the build.
댓글 없음:
댓글 쓰기