Skip to content

Commit

Permalink
New .csproj and preparations for a possible move to dotnet core, upda…
Browse files Browse the repository at this point in the history
…ted dependencies.

[release]
  • Loading branch information
Lakritzator committed Sep 28, 2018
1 parent 702e8d1 commit 51019aa
Show file tree
Hide file tree
Showing 25 changed files with 456 additions and 1,293 deletions.
11 changes: 2 additions & 9 deletions appveyor.yml
@@ -1,9 +1,8 @@
version: 0.3.{build}
version: 0.4.{build}
skip_tags: true
os: Visual Studio 2017
configuration: Release
platform: Any CPU
clone_depth: 2
test: off
branches:
only:
Expand All @@ -17,7 +16,7 @@ environment:
build_script:
- ps: .\build.ps1 --settings_skipverification=true
artifacts:
- path: artifacts\**\*.nupkg
- path: src\**\*.nupkg
- path: artifacts\**\site.zip
- path: artifacts\*.xml
- path: artifacts\*.html
Expand All @@ -28,9 +27,3 @@ notifications:
on_build_success: true
on_build_failure: true
on_build_status_changed: false
- provider: GitHubPullRequest
auth_token:
secure: YDFCm4fj2pYoTR+QCKcR1Q==
on_build_success: true
on_build_failure: true
on_build_status_changed: true
314 changes: 102 additions & 212 deletions build.cake
@@ -1,10 +1,7 @@
#tool "xunit.runner.console"
#tool "OpenCover"
#tool "GitVersion.CommandLine"
#tool "docfx.console"
//#tool "coveralls.net"
#tool nuget:?package=coveralls.net&version=0.7.0
#tool "PdbGit"
#tool "coveralls.io"
#addin "Cake.DocFx"
#addin "Cake.Coveralls"

Expand All @@ -27,244 +24,137 @@ var isPullRequest = !string.IsNullOrEmpty(EnvironmentVariable("APPVEYOR_PULL_REQ
// Check if the commit is marked as release
var isRelease = Argument<bool>("isRelease", string.Compare("[release]", EnvironmentVariable("appveyor_repo_commit_message_extended"), true) == 0);

// Used to store the version, which is needed during the build and the packaging
var version = EnvironmentVariable("APPVEYOR_BUILD_VERSION") ?? "1.0.0";
var branch = EnvironmentVariable("APPVEYOR_REPO_BRANCH");
Task("Default")
.IsDependentOn("Publish");
.IsDependentOn("Publish");

// Publish the Artifact of the Package Task to the Nexus Pro
// Publish taks depends on publish specifics
Task("Publish")
.IsDependentOn("CreateAndUploadCoverageReport")
.IsDependentOn("PublishPackages")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => !string.IsNullOrEmpty(nugetApiKey))
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRelease)
.Does(()=>
.IsDependentOn("PublishPackages")
.IsDependentOn("PublishCoverage")
.IsDependentOn("Documentation")
.WithCriteria(() => !BuildSystem.IsLocalBuild);

// Publish the coveralls report to Coveralls.io
Task("PublishCoverage")
.IsDependentOn("Coverage")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => !string.IsNullOrEmpty(coverallsRepoToken))
.WithCriteria(() => !isPullRequest)
.Does(()=>
{
CoverallsIo("./artifacts/coverage.xml", new CoverallsIoSettings
{
RepoToken = coverallsRepoToken
});
});

// Publish the Artifacts of the Package Task to NuGet
Task("PublishPackages")
.IsDependentOn("Package")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => !string.IsNullOrEmpty(nugetApiKey))
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRelease)
.Does(()=>
.IsDependentOn("Coverage")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => !string.IsNullOrEmpty(nugetApiKey))
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRelease)
.Does(()=>
{
var settings = new NuGetPushSettings {
Source = "https://www.nuget.org/api/v2/package",
ApiKey = nugetApiKey
};
var settings = new NuGetPushSettings {
Source = "https://www.nuget.org/api/v2/package",
ApiKey = nugetApiKey
};
var packages = GetFiles("./artifacts/*.nupkg").Where(p => !p.FullPath.ToLower().Contains("symbols"));
NuGetPush(packages, settings);
});
// Package the results of the build, if the tests worked, into a NuGet Package
Task("Package")
.IsDependentOn("Coverage")
.IsDependentOn("Documentation")
.IsDependentOn("GitLink")
.Does(()=>
{
var settings = new NuGetPackSettings
{
OutputDirectory = "./artifacts/",
Verbosity = NuGetVerbosity.Detailed,
Symbols = true,
IncludeReferencedProjects = true,
Properties = new Dictionary<string, string>
{
{ "Configuration", configuration },
{ "Platform", "AnyCPU" }
}
};
var projectFilePaths = GetFiles("./**/*.csproj")
.Where(p => !p.FullPath.ToLower().Contains("test"))
.Where(p => !p.FullPath.ToLower().Contains("packages"))
.Where(p => !p.FullPath.ToLower().Contains("tools"))
.Where(p => !p.FullPath.ToLower().Contains("demo"))
.Where(p => !p.FullPath.ToLower().Contains("diagnostics"))
.Where(p => !p.FullPath.ToLower().Contains("power"))
.Where(p => !p.FullPath.ToLower().Contains("example"));
foreach(var projectFilePath in projectFilePaths)
{
Information("Packaging: " + projectFilePath.FullPath);
NuGetPack(projectFilePath.FullPath, settings);
}
var packages = GetFiles("./src/**/*.nupkg").Where(p => !p.FullPath.ToLower().Contains("symbols"));
NuGetPush(packages, settings);
});

// Build the DocFX documentation site
Task("Documentation")
.Does(() =>
{
DocFxMetadata("./doc/docfx.json");
DocFxBuild("./doc/docfx.json");
CreateDirectory("artifacts");
// Archive the generated site
Zip("./doc/_site", "./artifacts/site.zip");
});

Task("CreateAndUploadCoverageReport")
.IsDependentOn("Coverage")
.WithCriteria(() => !string.IsNullOrEmpty(coverallsRepoToken))
.IsDependentOn("UploadCoverageReport")
.Does(() =>
.Does(() =>
{
});

Task("UploadCoverageReport")
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => FileExists("./artifacts/coverage.xml"))
.WithCriteria(() => !string.IsNullOrEmpty(coverallsRepoToken))
.Does(() =>
{
CoverallsNet("./artifacts/coverage.xml", CoverallsNetReportType.OpenCover, new CoverallsNetSettings
{
RepoToken = coverallsRepoToken
});
// Run DocFX
DocFxMetadata("./doc/docfx.json");
DocFxBuild("./doc/docfx.json");
CreateDirectory("artifacts");
// Archive the generated site
Zip("./doc/_site", "./artifacts/site.zip");
});

// Run the XUnit tests via OpenCover, so be get an coverage.xml report
Task("Coverage")
.IsDependentOn("Build")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => GetFiles("./**/*.csproj").Where(csprojFile => csprojFile.FullPath.Contains("Test")).Any())
.Does(() =>
{
CreateDirectory("artifacts");
var openCoverSettings = new OpenCoverSettings() {
// Forces error in build when tests fail
ReturnTargetCodeOffset = 0
};
var projectFiles = GetFiles("./**/*.csproj");
foreach(var projectFile in projectFiles)
{
var projectName = projectFile.GetDirectory().GetDirectoryName();
if (projectName.Contains("Test")) {
openCoverSettings.WithFilter("-["+projectName+"]*");
}
else {
openCoverSettings.WithFilter("+["+projectName+"]*");
}
}
// Make XUnit 2 run via the OpenCover process
OpenCover(
// The test tool Lamdba
tool => {
tool.XUnit2("./**/*.Tests.dll",
new XUnit2Settings {
// Add AppVeyor output, this "should" take care of a report inside AppVeyor
ArgumentCustomization = args => {
if (!BuildSystem.IsLocalBuild) {
args.Append("-appveyor");
}
return args;
},
ShadowCopy = false,
XmlReport = true,
HtmlReport = true,
ReportName = solutionName,
OutputDirectory = "./artifacts",
WorkingDirectory = "./src"
});
},
// The output path
new FilePath("./artifacts/coverage.xml"),
// Settings
openCoverSettings
);
});

// This starts the actual MSBuild
Task("Build")
.IsDependentOn("RestoreNuGetPackages")
.IsDependentOn("Clean")
.IsDependentOn("AssemblyVersion")
.Does(() =>
{
var settings = new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.VS2017,
Configuration = configuration,
PlatformTarget = PlatformTarget.MSIL
};
MSBuild(solutionFilePath.FullPath, settings);
// Make sure the .dlls in the obj path are not found elsewhere
CleanDirectories("./**/obj");
});

// Generate Git links in the PDB files
Task("GitLink")
.IsDependentOn("Build")
.Does(() =>
.IsDependentOn("Build")
.Does(() =>
{
FilePath pdbGitPath = Context.Tools.Resolve("PdbGit.exe");
var pdbFiles = GetFiles("./**/*.pdb")
.Where(p => !p.FullPath.ToLower().Contains("test"))
.Where(p => !p.FullPath.ToLower().Contains("tools"))
CreateDirectory("artifacts");
var openCoverSettings = new OpenCoverSettings() {
// Forces error in build when tests fail
ReturnTargetCodeOffset = 0
};
var projectFilePaths = GetFiles("./**/*.csproj")
.Where(p => !p.FullPath.ToLower().Contains("demo"))
.Where(p => !p.FullPath.ToLower().Contains("packages"))
.Where(p => !p.FullPath.ToLower().Contains("tools"))
.Where(p => !p.FullPath.ToLower().Contains("example"));
foreach(var pdbFile in pdbFiles)
{
Information("Processing: " + pdbFile.FullPath);
StartProcess(pdbGitPath, new ProcessSettings { Arguments = new ProcessArgumentBuilder().Append(pdbFile.FullPath)});
foreach(var projectFile in projectFilePaths)
{
var projectName = projectFile.GetDirectory().GetDirectoryName();
if (projectName.ToLower().Contains("test")) {
openCoverSettings.WithFilter("-["+projectName+"]*");
}
else {
openCoverSettings.WithFilter("+["+projectName+"]*");
}
}
var xunit2Settings = new XUnit2Settings {
// Add AppVeyor output, this "should" take care of a report inside AppVeyor
ArgumentCustomization = args => {
if (!BuildSystem.IsLocalBuild) {
args.Append("-appveyor");
}
return args;
},
ShadowCopy = false,
XmlReport = true,
HtmlReport = true,
ReportName = solutionName,
OutputDirectory = "./artifacts",
WorkingDirectory = "./src"
};
// Make XUnit 2 run via the OpenCover process
OpenCover(
// The test tool Lamdba
tool => tool.XUnit2("./**/bin/**/*.Tests.dll", xunit2Settings),
// The output path
new FilePath("./artifacts/coverage.xml"),
// Settings
openCoverSettings
);
});

// Load the needed NuGet packages to make the build work
Task("RestoreNuGetPackages")
.Does(() =>
{
NuGetRestore(solutionFilePath.FullPath);
});

// Version is written to the AssemblyInfo files when !BuildSystem.IsLocalBuild
Task("AssemblyVersion")
.Does(() =>
// This starts the actual MSBuild
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
foreach(var assemblyInfoFile in GetFiles("./**/AssemblyInfo.cs").Where(p => p.FullPath.Contains(solutionName))) {
var assemblyInfo = ParseAssemblyInfo(assemblyInfoFile.FullPath);
CreateAssemblyInfo(assemblyInfoFile.FullPath, new AssemblyInfoSettings {
Version = version,
InformationalVersion = version + (branch == "master" ? "" : "-beta"),
FileVersion = version,
CLSCompliant = assemblyInfo.ClsCompliant,
Company = assemblyInfo.Company,
ComVisible = assemblyInfo.ComVisible,
Configuration = assemblyInfo.Configuration,
Copyright = assemblyInfo.Copyright,
//CustomAttributes = assemblyInfo.CustomAttributes,
Description = assemblyInfo.Description,
//Guid = assemblyInfo.Guid,
InternalsVisibleTo = assemblyInfo.InternalsVisibleTo,
Product = assemblyInfo.Product,
Title = assemblyInfo.Title,
Trademark = assemblyInfo.Trademark
});
}
MSBuild(solutionFilePath.FullPath, new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.VS2017,
Configuration = "Release",
Restore = true,
PlatformTarget = PlatformTarget.MSIL
});
});


// Clean all unneeded files, so we build on a clean file system
Task("Clean")
.Does(() =>
.Does(() =>
{
CleanDirectories("./**/obj");
CleanDirectories("./**/bin");
CleanDirectories("./artifacts");
CleanDirectories("./**/obj");
CleanDirectories("./**/bin");
CleanDirectories("./artifacts");
});

RunTarget(target);

0 comments on commit 51019aa

Please sign in to comment.