diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
new file mode 100644
index 000000000000..493dd5c6774a
--- /dev/null
+++ b/.config/dotnet-tools.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "dotnet-reportgenerator-globaltool": {
+ "version": "4.8.0",
+ "commands": [
+ "reportgenerator"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6c87d512c524..5d23868878f3 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -55,8 +55,11 @@ Nuget package will be created in root directory under \artifacts\packages\Debug
### Using the command line:
Run e.g. `msbuild eng\mgmt.proj /t:"Runtests" /p:Scope=Compute`
-In the above example _RunTests_ will build and run tests for Compute only or you can use command line CLI
-`dotnet test Compute\Microsoft.Azure.Management.Compute\tests\Microsoft.Azure.Management.Tests.csproj`
+In the above example _RunTests_ will build and run tests for Compute only or you can use command line CLI:
+
+```bash
+dotnet test Compute\Microsoft.Azure.Management.Compute\tests\Microsoft.Azure.Management.Tests.csproj
+```
### Non-Windows command line build
@@ -67,6 +70,17 @@ Now you can use the same command on non-windows as above for e.g. on Ubuntu you
- `dotnet msbuild eng\mgmt.proj /t:CreateNugetPackage /p:scope=Compute`
- `dotnet msbuild build.proj /t:Util /p:UtilityName=InstallPsModules`
+### Code Coverage
+
+If you want to enable code coverage reporting, on the command line pass `/p:CollectCoverage=true` like so:
+
+```bash
+dotnet test /p:CollectCoverage=true
+```
+
+On developers' machines, you can open `index.html` from within the `TestResults` directory in your test projects.
+Coverage reports can also be found in Azure Pipelines on the "Code Coverage" tab after a pull request validation build completes.
+
### Update build tools
Build tools are now downloaded as part of a nuget package under `root\restoredPackages\microsoft.internal.netsdkbuild.mgmt.tools`
diff --git a/eng/CodeCoverage.runsettings b/eng/CodeCoverage.runsettings
index d1cde17305e9..22bb025333d7 100644
--- a/eng/CodeCoverage.runsettings
+++ b/eng/CodeCoverage.runsettings
@@ -1,16 +1,23 @@
+
+
+
+
+
-
+
cobertura
- ExcludeFromCodeCoverage,GeneratedCodeAttribute,Obsolete
- false
+ ExcludeFromCodeCoverageAttribute,GeneratedCodeAttribute,Obsolete
false
+ false
true
+
+
diff --git a/eng/CodeCoverage.targets b/eng/CodeCoverage.targets
index 980757434aea..f38947af3980 100644
--- a/eng/CodeCoverage.targets
+++ b/eng/CodeCoverage.targets
@@ -1,11 +1,42 @@
-
+
+ $([System.IO.Path]::GetFullPath("$(MSBuildProjectDirectory)\.."))
+ true
+ $(MSBuildProjectDirectory)\TestResults
+
+
+
+
all
runtime; build; native; contentfiles; analyzers
+
+
+
+
+
+
+
+
+ dotnet tool run reportgenerator --
+ $(CoverageReportCommandLine) "-reports:$(TestResultsDirectory)\**\coverage.cobertura.xml"
+ $(CoverageReportCommandLine) -reporttypes:Html
+ $(CoverageReportCommandLine) "-targetdir:$(TestResultsDirectory)"
+ $(CoverageReportCommandLine) "-filefilters:+$(CodeCoverageDirectory)\**"
+
+
+
+
-
- XPlat Code Coverage
-
- $(MSBuildThisFileDirectory)CodeCoverage.runsettings
-
-
@@ -108,7 +96,7 @@
false
netcoreapp2.1;net5.0
- netcoreapp2.1;net5.0;net461
+ net461;netcoreapp2.1;net5.0
diff --git a/eng/Directory.Build.Data.targets b/eng/Directory.Build.Data.targets
index a9f939e79812..e12b292d59be 100644
--- a/eng/Directory.Build.Data.targets
+++ b/eng/Directory.Build.Data.targets
@@ -71,8 +71,20 @@
-
-
+
+
+ <_ImportCodeCoverage>true
+ XPlat Code Coverage
+
+ $(MSBuildThisFileDirectory)CodeCoverage.runsettings
+
+
+
diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props
index 36ac2f4509dd..89ce9e3fcbc1 100644
--- a/eng/Packages.Data.props
+++ b/eng/Packages.Data.props
@@ -11,7 +11,7 @@
-
+
@@ -180,9 +180,9 @@
-
+
-
+
diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml
index 0e9f16765e54..dae7320da937 100644
--- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml
+++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml
@@ -150,7 +150,8 @@ jobs:
--logger "trx;LogFileName=$(TestTargetFramework).trx" --logger:"console;verbosity=normal"
/p:ServiceDirectory=${{parameters.ServiceToTest}}
/p:IncludeSrc=false /p:IncludeSamples=false /p:IncludePerf=false /p:IncludeStress=false
- /p:Configuration=$(BuildConfiguration) $(ConvertToProjectReferenceOption) /p:CollectCoverage=$(CollectCoverage)
+ /p:Configuration=$(BuildConfiguration) $(ConvertToProjectReferenceOption)
+ /p:CollectCoverage=$(CollectCoverage) /p:CodeCoverageDirectory=${{parameters.ServiceDirectory}}
displayName: "Build & Test ($(TestTargetFramework))"
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
@@ -165,14 +166,16 @@ jobs:
mergeTestResults: true
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'))
- displayName: ReportGenerator
+ displayName: Generate Code Coverage Reports
inputs:
- reports: 'sdk/**/coverage.cobertura.xml'
- targetdir: '$(Build.SourcesDirectory)'
- reporttypes: 'Cobertura;HtmlSummary'
+ reports: sdk/**/coverage.cobertura.xml
+ targetdir: $(Build.SourcesDirectory)
+ reporttypes: Cobertura;HtmlSummary
+ filefilters: >-
+ +sdk/${{parameters.ServiceDirectory}}
- task: PublishCodeCoverageResults@1
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'))
- displayName: 'Publish code coverage report'
+ displayName: Publish Code Coverage Reports
inputs:
- codeCoverageTool: 'Cobertura'
- summaryFileLocation: 'Cobertura.xml'
+ codeCoverageTool: Cobertura
+ summaryFileLocation: Cobertura.xml
diff --git a/eng/service.proj b/eng/service.proj
index 9e6ecfe5897a..b8197a7fdc33 100644
--- a/eng/service.proj
+++ b/eng/service.proj
@@ -9,6 +9,9 @@
true
true
false
+
+ CodeCoverageDirectory=$([System.IO.Path]::GetFullPath("$(CodeCoverageDirectory)", "$(MSBuildThisFileDirectory)..\sdk"));
+
diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs
index 587a672be15c..bc1602162ded 100644
--- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs
+++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/CertificatesTestBase.cs
@@ -17,7 +17,7 @@ namespace Azure.Security.KeyVault.Certificates.Tests
CertificateClientOptions.ServiceVersion.V7_0,
CertificateClientOptions.ServiceVersion.V7_1)]
[NonParallelizable]
- public class CertificatesTestBase : RecordedTestBase
+ public abstract class CertificatesTestBase : RecordedTestBase
{
protected readonly TimeSpan PollingInterval = TimeSpan.FromSeconds(5);
private readonly CertificateClientOptions.ServiceVersion _serviceVersion;
diff --git a/sdk/keyvault/samples/Directory.Build.props b/sdk/keyvault/samples/Directory.Build.props
index aac01a03d888..fe5aa561b019 100644
--- a/sdk/keyvault/samples/Directory.Build.props
+++ b/sdk/keyvault/samples/Directory.Build.props
@@ -3,6 +3,7 @@
true
false
+ true
false