RobinJiangdh
8/22/2017 - 3:28 PM

cake demo for msbuild,sonarQube,Xunit2

cake demo for msbuild,sonarQube,Xunit2

#tool nuget:?package=MSBuild.SonarQube.Runner.Tool
#addin nuget:?package=Cake.Sonar

//定义目录
var buildDir ="artifacts";
var nugetDir="packages";
var testResultsDir="TestResults";
var target = Argument("target", "Default");
var projects = GetFiles("./**/**/*.csproj");
// TASKS
Task("Clean")
    .Does(() =>{
        CleanDirectory(buildDir);
        CleanDirectory(nugetDir);
        CleanDirectory(testResultsDir);

        foreach(var project in projects)
        {
            CleanDirectory(project.GetDirectory().ToString()+"\\bin");
        }
        
});

Task("Restore-NuGet-Packages")
 .IsDependentOn("Clean")
    .Does(() =>
{
    NuGetRestore("McRobin.sln");
});

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .Does(() =>
{
      MSBuild("McRobin.sln", settings =>
        settings.SetConfiguration("Release"));

});

Task("UnitTest")
.IsDependentOn("Build")
.Does(()=>{ 
    var testDlls = GetFiles("./**/**/bin/**/*Tests.dll");
	foreach(var testdll in testDlls)
	{ 
         XUnit2(testdll.ToString(),new XUnit2Settings {
         NUnitReport=true,
         OutputDirectory=testResultsDir,
         ReportName=testdll.GetFilename().ToString().Replace(".dll","_TestResult"),
     });
	}
	
});

Task("SonarBegin")
  .Does(() => {
     SonarBegin(new SonarBeginSettings{
         Url="http://localhost:9000",
        Key = "org.sonarqube:McRobin:master",
        Name="McRobin",
        Version="v2.1",
        Login = "admin",
        Password = "admin",
        Verbose = true
     });
  });

Task("SonarEnd")
  .Does(() => {
     SonarEnd(new SonarEndSettings{
        Login = "admin",
        Password = "admin"
     });
  });

// TASK TARGETS

Task("Default")
  .IsDependentOn("SonarBegin")
  .IsDependentOn("UnitTest")
  .IsDependentOn("Build") 
  .IsDependentOn("SonarEnd");

// EXECUTION

RunTarget(target);