Skip to content

Commit

Permalink
Preparation for .NET 5 attributes (MemberNotNull, MemberNotNullWhen) …
Browse files Browse the repository at this point in the history
…and revamp of the project and how it is built.
  • Loading branch information
manuelroemer committed Sep 15, 2020
1 parent a39a33c commit 1d115f4
Show file tree
Hide file tree
Showing 22 changed files with 1,208 additions and 730 deletions.
1 change: 1 addition & 0 deletions .nuke
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Nullable.sln
31 changes: 0 additions & 31 deletions build.ps1

This file was deleted.

11 changes: 11 additions & 0 deletions build/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*.cs]
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
dotnet_style_require_accessibility_modifiers = never:warning

csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
99 changes: 99 additions & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.NuGet.NuGetTasks;

[CheckBuildProjectConfigurations]
[UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild
{
public static int Main () => Execute<Build>(x => x.Pack);

[Solution] readonly Solution Solution;

Project NullableProject => Solution.GetProject("Nullable");

IEnumerable<FileInfo> AttributeFiles => Directory
.GetFiles(NullableProject.Directory, "*Attribute.cs", SearchOption.AllDirectories)
.Select(path => new FileInfo(path));

FileInfo NuspecFile => new FileInfo(RootDirectory / "src" / "Nullable.nuspec");

DirectoryInfo ArtifactsDirectory => new DirectoryInfo(RootDirectory / "artifacts");

DirectoryInfo OutDirectory => new DirectoryInfo(TemporaryDirectory / "out");

DirectoryInfo ExcludeFromCodeCoverageOutDirectory => new DirectoryInfo(TemporaryDirectory / "out" / "ExcludeFromCodeCoverage");

DirectoryInfo NoExcludeFromCodeCoverageOutDirectory => new DirectoryInfo(TemporaryDirectory / "out" / "NoExcludeFromCodeCoverage");

Target Clean => _ => _
.Executes(() =>
{
DeleteDirectory(ArtifactsDirectory.FullName);
DeleteDirectory(ExcludeFromCodeCoverageOutDirectory.FullName);
DeleteDirectory(NoExcludeFromCodeCoverageOutDirectory.FullName);
});

Target Compile => _ => _
.Executes(() =>
{
// We build once to verify that the sources don't contain errors.
// Has no function apart from that since the build output is not used.
DotNetBuild(s => s
.SetProjectFile(NullableProject.Path)
.SetIgnoreFailedSources(true));
});

Target CreateOutFiles => _ => _
.DependsOn(Clean)
.DependsOn(Compile)
.Executes(() =>
{
// Nullable uses the [ExcludeFromCodeCoverage] attribute.
// This is not available in certain target frameworks (e.g. .NET 2.0 and .NET Standard 1.0).
// For this reason, we remove that attribute from the source code.
// This results in two different file versions. These are temporarily stored in the output directories
// and then used by the nuspec accordingly.
ExcludeFromCodeCoverageOutDirectory.Create();
NoExcludeFromCodeCoverageOutDirectory.Create();

foreach (var attributeFile in AttributeFiles)
{
attributeFile.CopyTo(Path.Combine(ExcludeFromCodeCoverageOutDirectory.FullName, attributeFile.Name));
attributeFile.CopyTo(Path.Combine(NoExcludeFromCodeCoverageOutDirectory.FullName, attributeFile.Name));
}

foreach (var noExcludeFromCodeCoverageFile in NoExcludeFromCodeCoverageOutDirectory.GetFiles())
{
var content = File.ReadAllText(noExcludeFromCodeCoverageFile.FullName);
content = content.Replace("ExcludeFromCodeCoverage, ", "");
File.WriteAllText(noExcludeFromCodeCoverageFile.FullName, content);
}

// Renaming the .cs files to .cs.pp ensures that the files aren't listed in VS's solution explorer
// when the package is consumed via NuGet. With .cs files, that happens.
foreach (var csFile in OutDirectory.GetFiles("*.cs", SearchOption.AllDirectories))
{
csFile.MoveTo($"{csFile.FullName}.pp");
}
});

Target Pack => _ => _
.DependsOn(CreateOutFiles)
.Executes(() =>
{
NuGetPack(s => s
.SetTargetPath(NuspecFile.FullName)
.SetBasePath(OutDirectory.FullName)
.SetOutputDirectory(ArtifactsDirectory.FullName));
});
}
20 changes: 20 additions & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..\src</NukeScriptDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NuGet.CommandLine" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nuke.Common" Version="0.24.11" />
</ItemGroup>

</Project>
Loading

0 comments on commit 1d115f4

Please sign in to comment.