Visual Studio 2022 Net6.0 无法发现testcase, 也无法执行test case

 

错误1:

编译正确,运行时 Tests 输出报错,

Failed to load extensions from file 'C:\Users\tangj15\.nuget\packages\xunit.runner.visualstudio\2.5.0\build\net6.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll'. Please use /diag for more information.

 

错误2:

编译正确,但编译完成时查看Tests输出,提示自动发现test case时错误

Failed to load extensions from file 'C:\Users\tangj15\.nuget\packages\xunit.runner.visualstudio\2.5.0\build\net6.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll'. Please use /diag for more information.

 

解决办法:

针对错误1,添加如下属性,且设置为true。

 

    <PropertyGroup>
							

          

        <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
											

        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
											

        <GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
											

 

        <GenerateDocumentationFile>false</GenerateDocumentationFile>
											

        <GenerateDependencyFile>false</GenerateDependencyFile>
											

    </PropertyGroup>
							

 

针对错误2,添加如下引用。不可缺少(针对xunit)

 

    <ItemGroup>
							

      <PackageReference Include="coverlet.collector" Version="6.0.0">
																			

        <PrivateAssets>all</PrivateAssets>
											

        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
											

      </PackageReference>
							

      <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
																			

      <PackageReference Include="Microsoft.TestPlatform" Version="17.6.3" />
																			

      <PackageReference Include="xunit" Version="2.5.0" />
																			

      <PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
																			

        <PrivateAssets>all</PrivateAssets>
											

        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
											

      </PackageReference>
							

    </ItemGroup>
							

posted @ 2023-07-19 18:09  一叶浮萍  阅读(68)  评论(0编辑  收藏  举报