对于几个项目,我有一个通用的使用项目,它包含一些基本的测试类、助手类等等。项目定义如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<RootNamespace>SomeRoot.Util</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
</Project>
我假设由于它引用了xUnit,所以visual和dotnet test
命令都把它当作一个测试项目。但是,由于它不是,我想在某种程度上防止visual和dotnet test
不承认这个项目是一个测试项目。
删除对xUnit的引用不是一个选项,因为基类需要来自xUnit包的一些接口。
发布于 2022-06-27 17:02:14
基于https://github.com/microsoft/vstest/issues/1129,它似乎检查了两件事情:IsTestProject
属性和TestContainer
的ProjectCapability
项。为了安全起见,我把两者都移走了。
将其添加到项目文件中:
<PropertyGroup>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Remove="TestContainer" />
</ItemGroup>
这是我在运行时遇到的错误,通过添加以下内容修复了该错误:
========== Starting test discovery ==========
Test project {ProjectName} does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
Loaded 0 test records from the solution cache in 0.220 sec.
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.VisualStudio.TestPlatform.TestHost.Program.Main(String[] args)
. Please check the diagnostic logs for more information.
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
https://stackoverflow.com/questions/61864140
复制相似问题