Skip to content

Commit

Permalink
refactor: split into common and csharp-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
amis92 committed Jan 4, 2024
1 parent 98a618a commit 93c23d7
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 103 deletions.
1 change: 1 addition & 0 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
with:
dotnet-version: |
6.0.x
8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
.ionide/
App_Data/
artifacts/
packages/
package/
obj/
Expand Down
5 changes: 1 addition & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,8 +19,4 @@
<!-- <None Include="$(MSBuildThisFileDirectory)CHANGELOG.md" Pack="true" PackagePath=""/> -->
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>

</Project>
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ The `Directory.Build.props` file should be updated in order to actually import t

Most properties are only set in the SDK if not configured by the project.

To configure the SDK, the following properties can be added into `Directory.Build.props` or `.csproj` files:
To configure the SDK, the following properties can be added into `Directory.Build.props` or `.*proj` files:

- `AllegroDotnetSdkEnableXmlDocAdjustments` (default: true) - enable doc file generation, suppress missing-comments warning (1591) - completely in test projects, as errors otherwise (keep as warning).
- `TreatWarningsAsErrors` (default: true in CI and Rider IDE)
- `UseAllegroDotnetSdkDefaultAnalyzers` (default: true when no CPM) - reference and configure several external analyzers - StyleCop, AsyncFixer, Meziantou.
- `TreatWarningsAsErrors` (default: true in CI and Rider IDE).
- `AllegroDotnetSdkEnableGlobalEditorConfig` (default: true) - add `editorconfig.global` analyzer configuration file.
- `AllegroDotnetSdkEnableImplicitUsingsAdjustments` (default: true) - add `System.Collections.Immutable` and remove `Microsoft.Extensions.Logging` and `System.Net.Http` implicit usings.
- `AllegroDotnetSdkEnablePackAdjustments` (default: true) - sets PublishRepositoryUrl and enables `.snupkg` symbols.
- `AllegroDotnetSdkEnableAzureArtifactsAdjustments` (default: false) - disables `.snupkg` and instead embeds PDBs in `.nupkg`.

For `C#` only:

- `AllegroDotnetSdkEnableImplicitUsingsAdjustments` (default: true for C#) - add `System.Collections.Immutable` and remove `Microsoft.Extensions.Logging` and `System.Net.Http` implicit usings.
- `UseAllegroDotnetSdkDefaultAnalyzers` (default: true for C# when no CPM) - reference and configure several external analyzers - StyleCop, AsyncFixer, Meziantou.
- `AllegroDotnetSdkEnableAsyncFixer` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references AsyncFixer package.
- `AllegroDotnetSdkEnableMeziantou` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references Meziantou.Analyzers package.
- `AllegroDotnetSdkEnableStyleCop` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references StyleCop.Analyzers package.
- `AllegroDotnetSdkEnableStyleCop` (default: `UseAllegroDotnetSdkDefaultAnalyzers`) - references StyleCop.Analyzers package and a preset `stylecop.json`.

Configure in `Directory.Build.props` - repo wide:

Expand Down
5 changes: 2 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"sdk": {
"version": "6.0.400",
"version": "8.0.100",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"Microsoft.Build.CentralPackageVersions": "2.1.3",
"Microsoft.Build.NoTargets": "3.5.6"
"Microsoft.Build.NoTargets": "3.7.56"
}
}
6 changes: 3 additions & 3 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
27 changes: 27 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.CSharp.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project>
<!-- This file configures C#-specific options -->

<PropertyGroup>
<AllegroDotnetSdkEnableImplicitUsingsAdjustments Condition="'$(AllegroDotnetSdkEnableImplicitUsingsAdjustments)' == ''">true</AllegroDotnetSdkEnableImplicitUsingsAdjustments>
<Nullable Condition="'$(Nullable)' == ''">enable</Nullable>
<ImplicitUsings Condition="'$(AllegroDotnetSdkEnableImplicitUsingsAdjustments)' == 'true' And '$(ImplicitUsings)' == ''">enable</ImplicitUsings>
<AnalysisLevel Condition="'$(AnalysisLevel)' == ''">latest-Recommended</AnalysisLevel>
<EnforceCodeStyleInBuild Condition="'$(EnforceCodeStyleInBuild)' == ''">true</EnforceCodeStyleInBuild>
</PropertyGroup>

<!-- XML documentation adjustments -->
<PropertyGroup Condition="'$(AllegroDotnetSdkEnableXmlDocAdjustments)' == 'true'">
<!-- Never mark missing docs as errors -->
<!-- CS1591: Missing XML comment for publicly visible type or member -->
<WarningsNotAsErrors Condition="'$(GenerateDocumentationFile)' == 'true'">$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
</PropertyGroup>

<!-- Exclude selected warnings in test projects -->
<PropertyGroup Condition="$(MSBuildProjectName.Contains(`Tests`))">
<!-- CA1707: Identifiers should not contain underscores -->
<NoWarn>$(NoWarn);CA1707</NoWarn>
<!-- CS1591: Missing XML comment for publicly visible type or member -->
<NoWarn Condition="'$(GenerateDocumentationFile)' == 'true' And '$(AllegroDotnetSdkEnableXmlDocAdjustments)' == 'true'">$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

</Project>
30 changes: 30 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.CSharp.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project>

<!-- Setup this SDKs defaults -->
<PropertyGroup>
<!-- Enable default analyzers if CPM is not used. -->
<UseAllegroDotnetSdkDefaultAnalyzers Condition="'$(UseAllegroDotnetSdkDefaultAnalyzers)' == '' And '$(ManagePackageVersionsCentrally)' != 'true'">true</UseAllegroDotnetSdkDefaultAnalyzers>
</PropertyGroup>

<PropertyGroup Condition="'$(UseAllegroDotnetSdkDefaultAnalyzers)' == 'true'">
<AllegroDotnetSdkEnableAsyncFixer Condition="'$(AllegroDotnetSdkEnableAsyncFixer)' == ''">true</AllegroDotnetSdkEnableAsyncFixer>
<AllegroDotnetSdkEnableMeziantou Condition="'$(AllegroDotnetSdkEnableMeziantou)' == ''">true</AllegroDotnetSdkEnableMeziantou>
<AllegroDotnetSdkEnableStyleCop Condition="'$(AllegroDotnetSdkEnableStyleCop)' == ''">true</AllegroDotnetSdkEnableStyleCop>
</PropertyGroup>

<ItemGroup Condition="'$(AllegroDotnetSdkEnableStyleCop)' == 'true'">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup Label="ImplicitUsings adjustments" Condition="('$(ImplicitUsings)' == 'true' Or '$(ImplicitUsings)' == 'enable') And '$(AllegroDotnetSdkEnableImplicitUsingsAdjustments)' == 'true'">
<!-- Add Immutable as we often use them -->
<Using Include="System.Collections.Immutable" />
<!-- Remove Logging because it conflicts with Serilog which we use by default -->
<Using Remove="Microsoft.Extensions.Logging" />
<!-- Remove Http because we want to explicitly enforce devs to think twice before using System.Net.Http -->
<Using Remove="System.Net.Http" />
</ItemGroup>

<Import Project="Allegro.NET.Sdk.CSharp.Analyzers.targets" />

</Project>
25 changes: 25 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project>
<!-- This file configures language-independent options -->

<!-- Setup this SDKs defaults -->
<PropertyGroup>
<AllegroDotnetSdkEnableXmlDocAdjustments Condition="'$(AllegroDotnetSdkEnableXmlDocAdjustments)' == ''">true</AllegroDotnetSdkEnableXmlDocAdjustments>
</PropertyGroup>

<!-- Warnings as Errors -->
<PropertyGroup>
<!-- Some devs want Warnings as Errors in local IDE development -->
<TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == '' And '$(BuildingByReSharper)' == 'true'">true</TreatWarningsAsErrors>
<!-- Enable Warnings as Errors in CI -->
<TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == '' And '$(CI)' != ''">true</TreatWarningsAsErrors>
<!-- LEGACY: enable by default until people explicitly set their preferences -->
<TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == ''">true</TreatWarningsAsErrors>
</PropertyGroup>

<!-- XML documentation adjustments -->
<PropertyGroup Condition="'$(AllegroDotnetSdkEnableXmlDocAdjustments)' == 'true'">
<!-- Documentation can be disabled per-project -->
<GenerateDocumentationFile Condition="'$(GenerateDocumentationFile)' == ''">true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.Common.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project>

<!-- Setup this SDKs defaults -->
<PropertyGroup>
<AllegroDotnetSdkEnableGlobalEditorConfig Condition="'$(AllegroDotnetSdkEnableGlobalEditorConfig)' == ''">true</AllegroDotnetSdkEnableGlobalEditorConfig>
<AllegroDotnetSdkEnablePackAdjustments Condition="'$(AllegroDotnetSdkEnablePackAdjustments)' == ''">true</AllegroDotnetSdkEnablePackAdjustments>
<AllegroDotnetSdkEnableAzureArtifactsAdjustments Condition="'$(AllegroDotnetSdkEnableAzureArtifactsAdjustments)' == ''">false</AllegroDotnetSdkEnableAzureArtifactsAdjustments>
</PropertyGroup>

<!-- Configure nuget-packing for Library/Packable non-test projects -->
<PropertyGroup Condition="'$(AllegroDotnetSdkEnablePackAdjustments)' == 'true' And ('$(OutputType)' == 'Library' Or '$(IsPackable)' != 'false') And '$(IsTestProject)' != 'true'">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(AllegroDotnetSdkEnableAzureArtifactsAdjustments)' == 'true'">
<!-- Embed PDBs in .nupkg because Azure Artifacts doesn't support .snupkg yet -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>
$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
</AllowedOutputExtensionsInPackageBuildOutputFolder>
<IncludeSymbols>false</IncludeSymbols>
</PropertyGroup>

<ItemGroup Condition="'$(AllegroDotnetSdkEnableGlobalEditorConfig)' == 'true'">
<GlobalAnalyzerConfigFiles Include="$(MSBuildThisFileDirectory)editor.globalconfig" Link="editor.globalconfig" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>

<Import Project="Allegro.NET.Sdk.Common.props" />
<Import Project="Allegro.NET.Sdk.CSharp.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />

</Project>
6 changes: 6 additions & 0 deletions src/Allegro.DotnetSdk/Sdk/Allegro.NET.Sdk.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>

<Import Project="Allegro.NET.Sdk.Common.targets" />
<Import Project="Allegro.NET.Sdk.CSharp.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />

</Project>
4 changes: 2 additions & 2 deletions src/Allegro.DotnetSdk/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<!--
Import our custom props just after Directory.Build.props is imported, but before Microsoft.NET.Sdk.props
-->
<CustomAfterDirectoryBuildProps>$(CustomAfterDirectoryBuildProps);$(MSBuildThisFileDirectory)UseAllegroDotnetSdkDefaults.props</CustomAfterDirectoryBuildProps>
<CustomAfterDirectoryBuildProps>$(CustomAfterDirectoryBuildProps);$(MSBuildThisFileDirectory)Allegro.NET.Sdk.props</CustomAfterDirectoryBuildProps>
<!--
Import our custom targets after Directory.Build.targets is imported
-->
<CustomBeforeDirectoryBuildTargets>$(CustomBeforeDirectoryBuildTargets);$(MSBuildThisFileDirectory)UseAllegroDotnetSdkDefaults.targets</CustomBeforeDirectoryBuildTargets>
<CustomBeforeDirectoryBuildTargets>$(CustomBeforeDirectoryBuildTargets);$(MSBuildThisFileDirectory)Allegro.NET.Sdk.targets</CustomBeforeDirectoryBuildTargets>
</PropertyGroup>

<!--
Expand Down
41 changes: 0 additions & 41 deletions src/Allegro.DotnetSdk/Sdk/UseAllegroDotnetSdkDefaults.props

This file was deleted.

45 changes: 0 additions & 45 deletions src/Allegro.DotnetSdk/Sdk/UseAllegroDotnetSdkDefaults.targets

This file was deleted.

0 comments on commit 93c23d7

Please sign in to comment.