在蛋糕糖霜 Cake.Sonar 中出现错误
Getting errors in Cake.Sonar on Cake Frosting
我正在尝试使用糖霜蛋糕项目中的 sonarqube。
有我的任务:
using Cake.Common;
using Cake.Common.IO;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Build;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Docker;
using Cake.Frosting;
using Cake.Git;
using Cake.SemVer;
using Cake.Sonar;
using System.Linq;
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}
public class BuildContext : FrostingContext
{
public string MsBuildConfiguration { get; set; }
public string ProjectPath { get; set; }
public string SolutionFile { get; set; }
public string SolutionName { get; set; }
// For SonarQube
public string SonarKey { get; set; }
public string SonarUrl { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Verbose { get; set; }
public BuildContext(ICakeContext context)
: base(context)
{
ProjectPath = context.Argument("projectPath", @"C:\Users\User\source\repos\ConsoleApp1");
MsBuildConfiguration = context.Argument("configuration", "Release");
SolutionFile = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilename().ToString();
SolutionName = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilenameWithoutExtension().ToString();
SonarKey = context.Argument("SonarKey", "MyProject");
SonarUrl = context.Argument("SonarUrl", "http://localhost:9000/");
Login = context.Argument("Login", "admin");
Password = context.Argument("Password", "admin");
}
}
[TaskName("Clean")]
[TaskDescription("Clean build solution folder. It depends of value of configuration argument: ./bin/Debug for 'Debug' value or .bin/Release for 'Release' value")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionName}/bin/{context.MsBuildConfiguration}");
context.Log.Information($"Cleaning folder: {directory}");
context.CleanDirectory(directory);
}
}
[TaskName("Restore")]
[TaskDescription("Restore selected project")]
public sealed class RestoreTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Restoring project: {directory}");
context.DotNetCoreRestore(directory);
}
}
[TaskName("Build")]
[TaskDescription("Build selected project. It depends of value of configuration argument (Debug or Release)")]
[IsDependentOn(typeof(CleanTask))]
[IsDependentOn(typeof(RestoreTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Building project: {directory}");
context.DotNetCoreBuild(directory, new DotNetCoreBuildSettings
{
Configuration = context.MsBuildConfiguration,
});
}
}
[TaskName("SonarBegin")]
[TaskDescription("Start test with SonarQube.")]
public sealed class SonarBeginTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
var settings = new SonarBeginSettings
{
Key = context.SonarKey,
Url = context.SonarUrl,
Login = context.Login,
Password = context.Password,
WorkingDirectory = directory,
Verbose = true,
};
context.SonarBegin(settings);
}
}
[TaskName("SonarEnd")]
[TaskDescription("End test with SonarQube.")]
public sealed class SonarEndTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var settings = new SonarEndSettings
{
Login = context.Login,
Password = context.Password,
};
context.SonarEnd(settings);
}
}
[TaskName("Default")]
[IsDependentOn(typeof(SonarBeginTask))]
[IsDependentOn(typeof(BuildTask))]
[IsDependentOn(typeof(SonarEndTask))]
public class DefaultTask : FrostingTask
{
}
执行命令是:
./build.ps1 --target Default --projectpath C:\route\of\project --sonarkey Prueba --sonarurl http://localhost:9000/ --login admin --password admin --verbosity Diagnostic
但是我得到这个错误:
An error occurred when executing task 'SonarBegin'.
Error: System.Exception: No CoreCLR executable found (SonarScanner.MSBuild.dll)
at Cake.Sonar.SonarRunner.Run(SonarSettings settings)
at Cake.Sonar.SonarCakeAliases.SonarBegin(ICakeContext context, SonarBeginSettings settings)
at SonarBeginTask.Run(BuildContext context) in C:\Users\jmedingr\Desktop\MonEES.CICD.Cake\cake\Program.cs:line 166
at Cake.Frosting.FrostingTask`1.Cake.Frosting.IFrostingTask.RunAsync(ICakeContext context)
at Cake.Core.CakeTask.Execute(ICakeContext context)
at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report)
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings)
at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target)
at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
at Cake.Frosting.Internal.FrostingEngine`1.Run(String target)
at Cake.Frosting.Internal.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings)
我看不到修复它的方法...
您看到的错误 (No CoreCLR executable found
) 是由 Cake.Sonar 在找不到所需工具时引发的。
如果您查看 Cake.Sonar 的自述文件,它指出 #tool nuget:?package=MSBuild.SonarQube.Runner.Tool
需要 运行 Cake.Sonar。
所以我猜你的 Main
方法应该是这样的:
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.InstallTool(new Uri("nuget:?package=MSBuild.SonarQube.Runner.Tool"))
.Run(args);
}
不过我没有测试过。
我正在尝试使用糖霜蛋糕项目中的 sonarqube。
有我的任务:
using Cake.Common;
using Cake.Common.IO;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Build;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Docker;
using Cake.Frosting;
using Cake.Git;
using Cake.SemVer;
using Cake.Sonar;
using System.Linq;
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}
public class BuildContext : FrostingContext
{
public string MsBuildConfiguration { get; set; }
public string ProjectPath { get; set; }
public string SolutionFile { get; set; }
public string SolutionName { get; set; }
// For SonarQube
public string SonarKey { get; set; }
public string SonarUrl { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Verbose { get; set; }
public BuildContext(ICakeContext context)
: base(context)
{
ProjectPath = context.Argument("projectPath", @"C:\Users\User\source\repos\ConsoleApp1");
MsBuildConfiguration = context.Argument("configuration", "Release");
SolutionFile = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilename().ToString();
SolutionName = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilenameWithoutExtension().ToString();
SonarKey = context.Argument("SonarKey", "MyProject");
SonarUrl = context.Argument("SonarUrl", "http://localhost:9000/");
Login = context.Argument("Login", "admin");
Password = context.Argument("Password", "admin");
}
}
[TaskName("Clean")]
[TaskDescription("Clean build solution folder. It depends of value of configuration argument: ./bin/Debug for 'Debug' value or .bin/Release for 'Release' value")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionName}/bin/{context.MsBuildConfiguration}");
context.Log.Information($"Cleaning folder: {directory}");
context.CleanDirectory(directory);
}
}
[TaskName("Restore")]
[TaskDescription("Restore selected project")]
public sealed class RestoreTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Restoring project: {directory}");
context.DotNetCoreRestore(directory);
}
}
[TaskName("Build")]
[TaskDescription("Build selected project. It depends of value of configuration argument (Debug or Release)")]
[IsDependentOn(typeof(CleanTask))]
[IsDependentOn(typeof(RestoreTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Building project: {directory}");
context.DotNetCoreBuild(directory, new DotNetCoreBuildSettings
{
Configuration = context.MsBuildConfiguration,
});
}
}
[TaskName("SonarBegin")]
[TaskDescription("Start test with SonarQube.")]
public sealed class SonarBeginTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
var settings = new SonarBeginSettings
{
Key = context.SonarKey,
Url = context.SonarUrl,
Login = context.Login,
Password = context.Password,
WorkingDirectory = directory,
Verbose = true,
};
context.SonarBegin(settings);
}
}
[TaskName("SonarEnd")]
[TaskDescription("End test with SonarQube.")]
public sealed class SonarEndTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var settings = new SonarEndSettings
{
Login = context.Login,
Password = context.Password,
};
context.SonarEnd(settings);
}
}
[TaskName("Default")]
[IsDependentOn(typeof(SonarBeginTask))]
[IsDependentOn(typeof(BuildTask))]
[IsDependentOn(typeof(SonarEndTask))]
public class DefaultTask : FrostingTask
{
}
执行命令是:
./build.ps1 --target Default --projectpath C:\route\of\project --sonarkey Prueba --sonarurl http://localhost:9000/ --login admin --password admin --verbosity Diagnostic
但是我得到这个错误:
An error occurred when executing task 'SonarBegin'.
Error: System.Exception: No CoreCLR executable found (SonarScanner.MSBuild.dll)
at Cake.Sonar.SonarRunner.Run(SonarSettings settings)
at Cake.Sonar.SonarCakeAliases.SonarBegin(ICakeContext context, SonarBeginSettings settings)
at SonarBeginTask.Run(BuildContext context) in C:\Users\jmedingr\Desktop\MonEES.CICD.Cake\cake\Program.cs:line 166
at Cake.Frosting.FrostingTask`1.Cake.Frosting.IFrostingTask.RunAsync(ICakeContext context)
at Cake.Core.CakeTask.Execute(ICakeContext context)
at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report)
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings)
at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target)
at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
at Cake.Frosting.Internal.FrostingEngine`1.Run(String target)
at Cake.Frosting.Internal.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings)
我看不到修复它的方法...
您看到的错误 (No CoreCLR executable found
) 是由 Cake.Sonar 在找不到所需工具时引发的。
如果您查看 Cake.Sonar 的自述文件,它指出 #tool nuget:?package=MSBuild.SonarQube.Runner.Tool
需要 运行 Cake.Sonar。
所以我猜你的 Main
方法应该是这样的:
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.InstallTool(new Uri("nuget:?package=MSBuild.SonarQube.Runner.Tool"))
.Run(args);
}
不过我没有测试过。