每个解决方案仅运行一次目标
我试图找到一种方法,在测试完成后,每个解决方案仅运行一次特定目标。
我有一个包含多个测试项目的解决方案。每个都与 coverlet.msbuild
集成,因此它们每个都会在指定文件夹中生成一个覆盖率报告 (opencover
) 文件。
我想要实现的是运行另一个目标,即 ReportGenerator
,但只有在完成所有测试并创建所有覆盖率报告文件之后。我已在 VSTest 目标之后成功创建了这些报告。但这意味着我在一次运行中多次生成报告,因为每个测试项目都单独运行 VSTest
目标。
这是我的最新尝试
<Project>
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>../../coverage/opencover/$(MSBuildProjectName).xml</CoverletOutput>
<CoverletOutputFormat>opencover</CoverletOutputFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="ReportGenerator" Version="5.0.4" />
</ItemGroup>
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
<ReportGenerator
ReportFiles="@(CoverletReport)"
TargetDirectory="../../coverage/html-coverage-report"
ProjectDirectory="$(MSBuildProjectDirectory)"
ClassFilters="-*OrleansGeneratedCode*"
HistoryDirectory="../../coverage/history"
ReportTypes="HTML"
VerbosityLevel="Verbose" />
</Target>
</Project>
注意:这是一个单独的props
文件,包含在所有测试项目使用的Directory.Build.props
中,只是为了避免重复。
有什么想法吗?
I'm trying to find a way to run a specific target only once per solution after tests are done.
I have a solution with multiple test projects. Each has integration with coverlet.msbuild
, hence they each produce a coverage report (opencover
) file in a designated folder.
What I want to achieve is run another target, namely ReportGenerator
, but only after all the tests are done and all the coverage report files are created. I've successfully created those report after the VSTest target. But that means I generate the report multiple times in a single run, because each testing project is running a VSTest
target separately.
this is my latest attempt
<Project>
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>../../coverage/opencover/$(MSBuildProjectName).xml</CoverletOutput>
<CoverletOutputFormat>opencover</CoverletOutputFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="ReportGenerator" Version="5.0.4" />
</ItemGroup>
<Target Name="GenerateHtmlCoverageReport" AfterTargets="GenerateCoverageResultAfterTest">
<ReportGenerator
ReportFiles="@(CoverletReport)"
TargetDirectory="../../coverage/html-coverage-report"
ProjectDirectory="$(MSBuildProjectDirectory)"
ClassFilters="-*OrleansGeneratedCode*"
HistoryDirectory="../../coverage/history"
ReportTypes="HTML"
VerbosityLevel="Verbose" />
</Target>
</Project>
Note: this is a separate props
file included in the Directory.Build.props
that is used by all test projects, just to avoid duplication.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些研究,我发现通过自定义构建过程,每个解决方案可以仅运行特定的目标一次,如 微软文档
技巧是引入一个名为的
targets
文件after..sln.targets
靠近解决方案文件。就我而言,它是:
在运行 VSTest 目标后运行此目标,每个解决方案仅运行一次。
After some research I've found that it is possible to run specific
targets
only once per solution by customizing the build process as described in the microsoft documentationthe trick was to introduce a
targets
file calledafter.<solution name>.sln.targets
near the solution file.in my case it was:
which ran this target after the VSTest target was run, which is only once per solution.