-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add analyzer template #9789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
YuliiaKovalova
merged 6 commits into
dotnet:exp/build-analyzers
from
YuliiaKovalova:dev/ykovalova/add_analyzer_template
Mar 25, 2024
Merged
Add analyzer template #9789
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7c13eb
add msbuild analyzer skeleton project
YuliiaKovalova dcbde46
update project structure
YuliiaKovalova 4ca2b18
apply readme suggestions
YuliiaKovalova d19968c
fix review comments
YuliiaKovalova fd95c22
Merge branch 'dev/ykovalova/add_analyzer_template' of https://github.…
YuliiaKovalova 464d7bc
Add skeleton example: for Analyzer1.cs
YuliiaKovalova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
template_feed/Microsoft.AnalyzerTemplate/.template.config/template.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "$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" | ||
| } | ||
| ], | ||
| "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 | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System; | ||
|
|
||
| namespace Company.AnalyzerTemplate | ||
| { | ||
| public class Analyzer1 | ||
| { | ||
| // will be added later. | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
template_feed/Microsoft.AnalyzerTemplate/Company.AnalyzerTemplate.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <DevelopmentDependency>true</DevelopmentDependency> | ||
| <IncludeBuildOutput>false</IncludeBuildOutput> | ||
| <GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
| <!-- The output structure was modified for msbuild develomplent needs.--> | ||
| <NoWarn>NU5101;NU5128</NoWarn> | ||
YuliiaKovalova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="Company.AnalyzerTemplate.props" Pack="true" PackagePath="build\Company.AnalyzerTemplate.props" /> | ||
| <Content Include="README.md" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Please add IncludeInPackage field to all third party dependencies. See an example below.--> | ||
| <!-- <PackageReference Include="ThirdPartyDependency" Version="1.0.0.0" PrivateAssets="all" IncludeInPackage="true" /> --> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="AddNuGetDlls" BeforeTargets="_GetPackageFiles"> | ||
| <!-- Merge the collection of PackageReference and Assemblies using the NuGetPackageId key. | ||
| This produces a new list containing the DLL path and the "IncludeInPackage" metadata--> | ||
| <JoinItems Left="@(ResolvedCompileFileDefinitions)" LeftKey="NuGetPackageId" LeftMetadata="*" | ||
| Right="@(PackageReference)" RightKey="" RightMetadata="*" | ||
| ItemSpecToUse="Left"> | ||
| <Output TaskParameter="JoinResult" ItemName="_PackagesToPack" /> | ||
| </JoinItems> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Remove NETStandard DLLs --> | ||
| <_PackagesToPack Remove="@(_PackagesToPack)" Condition="%(NuGetPackageId) == 'NETStandard.Library'" /> | ||
| <_PackagesToPack Remove="@(_PackagesToPack)" Condition="%(_PackagesToPack.IncludeInPackage) != 'true'" /> | ||
| </ItemGroup> | ||
|
|
||
| <Message Importance="High" Text="Adding DLLs from the following packages: @(_PackagesToPack->'%(NuGetPackageId)')" /> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Update the collection of items to pack with the DLLs from the NuGet packages --> | ||
| <None Include="@(_PackagesToPack)" | ||
| Pack="true" | ||
| PackagePath="lib" | ||
| Visible="false" /> | ||
|
|
||
| <!-- Add the DLL produced by the current project to the NuGet package --> | ||
| <None Include="$(OutputPath)\$(AssemblyName).dll" | ||
| Pack="true" | ||
| PackagePath="lib" | ||
| Visible="false" /> | ||
| </ItemGroup> | ||
| </Target> | ||
| </Project> | ||
6 changes: 6 additions & 0 deletions
6
template_feed/Microsoft.AnalyzerTemplate/Company.AnalyzerTemplate.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <PropertyGroup> | ||
| <MSBuildAnalyzer>$([MSBuild]::RegisterAnalyzer($(MSBuildThisFileDirectory)..\lib\Company.AnalyzerTemplate.dll))</MSBuildAnalyzer> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 C# project files (.csproj). | ||
YuliiaKovalova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## 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 -i msbuildanalyzer | ||
YuliiaKovalova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 2. Instantiate a custom template: | ||
| ```bash | ||
| dotnet new msbuildanalyzer -n <ProjectName> | ||
|
|
||
| ### Prerequisites | ||
| - .NET SDK installed on your machine. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.