Skip to content

Commit

Permalink
Merge pull request #16 from allegro/feature/v2-net8-support
Browse files Browse the repository at this point in the history
feat: refactor Sdk, make compatible with .NET 8 and CPM
  • Loading branch information
amis92 authored Jan 9, 2024
2 parents eb0ee08 + dfe4349 commit 2f9280b
Show file tree
Hide file tree
Showing 42 changed files with 935 additions and 218 deletions.
392 changes: 392 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.idea/
.ionide/
App_Data/
artifacts/
packages/
package/
obj/
bin/
build/
Expand Down
8 changes: 8 additions & 0 deletions Allegro.DotnetSdk.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{840CB7AA-881D-4626-9D81-29704148DC78}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Allegro.DotnetSdk", "src\Allegro.DotnetSdk\Allegro.DotnetSdk.csproj", "{655AEDF1-B3C4-4F74-9232-AA89FF07D598}"
Expand All @@ -12,18 +13,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Allegro.DotnetSdk.Tests", "src\Allegro.DotnetSdk.Tests\Allegro.DotnetSdk.Tests.csproj", "{DD3156B2-4B95-41D5-9215-18CFA226F538}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{655AEDF1-B3C4-4F74-9232-AA89FF07D598} = {840CB7AA-881D-4626-9D81-29704148DC78}
{DD3156B2-4B95-41D5-9215-18CFA226F538} = {840CB7AA-881D-4626-9D81-29704148DC78}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{655AEDF1-B3C4-4F74-9232-AA89FF07D598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{655AEDF1-B3C4-4F74-9232-AA89FF07D598}.Debug|Any CPU.Build.0 = Debug|Any CPU
{655AEDF1-B3C4-4F74-9232-AA89FF07D598}.Release|Any CPU.ActiveCfg = Release|Any CPU
{655AEDF1-B3C4-4F74-9232-AA89FF07D598}.Release|Any CPU.Build.0 = Release|Any CPU
{DD3156B2-4B95-41D5-9215-18CFA226F538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD3156B2-4B95-41D5-9215-18CFA226F538}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD3156B2-4B95-41D5-9215-18CFA226F538}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD3156B2-4B95-41D5-9215-18CFA226F538}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
50 changes: 17 additions & 33 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
<Project>

<PropertyGroup Label="Target Platforms" >
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Label="NuGet Properties">
<Authors>Allegro</Authors>
<Company>Allegro</Company>
<Copyright>© Allegro. All rights reserved.</Copyright>
<Description>$(MSBuildProjectName)</Description>
<Tags>Allegro</Tags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>

<PropertyGroup Label="Project Settings" >
<Platforms>AnyCPU</Platforms>
<TargetPlatform>AnyCPU</TargetPlatform>
<ErrorReport>prompt</ErrorReport>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
<NoWarn>$(NoWarn);NU5128;SA0001</NoWarn>
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)$(PackageReadmeFile)" Pack="true" PackagePath="" />
<None Include="$(MSBuildThisFileDirectory)$(PackageLicenseFile)" Pack="true" PackagePath="" />
<!-- <None Include="$(MSBuildThisFileDirectory)$(PackageIconPath)" Pack="true" PackagePath="" Visible="false" /> -->
<!-- <None Include="$(MSBuildThisFileDirectory)CHANGELOG.md" Pack="true" PackagePath=""/> -->
</ItemGroup>

<PropertyGroup Label="Build Output" >
<BaseOutputPath>$(MSBuildThisFileDirectory)\bin\$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<PackageOutputPath>$(MSBuildThisFileDirectory)\nuget</PackageOutputPath>
<DocumentationFileValue>$(MSBuildThisFileDirectory)\bin\$(MSBuildProjectName)\$(Configuration)\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFileValue>
</PropertyGroup>

<PropertyGroup Label="NuGet Properties">
<Authors>Allegro</Authors>
<Company>Allegro</Company>
<Copyright>© Allegro. All rights reserved.</Copyright>
<Description>$(MSBuildProjectName)</Description>
<Tags>Allegro</Tags>
</PropertyGroup>

</Project>
12 changes: 1 addition & 11 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<Project>
<Sdk Name="Microsoft.Build.CentralPackageVersions" />

<ItemGroup Condition="'$(IsPackable)' == 'true'">
<None Include="Sdk\**"
Pack="true"
PackagePath="Sdk\" />
<None Include="$(PackageIconPath)"
Pack="true"
PackagePath="\"
Visible="false" />
</ItemGroup>
<!-- Empty file prevents accidental inclusion of files from directories above -->
</Project>
21 changes: 21 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>
<PropertyGroup>
<!-- Enable central package management with transient pinning -->
<!-- https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.6.5" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
</ItemGroup>
</Project>
73 changes: 35 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

The Allegro .NET SDK provides common and importable project settings, such as build properties, coding styles, analyzers configuration etc.

The SDK is versioned and published on nuget It can be imported into dotnet projects.
The SDK is versioned and published on nuget. It can be imported into dotnet projects.

## Using the SDK

The SDK is meant to be easily importable - only a few initial config lines are required to bring its benefits. The SDK also makes it possible to override any of its default settings.
The SDK is meant to be easily importable - only a few initial config lines are required to bring its benefits. The SDK also makes it possible to override any of its default settings. Version 2+ will work only with .NET SDK v8+.

## Importing

Expand All @@ -27,18 +27,19 @@ It's necessary to include `Allegro.DotnetSdk` with the desired version in `globa
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"Allegro.DotnetSdk": "1.2.0"
"Allegro.DotnetSdk": "2.0.0"
}
}

```

### Directory.Build.props

The `Directory.Build.props` file should be updated in order to actually import the SDK:

```xml
<Project>
<Import Project="Sdk.props" Sdk="Allegro.DotnetSdk" />
<Sdk Name="Allegro.DotnetSdk" />
<PropertyGroup>
<TargetFramework>$(NetCoreVersions)</TargetFramework>
</PropertyGroup>
Expand All @@ -47,60 +48,53 @@ The `Directory.Build.props` file should be updated in order to actually import t
</Project>
```

### Directory.Build.targets

The `Directory.Build.targets` file should be updated in order to actually import the SDK:

```xml
<Project>
<Import Project="Sdk.targets" Sdk="Allegro.DotnetSdk"/>

<!-- other project-specific properties -->
</Project>
```

### Analyzers
## Project settings

The SDK imports and configures several external analyzers - StyleCop, AsyncFixer, Meziantou.
Most properties are only set in the SDK if not configured by the project.

The existing analyzer package reference sections should be removed from `paket.dependencies` and `paket.references`. If they're not removed, the build may fail because of duplicated package references.
To configure the SDK, the following properties can be added into `Directory.Build.props` or `.*proj` files:

## Overriding
- `AllegroDotnetSdkEnableXmlDocAdjustments` (default: true) - enable doc file generation, suppress missing-comments warning (1591) - completely in test projects, as errors otherwise (keep as warning).
- `AllegroDotnetSdkTreatWarningsAsErrors` (default: true in CI and Rider IDE) - to enable in local shell or other IDEs, just set your own user environment variable `TreatWarningsAsErrors=true`.
- `AllegroDotnetSdkEnableGlobalEditorConfig` (default: true) - add `editorconfig.global` analyzer configuration file.
- `AllegroDotnetSdkEnablePackAdjustments` (default: true) - sets PublishRepositoryUrl and enables `.snupkg` symbols.
- `AllegroDotnetSdkEnableAzureArtifactsAdjustments` (default: false) - disables `.snupkg` and instead embeds PDBs in `.nupkg`.

The imported properties can be overridden per repo or per project.
For `C#` only:

## Project settings
- `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 and a preset `stylecop.json`.

In order to override or disable some of the imported components, the behavior changing properties can be added into `Directory.Build.props` or `.csproj` files.
Configure in `Directory.Build.props` - repo wide:

* `Directory.Build.props` - repo wide:
```xml
<Project>
<Import Project="Sdk.props" Sdk="Allegro.DotnetSdk" />
<PropertyGroup>
<TargetFramework>$(NetCoreVersions)</TargetFramework>
</PropertyGroup>

<Sdk Name="Allegro.DotnetSdk" />

<PropertyGroup>
<!-- The line below disables nullable reference types -->
<nullable>disable</nullable>
<!-- The line below disables the StyleCop config -->
<Nullable>disable</Nullable>
<!-- The line below disables the StyleCop -->
<AllegroDotnetSdkEnableStyleCop>false</AllegroDotnetSdkEnableStyleCop>
</PropertyGroup>

<!-- other repo-specific properties -->

</Project>
```

* `.csproj` - project settings:
Configure in `*.csproj` - project settings:

```xml
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- The line below disables implicit usings adjustments -->
<AllegroDotnetSdkEnableImplicitUsingsAdjustments>false</AllegroDotnetSdkEnableImplicitUsingsAdjustments>
</PropertyGroup>

<!-- other project-specific properties -->
</Project>
```

Expand All @@ -117,6 +111,7 @@ More about the analyzer and editor config files can be found in [the docs](https
### Rider

Make sure you have enabled:

- Preferences -> Editor -> Code Style -> Enable StyleCop support (Ruleset files)
- Preferences -> Editor -> Code Style -> Enable EditorConfig support
- Preferences -> Editor -> Inspection Settings -> Read settings from editorconfig, project settings and rule sets
Expand All @@ -125,9 +120,11 @@ Make sure you have enabled:

**Be aware!**
Only some analyzers's warnings can be addressed by auto-format or code cleanup. Some of the warnings are not covered by Rider, and its settings need to be adjusted.
For that, in editor.globalconfig is `# ReSharper properties` section with some already defined settings which align with analyzers. If you find some inconsistency and you find appropriate settings in Rider, which will fix it - please, contribute! :)
For that, in editor.globalconfig is `# ReSharper properties` section with some already defined settings which align with analyzers. If you find some inconsistency and you find appropriate settings in Rider, which will fix it - please, contribute! :)

## License
Copyright 2022 Allegro Group

Copyright Allegro Group

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

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"
}
}
7 changes: 4 additions & 3 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
30 changes: 30 additions & 0 deletions src/Allegro.DotnetSdk.Tests/Allegro.DotnetSdk.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<DefaultItemExcludes>$(DefaultItemExcludes);projects/**</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
Loading

0 comments on commit 2f9280b

Please sign in to comment.