Disabling OBSOLETE error in C#

前端 未结 3 603
半阙折子戏
半阙折子戏 2020-12-03 21:22

I am using the Microsoft TFS API and one of the properties on one of the interfaces has been marked as Obsolete and it instructs me to use a different property. Unfortunate

3条回答
  •  無奈伤痛
    2020-12-03 21:47

    Visual Studio 2015

    Build failing due to [Obsolete]?

    This would only occur if "Treat Warnings As Errors" is enabled, and there is a method with the [Obsolete] attribute.

    Method 1: Downgrade error to warning

    Add 612,618 in the .csproj file (repeat for all sections):

    
        true
        4
        612,618
        true
        full
        false
        bin\Debug\
        DEBUG;TRACE
        prompt
    
    

    If dealing with many .csproj files, see Appendix A: Notepad++ for search and replace.

    Method 2: Ignore error in file

    Note: This method is not recommended, because it hides the warnings for methods marked [Obsolete]. We still want to see a list of all calls to obsolete methods so we can upgrade them.

    Use #pragma warning disable 612,618

    Method 3: Ignore error in project

    Note: This method is not recommended, because it hides the warnings for methods marked [Obsolete]. We still want to see a list of all calls to obsolete methods so we can upgrade them.

    Edit the project (repeat for all sections):

    Method 4: Ignore error in project

    Note: This method is not recommended, because it hides the warnings for methods marked [Obsolete]. We still want to see a list of all calls to obsolete methods so we can upgrade them.

    Manually edit your .csproj to disable warnings for specific errors. Add the tag 612,618 (repeat for all sections):

    
        612,618
        true
        bin\x64\Debug\
        DEBUG;TRACE
        true
        full
        x64
        prompt        
    
    

    Appendix A: Notepad++ for search and replace

    Have a lot of files? No problem!

    Open all .csproj files in NotePad++, then:

    • Find: true
    • Replace: true\n\t612,618

提交回复
热议问题