-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparation for .NET 5 attributes (MemberNotNull, MemberNotNullWhen) …
…and revamp of the project and how it is built.
- Loading branch information
1 parent
a39a33c
commit 1d115f4
Showing
22 changed files
with
1,208 additions
and
730 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/Nullable.sln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.