Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
]
}
9 changes: 9 additions & 0 deletions template_feed/Microsoft.AnalyzerTemplate/Analyzer1.cs
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.
}
}
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>
</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>
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>
21 changes: 21 additions & 0 deletions template_feed/Microsoft.AnalyzerTemplate/README.md
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).

## 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
2. Instantiate a custom template:
```bash
dotnet new msbuildanalyzer -n <ProjectName>

### Prerequisites
- .NET SDK installed on your machine.