-
Notifications
You must be signed in to change notification settings - Fork 357
2. NuGet Support
Gabe Stocco edited this page Nov 9, 2024
·
2 revisions
In additional to releases on GitHub, Application Inspector is available through nuget.org, both as a library and a stand-alone command-line tool.
- Microsoft.CST.ApplicationInspector.Commands - library that can be integrated into your application
- Microsoft.CST.ApplicationInspector.CLI - the command line tool
-
dotnet tool install Microsoft.CST.ApplicationInspector.CLI
or -
dotnet tool install --global Microsoft.CST.ApplicationInspector.CLI
(as global tool for use from any directory)
Then simply run the tool normally from a command prompt. See the README.md for more information.
- Add the Microsoft.CST.ApplicationInspector.Commands package to your project as described above
- Add the references as required, usually at least:
using Microsoft.ApplicationInspector.Commands;
using Microsoft.ApplicationInspector.RulesEngine;
- Start using the available commands.
try
{
AnalyzeCommand command = new AnalyzeCommand(new AnalyzeOptions()
{
SourcePath = "/home/user/myproject"
});
AnalyzeResult result = command.GetResult();
if (result.ResultCode == AnalyzeResult.ExitCode.Success)
{
//access result properties in result.Metadata e.g.
foreach (string tag in result.Metadata.UniqueTags)
{
Console.WriteLine(tag);
}
foreach (MatchRecord matchRecord in result.Metadata.Matches)
{
Console.WriteLine($"File: {matchRecord.FileName}");
Console.WriteLine($"Rule: {matchRecord.RuleName}");
Console.WriteLine($"Matched Text: {matchRecord.Sample}");
Console.WriteLine($"Confidence{matchRecord.Confidence}");
}
}
}
catch (Exception e)
{
}
try
{
TagDiffCommand command = new TagDiffCommand(new TagDiffOptions()
{
SourcePath1 = "/home/user/myproject/v1",
SourcePath2 = "/home/user/myproject/v2"
});
TagDiffResult result = command.GetResult();
if (result.ResultCode == TagDiffResult.ExitCode.TestFailed)
{
foreach (TagDiff diff in result.TagDiffList)
{
Console.WriteLine(string.Format("tagname: {0}, only found in: {1}", diff.Tag, diff.Source));
}
}
}
catch (Exception e)
{
//log error
}
try
{
TagTestCommand command = new TagTestCommand(new TagTestOptions()
{
SourcePath = "/home/user/myproject/v1",
CustomRulesPath = "/home/user/myrules/myrule.json"
});
TagTestResult result = command.GetResult();
if (result.ResultCode == TagTestResult.ExitCode.TestFailed)
{
foreach (TagStatus tagStatus in result.TagsStatusList)
{
if (!tagStatus.Detected)
Console.WriteLine(string.Format("Rule tag: {0} not detected", tagStatus.Tag));
}
}
}
catch (Exception e)
{
//log error
}
try
{
ExportTagsCommand command = new ExportTagsCommand(new ExportTagsOptions());
ExportTagsResult result = command.GetResult();
if (result.ResultCode == ExportTagsResult.ExitCode.Success)
{
foreach (string tag in result.TagsList)
{
Console.WriteLine(tag);
}
}
}
catch (Exception)
{
//check for specific error if desired
}
try
{
VerifyRulesCommand command = new VerifyRulesCommand(new VerifyRulesOptions()
{
CustomRulesPath = "/home/user/myrules/myrule.json"
});
VerifyRulesResult result = command.GetResult();
foreach (RuleStatus ruleStatus in result.RuleStatusList)
{
if (!ruleStatus.Verified)
Console.WriteLine(string.Format("Rule {0} [1} not verfied", ruleStatus.RulesId, ruleStatus.RulesName));
}
}
catch (Exception e)
{
//log error
}
The Pack Rules command requires a file for packing result and is only available via the CLI application.
Additional options exists for each command option type. See README.md for more information.