Common MSBuild extensions for all C# projects at Bottlenose Labs.
-
Create
Directory.Build.props
file above the directory of your C# projects.- Set
UseArtifactsOutput
totrue
in a property group. This will cause allbin
andobj
folders to be placed under theartifacts
directory at the root of the Git repository. To change this directory setArtifactsPath
. - Set
ArtifactsPath
to a directory where thebin/ProjectName
andobj/ProjectName
folders will be generated. - Add
bottlenoselabs.MSBuild.Extensions
NuGet package with wildcard version.
- Set
<Project>
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput> <!-- Only available in .NET 8 -->
<ArtifactsPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), .gitignore))/artifacts</ArtifactsPath> <!-- Only available in .NET 8 -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="bottlenoselabs.MSBuild.Extensions" Version="*">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
- Create a
.globalconfig
file to configure C# Roslyn analyzers:
# NOTE: Requires .NET 5 SDK (VS2019 16.8 or later)
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig
is_global = true
# StyleCop Rules
# Description: StyleCop code analysis rules for C# projects.
dotnet_diagnostic.SA1309.severity = error