Search code examples
c#visual-studiocompiler-errorsvisual-studio-2022live-unit-tests

How can I ignore obsolete type errors when running Live Unit Testing in VS 2022 enterprise?


I have a solution with about 58 projects, including 10 test projects. There's only one I'm interested in running, that relates to my team's work.

I can run the test project manually from the Test Explorer, and it builds with all tests passing fine.

However, when I set up Live Unit Testing, the build fails due to obsolete types being used in some another projects. I don't want to replace all the type references since that code is managed by other teams.

Here are my VS2022 LUT settings.

I have only added the test project I'm interested in to the LUT playlist. I also tried replacing some of the obsolete types (I only had 3 errors initially) but the compiler then found dozens more...

I increased the logging level on LUT to verbose, but that didn't give anything useful. There aren't any other settings I can see for LUT to ignore certain projects or errors.

I have looked up the MS documentation on the [obsolete] attribute, but I'm not sure why I get the error on LUT and not on regular test or debug builds.

The .csproj of a project that fails has this line: <TreatWarningsAsErrors>True</TreatWarningsAsErrors> and setting it to False allows LUT to build it. But I don't want to have to change dozens of .csprojs just for running some tests.

Is there any other way to mark errors as warnings for live unit testing?


Solution

  • Instead of setting <TreatWarningsAsErrors>false</TreatWarningsAsErrors> you can add <NoWarn>CS0618</NoWarn> to the project files. That's probably going to help everybody, because others will have the same problem as well.

    You can also add a section such as the following to your Directory.Build.props file (should be in the root of your project structure):

      <PropertyGroup Condition="$(MSBuildProjectName.EndsWith('UnitTest')) AND '$(MSBuildProjectExtension)' == '.csproj'">
        <NoWarn>$(NoWarn);CS0618</NoWarn>
      </PropertyGroup>
    

    This will disable the warning for all projects whose name ends with "UnitTest".