Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.2.0: Support packages.config and exclude the attributes from code coverage by default #7

Merged
merged 7 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

[*.md]
indent_size=2
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

# v1.2.0

This release provides solutions for [issue #1](https://github.com/manuelroemer/Nullable/issues/1) and
[issue #6](https://github.com/manuelroemer/Nullable/issues/6). In addition, potential compiler
warnings in the `NullableAttributes.cs` file are now hidden.

**Upgrading:**

Remove any previously defined `NULLABLE_ATTRIBUTES_EXCLUDE_FROM_CODE_COVERAGE` compiler constant,
as it does not have any effect anymore.

> :information_source: **Note:** <br/>
> Builds will NOT break if the constant is still defined. It is simply ignored now.

**Details:**

* The package now supports `packages.config` via a `content/` folder in the NuGet package.
* The attributes are now excluded from code coverage by default.
When referenced from projects targeting .NET Standard >= 2.0 or .NET Framework >= 4.0, the
`ExcludeFromCodeCoverageAttribute` is used. For other project types, the `DebuggerNonUserCodeAttribute`
is used.
* Added support for the `NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE` compiler constant which
removes the code coverage attributes.
* The `NULLABLE_ATTRIBUTES_EXCLUDE_FROM_CODE_COVERAGE` compiler constant no longer has
any effects. Code coverage is now disabled by default.
* The `NullableAttributes.cs` file now wraps the attributes with a `#pragma warning disable` and
`#pragma warning restore` block to disable both compiler- and code-analysis warnings.


# v1.1.1

This release adds the `// <auto-generated>` header to the `NullableAttributes.cs` file so that
Expand Down
37 changes: 16 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ have been added during the compilation.
That is not the case for the library targeting .NET Standard 2.1, because the attributes are
available through the .NET BCL there.
This allows you to easily **multi-target** your projects without having to change a single line of
code.
code.

| .NET Standard 2.0 | .NET Standard 2.1 |
| ----------------- | ----------------- |
Expand All @@ -57,14 +57,10 @@ install the package for your target framework.

> :warning: **Important:** <br/>
> You **must** use C# 8.0 with the `Nullable` package - otherwise, your project won't compile.
>
> Currently, you can **not** use the package with a `packages.config` file.
> See [this issue](https://github.com/manuelroemer/Nullable/issues/1) for details. <br/>
> You may use [this guide](https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference)
> to see how you can upgrade from a `packages.config` to package references.

The steps below will only work with the **new SDK `.csproj`** style!
Other installation guides can be found [here](https://github.com/manuelroemer/Nullable/wiki).
The steps below assume that you are using the **new SDK `.csproj`** style.
Please find installation guides and notes for other project types (for example `packages.config`)
[here](https://github.com/manuelroemer/Nullable/wiki).

1. **Reference the package** <br/>
Add the package to your project, for example via:
Expand All @@ -84,6 +80,9 @@ Other installation guides can be found [here](https://github.com/manuelroemer/Nu
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<!-- This style also works, but is not automatically used by .NET: -->
<PackageReference Include="Nullable" Version="<YOUR_VERSION>" PrivateAssets="all" />
```

This is especially important for libraries that are published to NuGet, because without this,
Expand All @@ -97,7 +96,7 @@ Afterwards, you can immediately start using the attributes.

## Compiler Constants

The [included C# file](https://github.com/manuelroemer/Nullable/blob/master/src/Nullable/NullableAttributes.cs)
The [included C# file](https://github.com/manuelroemer/Nullable/blob/master/src/Nullable.ExcludeFromCodeCoverage/NullableAttributes.cs)
makes use of some compiler constants that can be used to enable or disable certain features.

### `NULLABLE_ATTRIBUTES_DISABLE`
Expand All @@ -109,20 +108,16 @@ In most cases, this should not be required, because the package automatically ex
from target frameworks that already support these attributes.


### `NULLABLE_ATTRIBUTES_EXCLUDE_FROM_CODE_COVERAGE`

Because the attributes are added as source code, they may appear in code coverage reports.
### `NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE`

By defining the `NULLABLE_ATTRIBUTES_EXCLUDE_FROM_CODE_COVERAGE` constant, the
[`ExcludeFromCodeCoverage`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=netcore-3.0)
attribute gets added to the nullable attribute classes, thus preventing them from appearing in
the reports.
Because the attributes are added as source code, they could appear in code coverage reports.
By default, this is disabled via the [`ExcludeFromCodeCoverage`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=netcore-3.0)
and [`DebuggerNonUserCode`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggernonusercodeattribute?view=netcore-3.0)
attributes.

> :warning: **Important:** <br/>
> This is disabled by default, because certain target frameworks like .NET Standard 1.7 don't
> support the [`ExcludeFromCodeCoverage`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=netcore-3.0)
> attribute.
> Ensure that this attribute is supported by your target framework before defining this constant.
By defining the `NULLABLE_ATTRIBUTES_INCLUDE_IN_CODE_COVERAGE` constant, the [`ExcludeFromCodeCoverage`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.excludefromcodecoverageattribute?view=netcore-3.0)
and [`DebuggerNonUserCode`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggernonusercodeattribute?view=netcore-3.0)
attributes are not applied and the nullable attributes may therefore appear in code coverage reports.


## Building
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -8,8 +8,4 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" PrivateAssets="all" />
</ItemGroup>

</Project>
Loading