Introduced
Each of us from the original development environment to the user under the Vs.net, have encountered a lot of obstacles. One of the obstacles I have encountered is that my original macro cannot continue to work.
Now the compile serial number automatic growth tool is a combination of many people's code snippets, although it is not perfect, and lack of some features, but at least it provides a solid foundation for further development.
Goal
Here is the need to compile the serial number automatically:
1. At the time of compiling each release, automatically increase the compiled serial number saved in a separate file, which will be added to my project.
2. Automatically record the date and serial number of the compilation.
Code Analysis
My first task was to find a replacement for vs 6. Application_beforebuildstart () event, VS. NET designers provide us with a very easy to use compilation events:
Onbuildbegin
OnBuildDone
Onbuildprojconfigbegin
OnBuildProjConfigDone
The naming conventions for these event handlers are a bit misleading. We don't want to use onbuildbegin, because even if we compile for multiple configurations (release, Debug, and so on), It will only be executed once. This makes it difficult to increase the compilation sequence number only when compiling release versions. Onbuildprojconfigbegin can be executed when compiling for each configuration. It also provides a string parameter named Projectconfig to describe which configuration is being used by the current compilation.
Most of the tasks are done in the Onbuildprojconfigbegin event handler, which also uses two auxiliary macro:
Writetologfile
Writetooutputbuildpane
Both macros can be written to the Onbuildprojconfigbegin event handler or deleted when not in use.
Private Sub Buildevents_onbuildprojconfigbegin (
ByVal Project as String,
ByVal Projectconfig as String,
ByVal Platform as String,
ByVal Solutionconfig as String)
Handles Buildevents.onbuildprojconfigbegin
' Abort if build type is debug
If InStr (1, Projectconfig, "Debug", 1) Then Exit Sub
Dim SW As StreamWriter = File.appendtext (log_filename)
Sw. WriteLine (Msg_text)
Sw. Close ()
Catch ex as Exception
MsgBox ("Log file Write failed:" & ex. Message)
End Try
End Sub
' ----------------------------------------------------------------
' Write a text message to the ' build pane of the Output tool window
' ----------------------------------------------------------------
Sub Writetooutputbuildpane (ByVal msg_text as String)
' Create a tool window handle for the Output window.
Dim win as Window = DTE. Windows.item (EnvDTE.Constants. _
Qvswindowkindoutput)
' Create handles to the ' Output window and it build pane.
Dim OW as OutputWindow = win. Object
Dim OWP as OutputWindowPane
OWP = OW. OutputWindowPanes.Item ("Build")
' Add a line of ' the ' the ' Output pane.
Owp.outputstring (Msg_text & VbCrLf)
End Sub
Integration
Attention! If you don't have a macro project, create one first. You need to open a macro project and display it in the VS Macros IDE. (Note: You can use the shortcut key ALT + F8, or click View-> other Windows-> Macro Explorer to open the Macro Navigation window.) Double-click one of the macros to edit.
1. Each macro project has a page called EnvironmentEvents, double-click to open it.
2. From the class name Drop-down list, select BuildEvents.
3. Select Onbuildprojconfigbegin from the method name Drop-down list.
4. Add two reference declarations (import).
The declaration of an exception class needs to reference the System namespace. The action class for the file affirms the need to reference System.IO.
5. Add in the Onbuildprojconfigbegin method.
6. Double hit Open Module1 page.
Module1 is a default page name used by the IDE. If you use a different name, be sure to modify the corresponding namespace in the Onbuildprojconfigbegin.
Add two secondary methods.
Add pairs. Reference to System and. Systemio.
Run
Save the editing results, and then compile to check for errors. Once the compilation is successful, it can be used directly. It is simple to use, and this code is executed at every compile time.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.