Common MSBuild extensions for all C# projects at Bottlenose Labs.
-
Create
Directory.Build.propsfile above the directory of your C# projects.- Set
UseArtifactsOutputtotruein a property group. This will cause allbinandobjfolders to be placed under theartifactsdirectory at the root of the Git repository. To change this directory setArtifactsPath. - Set
ArtifactsPathto a directory where thebin/ProjectNameandobj/ProjectNamefolders will be generated. - Add
bottlenoselabs.MSBuild.ExtensionsNuGet 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
.globalconfigfile 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