Skip to content

Commit f016c7b

Browse files
committed
Fix dotnet build of a clean repo
For a perfectly clean repo (git clean -fdx), `dotnet build` fails because some tests require that other projects have been built using build.proj first. This change adds the necessary build ordering instructions so that the build tasks are always built before the tests that need them, and the tests are always run against the *latest* source code being tested rather than the last version that happened to be built with build.proj.
1 parent 02708bb commit f016c7b

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

build.proj

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,7 @@
1313
<Exec Command="dotnet build &quot;$(MSBuildThisFileDirectory)src\coverlet.collector\coverlet.collector.csproj&quot; -c $(Configuration)" />
1414
</Target>
1515

16-
<Target Name="PublishMSBuildTaskProject" AfterTargets="BuildAllProjects">
17-
<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)src\coverlet.msbuild.tasks\coverlet.msbuild.tasks.csproj&quot; -c $(Configuration) -o &quot;$(OutputPath)&quot;" />
18-
</Target>
19-
20-
<Target Name="CopyMSBuildScripts" AfterTargets="PublishMSBuildTaskProject">
21-
<ItemGroup>
22-
<BuildScript Include="$(MSBuildThisFileDirectory)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
23-
<BuildScript Include="$(MSBuildThisFileDirectory)src\coverlet.msbuild.tasks\coverlet.msbuild.targets" />
24-
</ItemGroup>
25-
<Copy SourceFiles="@(BuildScript)" DestinationFolder="$(OutputPath)" />
26-
</Target>
27-
28-
<Target Name="RunTests" AfterTargets="CopyMSBuildScripts">
16+
<Target Name="RunTests" AfterTargets="BuildAllProjects">
2917
<Exec Command="dotnet test &quot;$(MSBuildThisFileDirectory)test\coverlet.core.tests\coverlet.core.tests.csproj&quot; -c $(Configuration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=[coverlet.*]*"/>
3018
<Exec Command="dotnet test &quot;$(MSBuildThisFileDirectory)test\coverlet.collector.tests\coverlet.collector.tests.csproj&quot; -c $(Configuration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=[coverlet.*]*"/>
3119
</Target>

src/coverlet.msbuild.tasks/coverlet.msbuild.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
<ThresholdType Condition="$(ThresholdType) == ''">line,branch,method</ThresholdType>
1717
<ThresholdStat Condition="$(ThresholdStat) == ''">minimum</ThresholdStat>
1818
</PropertyGroup>
19+
<PropertyGroup>
20+
<CoverletToolsPath Condition=" '$(CoverletToolsPath)' == '' ">$(MSBuildThisFileDirectory)</CoverletToolsPath>
21+
</PropertyGroup>
1922
</Project>

src/coverlet.msbuild.tasks/coverlet.msbuild.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

3-
<UsingTask TaskName="Coverlet.MSbuild.Tasks.InstrumentationTask" AssemblyFile="$(MSBuildThisFileDirectory)coverlet.msbuild.tasks.dll"/>
4-
<UsingTask TaskName="Coverlet.MSbuild.Tasks.CoverageResultTask" AssemblyFile="$(MSBuildThisFileDirectory)coverlet.msbuild.tasks.dll"/>
3+
<UsingTask TaskName="Coverlet.MSbuild.Tasks.InstrumentationTask" AssemblyFile="$(CoverletToolsPath)coverlet.msbuild.tasks.dll"/>
4+
<UsingTask TaskName="Coverlet.MSbuild.Tasks.CoverageResultTask" AssemblyFile="$(CoverletToolsPath)coverlet.msbuild.tasks.dll"/>
55

66
<Target Name="InstrumentModulesNoBuild" BeforeTargets="VSTest">
77
<Coverlet.MSbuild.Tasks.InstrumentationTask

test/Directory.Build.targets

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project>
2+
<Choose>
3+
<!-- This condition tests whether coverlet.msbuild.props has been imported by the project -->
4+
<When Condition=" '$(ThresholdType)' != '' ">
5+
<ItemGroup>
6+
<!-- Arrange for the project that builds the build tools has built first. -->
7+
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\src\coverlet.msbuild.tasks\coverlet.msbuild.tasks.csproj">
8+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
9+
</ProjectReference>
10+
</ItemGroup>
11+
<PropertyGroup>
12+
<!-- Ensure that the built tools can be found at build time.
13+
This is required when the coverlet.msbuild imports are made in their src directory
14+
(so that msbuild eval works even before they are built)
15+
so that they can still find the tooling that will be built by the build. -->
16+
<CoverletToolsPath>$(MSBuildThisFileDirectory)..\src\coverlet.msbuild.tasks\bin\$(Configuration)\netstandard2.0\</CoverletToolsPath>
17+
</PropertyGroup>
18+
</When>
19+
</Choose>
20+
</Project>

test/coverlet.core.performancetest/coverlet.core.performancetest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="$(MSBuildThisFileDirectory)\..\..\build\$(Configuration)\coverlet.msbuild.props" />
2+
<Import Project="..\..\src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
33

44
<PropertyGroup>
55
<TargetFramework>netcoreapp2.0</TargetFramework>
@@ -15,5 +15,5 @@
1515
<ProjectReference Include="..\coverlet.testsubject\coverlet.testsubject.csproj" />
1616
</ItemGroup>
1717

18-
<Import Project="$(MSBuildThisFileDirectory)\..\..\build\$(Configuration)\coverlet.msbuild.targets" />
18+
<Import Project="..\..\src\coverlet.msbuild.tasks\coverlet.msbuild.targets" />
1919
</Project>

test/coverlet.core.tests/coverlet.core.tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="$(MSBuildThisFileDirectory)\..\..\build\$(Configuration)\coverlet.msbuild.props" />
2+
<Import Project="..\..\src\coverlet.msbuild.tasks\coverlet.msbuild.props" />
33

44
<PropertyGroup>
55
<TargetFramework>netcoreapp2.0</TargetFramework>
@@ -19,5 +19,5 @@
1919
<ProjectReference Include="..\..\src\coverlet.core\coverlet.core.csproj" />
2020
</ItemGroup>
2121

22-
<Import Project="$(MSBuildThisFileDirectory)\..\..\build\$(Configuration)\coverlet.msbuild.targets" />
22+
<Import Project="..\..\src\coverlet.msbuild.tasks\coverlet.msbuild.targets" />
2323
</Project>

0 commit comments

Comments
 (0)