Skip to content

Commit 5d5c7a0

Browse files
authored
Fix NRE on XUnitMigrationAnalyzer and Simplify Analyzer project files (#2493)
1 parent 11637c3 commit 5d5c7a0

File tree

12 files changed

+87
-71
lines changed

12 files changed

+87
-71
lines changed

Analyzer.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
3+
<Import Project="$(MSBuildThisFileDirectory)Roslyn.props" />
4+
5+
<ItemGroup>
6+
<Compile Include="..\TUnit.Analyzers\**\*.cs" Exclude="..\TUnit.Analyzers\obj\**\*.cs" />
7+
<EmbeddedResource Include="..\TUnit.Analyzers\**\*.resx" />
8+
</ItemGroup>
9+
10+
</Project>

Roslyn.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
3+
<ItemGroup>
4+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
5+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
6+
<PackageReference Include="Polyfill">
7+
<PrivateAssets>all</PrivateAssets>
8+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9+
</PackageReference>
10+
</ItemGroup>
11+
12+
</Project>

SourceGenerator.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
3+
<Import Project="$(MSBuildThisFileDirectory)Roslyn.props" />
4+
5+
<ItemGroup>
6+
<Compile Include="..\TUnit.Core.SourceGenerator\**\*.cs" Exclude="..\TUnit.Core.SourceGenerator\obj\**\*.cs" />
7+
</ItemGroup>
8+
9+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RoslynVersion>4.14</RoslynVersion>
5+
</PropertyGroup>
6+
7+
<Import Project="$(MSBuildThisFileDirectory)..\Analyzer.props" />
8+
9+
</Project>

TUnit.Analyzers.Roslyn44/TUnit.Analyzers.Roslyn44.csproj

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
<RoslynVersion>4.4</RoslynVersion>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
10-
<PackageReference Include="Polyfill">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
14-
</ItemGroup>
7+
<Import Project="$(MSBuildThisFileDirectory)..\Analyzer.props" />
158

16-
<ItemGroup>
17-
<Compile Include="..\TUnit.Analyzers\**\*.cs" Exclude="..\TUnit.Analyzers\obj\**\*.cs" />
18-
<EmbeddedResource Include="..\TUnit.Analyzers\**\*.resx" />
19-
</ItemGroup>
20-
21-
</Project>
9+
</Project>

TUnit.Analyzers.Roslyn47/TUnit.Analyzers.Roslyn47.csproj

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@
44
<RoslynVersion>4.7</RoslynVersion>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
10-
<PackageReference Include="Polyfill">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
14-
</ItemGroup>
7+
<Import Project="$(MSBuildThisFileDirectory)..\Analyzer.props" />
158

16-
<ItemGroup>
17-
<Compile Include="..\TUnit.Analyzers\**\*.cs" Exclude="..\TUnit.Analyzers\obj\**\*.cs" />
18-
<EmbeddedResource Include="..\TUnit.Analyzers\**\*.resx" />
19-
</ItemGroup>
20-
21-
<ItemGroup>
22-
<Folder Include="..\TUnit.Analyzers\EqualityComparers\">
23-
<Link>EqualityComparers</Link>
24-
</Folder>
25-
</ItemGroup>
26-
27-
</Project>
9+
</Project>

TUnit.Analyzers/Migrators/XUnitMigrationAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
3737
return;
3838
}
3939

40-
if (symbol.AllInterfaces.Any(i => i.ContainingNamespace.Name.StartsWith("Xunit")))
40+
if (symbol.AllInterfaces.Any(i => i.ContainingNamespace?.Name.StartsWith("Xunit") is true))
4141
{
4242
Flag(context);
4343
return;
@@ -82,9 +82,9 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
8282

8383
ITypeSymbol[] types =
8484
[
85-
..members.OfType<IPropertySymbol>().Where(x => x.Type.ContainingNamespace.Name.StartsWith("Xunit")).Select(x => x.Type),
86-
..members.OfType<IMethodSymbol>().Where(x => x.ReturnType.ContainingNamespace.Name.StartsWith("Xunit")).Select(x => x.ReturnType),
87-
..members.OfType<IFieldSymbol>().Where(x => x.Type.ContainingNamespace.Name.StartsWith("Xunit")).Select(x => x.Type),
85+
..members.OfType<IPropertySymbol>().Where(x => x.Type.ContainingNamespace?.Name.StartsWith("Xunit") is true).Select(x => x.Type),
86+
..members.OfType<IMethodSymbol>().Where(x => x.ReturnType.ContainingNamespace?.Name.StartsWith("Xunit") is true).Select(x => x.ReturnType),
87+
..members.OfType<IFieldSymbol>().Where(x => x.Type.ContainingNamespace?.Name.StartsWith("Xunit") is true).Select(x => x.Type),
8888
];
8989

9090
if (types.Any())
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RoslynVersion>4.14</RoslynVersion>
5+
</PropertyGroup>
6+
7+
<Import Project="..\SourceGenerator.props" />
8+
9+
</Project>

TUnit.Core.SourceGenerator.Roslyn44/TUnit.Core.SourceGenerator.Roslyn44.csproj

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
<RoslynVersion>4.4</RoslynVersion>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
10-
<PackageReference Include="Polyfill">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
14-
</ItemGroup>
15-
16-
<ItemGroup>
17-
<Compile Include="..\TUnit.Core.SourceGenerator\**\*.cs" Exclude="..\TUnit.Core.SourceGenerator\obj\**\*.cs" />
18-
</ItemGroup>
7+
<Import Project="..\SourceGenerator.props" />
198

209
</Project>

TUnit.Core.SourceGenerator.Roslyn47/TUnit.Core.SourceGenerator.Roslyn47.csproj

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,7 @@
33
<PropertyGroup>
44
<RoslynVersion>4.7</RoslynVersion>
55
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
10-
<PackageReference Include="Polyfill">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
14-
</ItemGroup>
156

16-
<ItemGroup>
17-
<Compile Include="..\TUnit.Core.SourceGenerator\**\*.cs" Exclude="..\TUnit.Core.SourceGenerator\obj\**\*.cs" />
18-
<Compile Update="..\TUnit.Core.SourceGenerator\CodeGenerators\Helpers\DynamicTestSourceDataModelRetriever.cs">
19-
<Link>CodeGenerators\Helpers\DynamicTestSourceDataModelRetriever.cs</Link>
20-
</Compile>
21-
<Compile Update="..\TUnit.Core.SourceGenerator\Models\DynamicTestSourceDataModel.cs">
22-
<Link>Models\DynamicTestSourceDataModel.cs</Link>
23-
</Compile>
24-
</ItemGroup>
7+
<Import Project="..\SourceGenerator.props" />
258

26-
</Project>
9+
</Project>

0 commit comments

Comments
 (0)