none
How to remove all the suppressed compiler warnings from a solution RRS feed

  • Question

  • Hi,

    I have a visual studio solution with hundreds of projects (Few projects are in some folders ) where we have suppressed few warnings for every project.

    it is hard to remove the suppression's from each and every project (Project-->Properties-->Build-->SupressWarnings and remove all the numbers) Is there any way to remove all the suppressions at one shot using any sample script?


    • Edited by Avatar 123 Thursday, March 14, 2019 11:53 AM
    Thursday, March 14, 2019 10:09 AM

Answers

  • If you want to remove all the warnings across all projects in a solution then the only approach that I know is to enumerate the project files and remove the entries. While you could figure out MSBuild I think it would just be easier to use XPath to find and remove all the entries.  What you need to remove is the `Project\PropertyGroup\NoWarn` elements in a file. Note that there will generally be multiple entries so you should remove all of them.

    Try this PowerShell script. It is written only for C# projects but should work with VB projects as well. If you're using the newer SDK format projects then it may fail to load the XML because there isn't a traditional XML declaration.

    $targetPath = "??"
    
    $projectFiles = Get-ChildItem $targetPath -Include "*.csproj" -Recurse
    foreach ($projectFile in $projectFiles) {    
        $xml = [xml](Get-Content $projectFile)
        $namespace = $xml.DocumentElement.NamespaceURI
        $ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
        $ns.AddNamespace("ns", $namespace)    
    
        $items = $xml.SelectNodes("//ns:Project/ns:PropertyGroup/ns:NoWarn", $ns)
        foreach ($item in $items) {
            $item.ParentNode.RemoveChild($item)         
        }
    
        $xml.Save($projectFile)
    }


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, March 14, 2019 2:29 PM
    Moderator

All replies

  • Hi,

    I have a solution with hundreds of projects (Few projects are in some folders ) where we have suppressed few warnings for every project.

    it is hard to remove the suppression's from each and every project (Project-->Properties-->Build-->SupressWarnings and remove all the numbers) Is there any way to remove all the suppressions at one shot using any sample script?


    Try these: link1, link2, link3, link4, link5.
    I advise to read and try the solutions.

    I just exclude them from showing on the error list, and that's fine for me.

    PS: If they work, I just Googled and read to see if they was talking about your problem.


    BP-LP 2005/2016 @ll rights reserved

    Thursday, March 14, 2019 11:39 AM
  • If you want to remove all the warnings across all projects in a solution then the only approach that I know is to enumerate the project files and remove the entries. While you could figure out MSBuild I think it would just be easier to use XPath to find and remove all the entries.  What you need to remove is the `Project\PropertyGroup\NoWarn` elements in a file. Note that there will generally be multiple entries so you should remove all of them.

    Try this PowerShell script. It is written only for C# projects but should work with VB projects as well. If you're using the newer SDK format projects then it may fail to load the XML because there isn't a traditional XML declaration.

    $targetPath = "??"
    
    $projectFiles = Get-ChildItem $targetPath -Include "*.csproj" -Recurse
    foreach ($projectFile in $projectFiles) {    
        $xml = [xml](Get-Content $projectFile)
        $namespace = $xml.DocumentElement.NamespaceURI
        $ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
        $ns.AddNamespace("ns", $namespace)    
    
        $items = $xml.SelectNodes("//ns:Project/ns:PropertyGroup/ns:NoWarn", $ns)
        foreach ($item in $items) {
            $item.ParentNode.RemoveChild($item)         
        }
    
        $xml.Save($projectFile)
    }


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, March 14, 2019 2:29 PM
    Moderator
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 19, 2019 3:27 AM
    Moderator