public void Load(IScriptAnalyzerContext context, LoadReference reference) { #if NETCORE throw new NotSupportedException("The NuGet provider for #load is not supported on .NET Core."); #else // Create a package reference from our load reference. // The package should contain the necessary include parameters to make sure // that .cake files are included as part of the result. var separator = reference.OriginalString.Contains("?") ? "&" : "?"; var uri = string.Concat(reference.OriginalString, $"{separator}include=./**/*.cake"); var package = new PackageReference(uri); // Find the tool folder. var toolPath = GetToolPath(context.Root.GetDirectory()); // Install the NuGet package. var files = _installer.Install(package, PackageType.Tool, toolPath); if (files.Count == 0) { // No files found. _log.Warning("No scripts found in NuGet package {0}.", package.Package); return; } foreach (var file in files) { var extension = file.Path.GetExtension(); if (extension != null && extension.Equals(".cake", StringComparison.OrdinalIgnoreCase)) { context.Analyze(file.Path); } } #endif }
public void Load(IScriptAnalyzerContext context, LoadReference reference) { // Create a package reference from our load reference. // If not specified in script, the package should contain the necessary include // parameters to make sure that .cake files are included as part of the result. var uri = new Uri(reference.OriginalString); var parameters = uri.GetQueryString(); const string includeParameterName = "include"; if (!parameters.ContainsKey(includeParameterName)) { var separator = parameters.Count > 0 ? "&" : "?"; uri = new Uri(string.Concat(reference.OriginalString, $"{separator}include=./**/*.cake")); } var package = new PackageReference(uri); // Find the tool folder. var toolPath = GetToolPath(_environment.WorkingDirectory); // Install the NuGet package. var files = _installer .Install(package, PackageType.Tool, toolPath) .Where(file => { var extension = file.Path.GetExtension(); return(extension != null && extension.Equals(".cake", StringComparison.OrdinalIgnoreCase)); }) .ToArray(); if (files.Length == 0) { // No scripts found. _log.Warning("No scripts found in NuGet package {0}.", package.Package); return; } foreach (var file in files) { context.Analyze(file.Path); } }