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

HAST-327: New instructions about nested Directory.Build.props usage #94

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions Lombiq.Analyzers/Docs/AddingAnalyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ You only need to reference a single project; e.g., even though Orchard Core apps
If you don't want to stay on the cutting-edge version, nor do you intend to contribute to Lombiq .NET Analyzers, you can use one of the NuGet packages. Install the package suitable for your project, as described above. Check for the latest version number [on NuGet](https://www.nuget.org/packages/Lombiq.Analyzers/).

```csproj
<PackageReference Include="Lombiq.Analyzers" Version="<latest version>">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Lombiq.Analyzers" Version="<latest version>">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
```

The `<PrivateAssets>all</PrivateAssets>` is necessary to prevent the analyzers "leaking" into other projects that may consume yours.
Expand Down
12 changes: 12 additions & 0 deletions Lombiq.Analyzers/Docs/ConfiguringAnalyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ This will completely disable code analysis packages. To also disable .NET SDK an
dotnet_analyzer_diagnostic.category-Style.severity = none
```

Note that MSBuild only loads in the closest _Directory.Build.props_ file to the project being built. So if you also used a _Directory.Build.props_ file to enable _Lombiq.Analyzers_ in a higher directory, it is now overridden. This can be a problem if you rely on `Lombiq.Analyzers` to set up compiler properties such as `<LangVersion>`. Put this into the _Directory.Build.props_ file instead:
Piedone marked this conversation as resolved.
Show resolved Hide resolved

```xml
<Project>
<PropertyGroup>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
</Project>
```

## How to disable all analyzers during `dotnet build`

By default the `dotnet build` command runs analyzers and produces code analysis warnings if there are any but it makes the build slower. Pass the `/p:RunCodeAnalysis=false` parameter to disable analyzers during build, like:
Expand Down