diff --git a/template_feed/Microsoft.AnalyzerTemplate/.template.config/template.json b/template_feed/Microsoft.AnalyzerTemplate/.template.config/template.json new file mode 100644 index 00000000000..071723c97cc --- /dev/null +++ b/template_feed/Microsoft.AnalyzerTemplate/.template.config/template.json @@ -0,0 +1,49 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Microsoft", + "classifications": [ + "Common", + "Library" + ], + "name": "MSBuild custom analyzer skeleton project.", + "generatorVersions": "[1.0.0.0-*)", + "description": "A project for creating a MSBuild analyzer library that targets .NET Standard", + "groupIdentity": "Microsoft.AnalyzerTemplate", + "identity": "Microsoft.AnalyzerTemplate", + "shortName": "msbuildanalyzer", + "tags": { + "language": "C#", + "type": "project" + }, + "sourceName": "Company.AnalyzerTemplate", + "preferNameDirectory": true, + "primaryOutputs": [ + { + "path": "Company.AnalyzerTemplate.csproj" + } + ], + "symbols": { + "MicrosoftBuildVersion": { + "type": "parameter", + "description": "Overrides the default Microsoft.Build version where analyzer's interfaces are placed", + "datatype": "text", + "defaultValue": "17.9.5", + "replaces": "1.0.0-MicrosoftBuildPackageVersion", + "displayName": "Microsoft.Build default package version override" + } + }, + "postActions": [ + { + "id": "restore", + "condition": "(!skipRestore)", + "description": "Restore NuGet packages required by this project.", + "manualInstructions": [ + { + "text": "Run 'dotnet restore'" + } + ], + "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025", + "continueOnError": true + } + ] + } \ No newline at end of file diff --git a/template_feed/Microsoft.AnalyzerTemplate/Analyzer1.cs b/template_feed/Microsoft.AnalyzerTemplate/Analyzer1.cs new file mode 100644 index 00000000000..e6d225f21dd --- /dev/null +++ b/template_feed/Microsoft.AnalyzerTemplate/Analyzer1.cs @@ -0,0 +1,34 @@ +using System; + +namespace Company.AnalyzerTemplate +{ + public sealed class Analyzer1 : BuildAnalyzer + { + public static BuildAnalyzerRule SupportedRule = new BuildAnalyzerRule("X01234", "Title", + "Description", "Category", + "Message format: {0}", + new BuildAnalyzerConfiguration() { Severity = BuildAnalyzerResultSeverity.Warning, IsEnabled = true }); + + public override string FriendlyName => "Company.Analyzer1"; + + public override IReadOnlyList SupportedRules { get; } =[SupportedRule]; + + public override void Initialize(ConfigurationContext configurationContext) + { + // configurationContext to be used only if analyzer needs external configuration data. + } + + public override void RegisterActions(IBuildCopRegistrationContext registrationContext) + { + registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); + } + + private void EvaluatedPropertiesAction(BuildCopDataContext context) + { + context.ReportResult(BuildCopResult.Create( + SupportedRule, + ElementLocation.EmptyLocation, + "Argument for the message format"); + } + } +} diff --git a/template_feed/Microsoft.AnalyzerTemplate/Company.AnalyzerTemplate.csproj b/template_feed/Microsoft.AnalyzerTemplate/Company.AnalyzerTemplate.csproj new file mode 100644 index 00000000000..6de9fb1f434 --- /dev/null +++ b/template_feed/Microsoft.AnalyzerTemplate/Company.AnalyzerTemplate.csproj @@ -0,0 +1,45 @@ + + + + netstandard2.0 + true + false + True + + NU5101;NU5128 + + + + + + + + + + + + + + + + + + + + + <_PackagesToPack Remove="@(_PackagesToPack)" Condition="%(NuGetPackageId) == 'NETStandard.Library'" /> + <_PackagesToPack Remove="@(_PackagesToPack)" Condition="%(_PackagesToPack.IncludeInPackage) != 'true'" /> + + + + + + + + + + + + + diff --git a/template_feed/Microsoft.AnalyzerTemplate/Directory.Build.props b/template_feed/Microsoft.AnalyzerTemplate/Directory.Build.props new file mode 100644 index 00000000000..8de4380640c --- /dev/null +++ b/template_feed/Microsoft.AnalyzerTemplate/Directory.Build.props @@ -0,0 +1,9 @@ + + + + $([MSBuild]::RegisterAnalyzer($(MSBuildThisFileDirectory)..\lib\Company.AnalyzerTemplate.dll)) + + + + + diff --git a/template_feed/Microsoft.AnalyzerTemplate/README.md b/template_feed/Microsoft.AnalyzerTemplate/README.md new file mode 100644 index 00000000000..4f29145e7f0 --- /dev/null +++ b/template_feed/Microsoft.AnalyzerTemplate/README.md @@ -0,0 +1,21 @@ +# MSBuild Custom Analyzer Template + +## Overview +MSBuild Custom Analyzer Template is a .NET template designed to streamline the creation of MSBuild analyzer libraries. This template facilitates the development of custom analyzers targeting .NET Standard, enabling developers to inspect and enforce conventions, standards, or patterns within their MSBuild builds. + +## Features +- Simplified template for creating MSBuild analyzer libraries. +- Targeting .NET Standard for cross-platform compatibility. +- Provides a starting point for implementing custom analysis rules. + +## Getting Started +To use the MSBuild Custom Analyzer Template, follow these steps: +1. Install the template using the following command: + ```bash + dotnet new install msbuildanalyzer +2. Instantiate a custom template: + ```bash + dotnet new msbuildanalyzer -n + +### Prerequisites +- .NET SDK installed on your machine. \ No newline at end of file