Skip to content

Commit 50c741b

Browse files
author
David Thompson
committed
Fixes NetFabric#73 Loading NuGet dependencies in a Rosyln analyzer.
Add a package reference to NetFrabric.CodeAnalysis - Gets the dll into the build Include PackDependencies target - Adds the reference to the lib and analyzer Add all output dlls as analyzer references
1 parent bc03835 commit 50c741b

File tree

4 files changed

+77
-66
lines changed

4 files changed

+77
-66
lines changed

NetFabric.Hyperlinq.Analyzer.CodeFixes/NetFabric.Hyperlinq.Analyzer.CodeFixes.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
11+
<PackageReference Include="NetFabric.CodeAnalysis" Version="5.1.0" />
12+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
13+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
1214
<PrivateAssets>all</PrivateAssets>
1315
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1416
</PackageReference>
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,78 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<IsPackable>true</IsPackable>
5+
<IncludeBuildOutput>false</IncludeBuildOutput>
6+
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
</PropertyGroup>
29

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<IncludeBuildOutput>false</IncludeBuildOutput>
6-
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
7-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
</PropertyGroup>
10+
<PropertyGroup>
11+
<PackageId>NetFabric.Hyperlinq.Analyzer</PackageId>
12+
<PackageVersion>2.3.1</PackageVersion>
13+
<Authors>Antao Almada</Authors>
14+
<PackageIcon>Icon.png</PackageIcon>
15+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16+
<RepositoryUrl>https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer</RepositoryUrl>
17+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
18+
<Description>A Roslyn analyzer with rules related to generation and consumption of enumerables and async enumerables in C#.</Description>
19+
<PackageReleaseNotes></PackageReleaseNotes>
20+
<Copyright>Copyright 2019-2023 Antao Almada</Copyright>
21+
<PackageTags>hyperlinq, analyzers, enumerable, async, linq, performance</PackageTags>
22+
<DevelopmentDependency>true</DevelopmentDependency>
23+
<NoPackageAnalysis>true</NoPackageAnalysis>
24+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
25+
</PropertyGroup>
926

10-
<PropertyGroup>
11-
<PackageId>NetFabric.Hyperlinq.Analyzer</PackageId>
12-
<PackageVersion>2.2.0</PackageVersion>
13-
<Authors>Antao Almada</Authors>
14-
<PackageIcon>Icon.png</PackageIcon>
15-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16-
<RepositoryUrl>https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer</RepositoryUrl>
17-
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
18-
<Description>A Roslyn analyzer with rules related to generation and consumption of enumerables and async enumerables in C#.</Description>
19-
<PackageReleaseNotes></PackageReleaseNotes>
20-
<Copyright>Copyright 2019-2023 Antao Almada</Copyright>
21-
<PackageTags>hyperlinq, analyzers, enumerable, async, linq, performance</PackageTags>
22-
<DevelopmentDependency>true</DevelopmentDependency>
23-
<NoPackageAnalysis>true</NoPackageAnalysis>
24-
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
25-
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
26-
</PropertyGroup>
27+
<ItemGroup>
28+
<None Include="..\Icon.png" Pack="true" PackagePath="" />
29+
<None Include="..\LICENSE" Pack="true" PackagePath="" />
30+
</ItemGroup>
2731

28-
<ItemGroup>
29-
<None Include="..\Icon.png" Pack="true" PackagePath="" />
30-
<None Include="..\LICENSE" Pack="true" PackagePath="" />
31-
</ItemGroup>
32-
33-
<ItemGroup>
34-
<ProjectReference Include="..\NetFabric.Hyperlinq.Analyzer.CodeFixes\NetFabric.Hyperlinq.Analyzer.CodeFixes.csproj" />
35-
<ProjectReference Include="..\NetFabric.Hyperlinq.Analyzer\NetFabric.Hyperlinq.Analyzer.csproj" />
36-
</ItemGroup>
32+
<ItemGroup>
33+
<ProjectReference Include="..\NetFabric.Hyperlinq.Analyzer.CodeFixes\NetFabric.Hyperlinq.Analyzer.CodeFixes.csproj" />
34+
<ProjectReference Include="..\NetFabric.Hyperlinq.Analyzer\NetFabric.Hyperlinq.Analyzer.csproj" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<None Update="tools\*.ps1" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="" />
39+
</ItemGroup>
3740

38-
<ItemGroup>
39-
<None Update="tools\*.ps1" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="" />
40-
</ItemGroup>
41+
<ItemGroup>
42+
<PackageReference Include="NetFabric.CodeAnalysis" Version="5.1.0" PrivateAssets="all" Pack="true" GeneratePathProperty="true" />
43+
</ItemGroup>
4144

42-
<Target Name="_AddAnalyzersToOutput">
43-
<ItemGroup>
44-
<TfmSpecificPackageFile Include="$(OutputPath)\NetFabric.Hyperlinq.Analyzer.dll" PackagePath="analyzers/dotnet/cs" />
45-
<TfmSpecificPackageFile Include="$(OutputPath)\NetFabric.Hyperlinq.Analyzer.CodeFixes.dll" PackagePath="analyzers/dotnet/cs" />
46-
</ItemGroup>
47-
</Target>
45+
<ItemGroup>
46+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
47+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" PrivateAssets="all" />
48+
</ItemGroup>
4849

49-
</Project>
50+
<!-- For every PackageReference with Pack=true, we include the assemblies from it in the package -->
51+
<Target Name="AddPackDependencies" Inputs="@(RuntimeCopyLocalItems)" Outputs="%(RuntimeCopyLocalItems.NuGetPackageId)" DependsOnTargets="ResolvePackageAssets" BeforeTargets="GenerateNuspec" AfterTargets="ResolvePackageAssets">
52+
<ItemGroup>
53+
<NuGetPackageId Include="@(RuntimeCopyLocalItems -> '%(NuGetPackageId)')" />
54+
</ItemGroup>
55+
<PropertyGroup>
56+
<NuGetPackageId>@(NuGetPackageId -&gt; Distinct())</NuGetPackageId>
57+
</PropertyGroup>
58+
<ItemGroup>
59+
<PackageReferenceDependency Include="@(PackageReference -&gt; WithMetadataValue('Identity', '$(NuGetPackageId)'))" />
60+
</ItemGroup>
61+
<PropertyGroup>
62+
<NuGetPackagePack>@(PackageReferenceDependency -> '%(Pack)')</NuGetPackagePack>
63+
</PropertyGroup>
64+
<ItemGroup Condition="'$(NuGetPackagePack)' == 'true'">
65+
<_PackageFiles Include="@(RuntimeCopyLocalItems)" PackagePath="$(BuildOutputTargetFolder)/$(TargetFramework)/%(Filename)%(Extension)" />
66+
<None Include="@(RuntimeCopyLocalItems)" Pack="true" PackagePath="analyzers/dotnet/cs" />
67+
<RuntimeCopyLocalItems Update="@(RuntimeCopyLocalItems)" CopyLocal="true" Private="true" />
68+
<ResolvedFileToPublish Include="@(RuntimeCopyLocalItems)" CopyToPublishDirectory="PreserveNewest" RelativePath="%(Filename)%(Extension)" />
69+
</ItemGroup>
70+
</Target>
71+
72+
<Target Name="_AddAnalyzersToOutput">
73+
<ItemGroup>
74+
<TfmSpecificPackageFile Include="$(OutputPath)\*.dll" PackagePath="analyzers/dotnet/cs" />
75+
</ItemGroup>
76+
</Target>
77+
78+
</Project>

NetFabric.Hyperlinq.Analyzer.sln

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat
3232
docs\reference\HLQ007_NonDisposableEnumerator.md = docs\reference\HLQ007_NonDisposableEnumerator.md
3333
docs\reference\HLQ008_ReadOnlyRefEnumerable.md = docs\reference\HLQ008_ReadOnlyRefEnumerable.md
3434
docs\reference\HLQ009_RemoveOptionalMethods.md = docs\reference\HLQ009_RemoveOptionalMethods.md
35+
docs\reference\HLQ010_UseForLoop.md = docs\reference\HLQ010_UseForLoop.md
3536
docs\reference\HLQ011_ReadOnlyEnumeratorField.md = docs\reference\HLQ011_ReadOnlyEnumeratorField.md
3637
docs\reference\HLQ012_UseCollectionsMarshalAsSpan.md = docs\reference\HLQ012_UseCollectionsMarshalAsSpan.md
3738
docs\reference\HLQ013_UseForEachLoop.md = docs\reference\HLQ013_UseForEachLoop.md

NetFabric.Hyperlinq.Analyzer/NetFabric.Hyperlinq.Analyzer.csproj

+2-23
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
<IsPackable>false</IsPackable>
66
<LangVersion>10</LangVersion>
77
<EnforceExtendedAnalyzerRules>True</EnforceExtendedAnalyzerRules>
8-
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
9-
10-
<!-- Avoid ID conflicts with the package project. -->
11-
<PackageId>*$(MSBuildProjectFile)*</PackageId>
8+
9+
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1210
</PropertyGroup>
1311

1412
<ItemGroup>
@@ -22,30 +20,11 @@
2220
<PrivateAssets>all</PrivateAssets>
2321
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2422
</PackageReference>
25-
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13">
26-
<PrivateAssets>all</PrivateAssets>
27-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
28-
</PackageReference>
2923
</ItemGroup>
3024

3125
<ItemGroup>
3226
<Compile Update="Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
3327
<EmbeddedResource Update="Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
3428
</ItemGroup>
3529

36-
<Target Name="ILRepack" AfterTargets="Build">
37-
<PropertyGroup>
38-
<WorkingDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)</WorkingDirectory>
39-
</PropertyGroup>
40-
<ItemGroup>
41-
<InputAssemblies Include="NetFabric.CodeAnalysis.dll" />
42-
</ItemGroup>
43-
<ILRepack OutputType="$(OutputType)"
44-
MainAssembly="$(AssemblyName).dll"
45-
OutputAssembly="$(AssemblyName).dll"
46-
InputAssemblies="@(InputAssemblies)"
47-
InternalizeExcludeAssemblies="@(InternalizeExcludeAssemblies)"
48-
WorkingDirectory="$(WorkingDirectory)" />
49-
</Target>
50-
5130
</Project>

0 commit comments

Comments
 (0)