Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for the future iteration - the version here should be in sync with Version.props - we can either ensure that during pcaking, or just simply ad a manual steps to our release checklist

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GangWang01, could you take care of it? the first option is preferable. Feel free to create a separate work item for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GangWang01 - would you be able to handle #9915 as well? Feel free to contact me with any questions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #9923. And self assigned with both issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for the future iteration - the version here should be in sync with Version.props - we can either ensure that during pcaking, or just simply ad a manual steps to our release checklist

@JanKrivanek Could you give me more info how to add a manual steps to our release checklist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please include this info to this document
#9958

"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
}
]
}
34 changes: 34 additions & 0 deletions template_feed/Microsoft.AnalyzerTemplate/Analyzer1.cs
Original file line number Diff line number Diff line change
@@ -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<BuildAnalyzerRule> 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<EvaluatedPropertiesAnalysisData> context)
{
context.ReportResult(BuildCopResult.Create(
SupportedRule,
ElementLocation.EmptyLocation,
"Argument for the message format");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<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="Directory.Build.props" Pack="true" PackagePath="build\Directory.Build.props" />
<Content Include="README.md" />
</ItemGroup>

<ItemGroup>
<!-- Please add IncludeInPackage field to all third party dependencies. See the example below.-->
<PackageReference Include="Microsoft.Build" 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,9 @@
<?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>
<ItemGroup>
<PackageVersion Include="Microsoft.Build" Version="1.0.0-MicrosoftBuildPackageVersion" />
</ItemGroup>
</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 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 <ProjectName>

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