The. vcproj file is no stranger to Visual Studio (VC ++) users, and. vcxproj is released after vs2010, The. vcproj file is changed
. Vcxproj. They are all XML-based files, so there are many libraries for parsing them. Here I will use libxml.
The simple function I want to implement is to add an ignorewarning (remove warning) to all projects in the project, such as/ignore: 4011.
Write a script to add/ignor: 4011 to all. vcproj (versions earlier than vs2008) or all. vcxproj (vs2010.
Note that you must use the libxml library to parse. vcxproj. Add the default namespace prefix to the parsed node (node), and the default namespace prefix to. vcproj.
This is not required.
Another point: the location where the/ignore: 4011 is added. vcxproj and. vcproj are different. Specific analysis of ignore warning.
The example code for parsing. vcproj and. vcxproj is provided below (for reference only ):
# To the. vcproj
Require 'libxml'
Include libxmldef ignorewarningadd (filepath)
Parser = libxml: XML: parser. File (filepath)
Doc = parser. parse Doc. Find ("// tool"). Each do | tool |
Puts tool ['name']
If tool ['name'] = "vclinkertool" & tool ['additionaloptions'] = ""
Tool ['additionaloptions'] = "/ignore: 4011"
End
End Doc. Save (filepath)
End # recur to find the. vcproj filesdef vcprojwarningadd (dirpath)
Dir. Entries (dirpath). Each do | sub |
If sub! = '.' & Sub! = '..'
If file. directory? ("# {Dirpath}/# {sub }")
Vcprojwarningadd ("# {dirpath}/# {sub }")
Else
Filepath = "# {dirpath}/# {sub }"
# If/*. vcproj/. Match (filepath) If file. extname (filepath) = '. vcproj'
Ignorewarningadd ("# {dirpath}/# {sub }")
End
End
End
End
End # vcprojwarningadd ("E: // vcproj_folders") vcprojwarningadd (argv)
# To the. vcxprojRequire 'libxml'
Include libxml
Def ignorewarningadd (filepath)
Document = libxml: XML: Document. File (filepath)
Root = Document. Root # To. vcxproj, need the default namespace prefix to parse the. vcxproj File
Root. namespaces. default_prefix = "parsexml_ns"
Document. Find ('// parsexml_ns: link // parsexml_ns: additionaloption'). Each do | node |
Puts "Here I entered"
Node </ignore: 4011"
End
Document. Save (filepath)
End
Def vcxprojwarningadd (dirpath)
Dir. Entries (dirpath). Each do | sub |
If sub! = '.' & Sub! = '..'
If file. directory? ("# {Dirpath}/# {sub }")
Vcxprojwarningadd ("# {dirpath}/# {sub }")
Else
Filepath = "# {dirpath}/# {sub }"
# If/. vcxproj/. Match (filepath) If file. extname (filepath) = '. vcxproj'
Puts filepath
Ignorewarningadd ("# {dirpath}/# {sub }")
Puts "Here am I: # {dirpath}/# {sub }"
End
End
End
End
End
# Vcxprojwarningadd ("E: // vcxproj_folder ")
Vcxprojwarningadd (argv)