Use libxml and Ruby to process. vcxproj files and. vcproj files

Source: Internet
Author: User

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)
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.