Skip to content
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

add .NET analyzers to the sdk #11717

Merged
merged 20 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
<Uri>https://github.com/dotnet/wpf</Uri>
<Sha>ad9690863941cee3961438b9f31002da530da71d</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="">
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
<Sha>03d8e7dbfc82a440aa6b08792693c1a0ea89fe64</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="5.0.0-beta.20228.4">
Expand Down
4 changes: 4 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<SystemSecurityCryptographyProtectedDataPackageVersion>5.0.0-preview.5.20253.7</SystemSecurityCryptographyProtectedDataPackageVersion>
<SystemResourcesExtensionsPackageVersion>5.0.0-preview.5.20253.7</SystemResourcesExtensionsPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/roslyn-analyzers -->
<MicrosoftCodeAnalysisNetAnalyzersVersion>3.3.0-beta1.20270.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/Microsoft/msbuild -->
<MicrosoftBuildPackageVersion>16.7.0-preview-20258-02</MicrosoftBuildPackageVersion>
Expand Down
1 change: 1 addition & 0 deletions src/Layout/redist/redist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Condition=" '$(DotNetBuildFromSource)' != 'true' " Include="NuGet.Localization" Version="$(NuGetProjectModelPackageVersion)" />
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetProjectModelPackageVersion)" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="$(MicrosoftNetCompilersToolsetPackageVersion)" ExcludeAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" ExcludeAssets="All" />

<!-- Lift up dependencies of dependencies to prevent build tasks from getting pinned to older versions -->
<PackageReference Include="System.CodeDom" Version="$(SystemCodeDomPackageVersion)" />
Expand Down
16 changes: 16 additions & 0 deletions src/Layout/redist/targets/GenerateLayout.targets
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
<Delete Files="@(RoslynFrameworkAssemblies)" />
</Target>

<Target Name="PublishNETAnalyzers"
BeforeTargets="Build;PublishNetSdk">
<PropertyGroup>
<AnalyzerAssembliesDirectory>$(ArtifactsBinDir)$(Configuration)\Sdks\Microsoft.NET.Sdk\analyzers</AnalyzerAssembliesDirectory>
<AnalyzerTargetsDirectory>$(AnalyzerAssembliesDirectory)\build</AnalyzerTargetsDirectory>
</PropertyGroup>
<ItemGroup>
<AnalyzerAssemblies Include="$(NuGetPackageRoot)/microsoft.codeanalysis.netanalyzers/$(MicrosoftCodeAnalysisNetAnalyzersVersion)/analyzers/dotnet/**/*" />
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
<AnalyzerTargets Include="$(NuGetPackageRoot)/microsoft.codeanalysis.netanalyzers/$(MicrosoftCodeAnalysisNetAnalyzersVersion)/build/**/*" />
</ItemGroup>
<Error Condition="'@(AnalyzerAssemblies)' == ''" Text="Something moved around in Analyzer package, adjust code here accordingly. TFM change?" />
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
<Error Condition="'@(AnalyzerTargets)' == ''" Text="Something moved around in Analyzer package, adjust code here accordingly. TFM change?" />
<Copy SourceFiles="@(AnalyzerAssemblies)" DestinationFiles="@(AnalyzerAssemblies->'$(AnalyzerAssembliesDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(AnalyzerTargets)" DestinationFiles="@(AnalyzerTargets->'$(AnalyzerTargetsDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

<Target Name="PublishMSBuildExtensions"
DependsOnTargets="GenerateMSBuildExtensions"
BeforeTargets="Build">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
***********************************************************************************************
Microsoft.NET.Sdk.Analyzers.props

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
<Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.props" Condition="'$(MSBuildProjectExtension)' == '.vbproj'" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
***********************************************************************************************
Microsoft.NET.Sdk.CSharp.Analyzers.targets
jmarolf marked this conversation as resolved.
Show resolved Hide resolved

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'">
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
<UsingNETAnalyzers>true</UsingNETAnalyzers>
</PropertyGroup>
<Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.targets" Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'" />
<ItemGroup Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'">
<Analyzer
Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\cs\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll"
IsImplicitlyDefined="true" />
<Analyzer
Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\cs\Microsoft.CodeAnalysis.NetAnalyzers.dll"
IsImplicitlyDefined="true" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
***********************************************************************************************
Microsoft.NET.Sdk.VisualBasic.Analyzers.targets

WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'">
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
<UsingNETAnalyzers>true</UsingNETAnalyzers>
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
<Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\build\Microsoft.CodeAnalysis.NetAnalyzers.targets" Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'" />
<ItemGroup Condition="'$(DisableNetAnalyzers)' != 'true' And '$(_TargetFrameworkVersionWithoutV)' >= '5.0'">
<Analyzer
Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\vb\Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"
IsImplicitlyDefined="true" />
<Analyzer
Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..))\analyzers\vb\Microsoft.CodeAnalysis.NetAnalyzers.dll"
IsImplicitlyDefined="true" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.CSharp.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.VisualBasic.props" Condition="'$(MSBuildProjectExtension)' == '.vbproj'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.FSharp.props" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.Analyzers.props" />

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackTool.props" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackProjectTool.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.VisualBasic.targets" Condition="'$(Language)' == 'VB'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.FSharp.targets" Condition="'$(Language)' == 'F#'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.ILLink.targets" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.CSharp.Analyzers.targets" Condition="'$(Language)' == 'C#'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.VisualBasic.Analyzers.targets" Condition="'$(Language)' == 'VB'" />
</Project>