Build/Test Issues

Regression in Roslyn analyzer references in NCrunch 5

Started by grimsqueak on 2,317 views

Hi, my team at work has been using NCrunch 4 for years now and has grown addicted to it.

I'm looking into NCrunch 5 for the awesome RDI feature, but I'm struggling to get it to work correctly with some Roslyn analyzers and code generators we have. From the looks of it, it seems to import analyzers as both analyzers and dll references in the NCrunch project file, which breaks the build due to conflicts with classes in the code generators.

Here is how it looks, with the project file examples slightly abridged:

Original project file:
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\src\Brage.Schema\Brage.Schema.csproj" />
<ProjectReference Include="..\..\src\SWGLive.Schema.SourceGenerator\SWGLive.Schema.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" />
<ProjectReference Include="..\..\src\SWGLive.Schema\SWGLive.Schema.csproj" />
</ItemGroup>

</Project>

NCrunch 4 project file from working directory:
<Project DefaultTargets="Build;NCrunchOutputDataQuery" Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Reference Include="D:\ncrunch\17112\15\src\Brage.Capabilities\bin\Debug\net6.0\Brage.Capabilities.dll" />
<Reference Include="D:\ncrunch\17112\16\src\Brage.Schema\bin\Debug\net6.0\Brage.Schema.dll" />
<Reference Include="D:\ncrunch\17112\20\src\Brage.Compilation\bin\Debug\net6.0\Brage.Compilation.dll" />
<Reference Include="D:\ncrunch\17112\21\src\Brage.Evaluation\bin\Debug\net6.0\Brage.Evaluation.dll" />
<Reference Include="D:\ncrunch\17112\9\src\Brage.Core\bin\Debug\net6.0\Brage.Core.dll" />
<Reference Include="D:\ncrunch\17112\29\src\SWGLive.Schema\bin\Debug\net6.0\SWGLive.Schema.dll" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="c:\program files\microsoft visual studio\2022\enterprise\common7\ide\extensions\remco software\ncrunch for visual studio 2022\nCrunch.TestRuntime.DotNetCore.dll" />
[h] <Analyzer Include="D:\ncrunch\17112\5\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Client.dll" />
<Analyzer Include="D:\ncrunch\17112\5\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.ContentSchema.dll" />
<Analyzer Include="D:\ncrunch\17112\5\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Schema.dll" />
<Analyzer Include="D:\ncrunch\17112\5\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\SWGLive.Schema.SourceGenerator.dll" />[/h]
</ItemGroup>
</Project>

NCrunch 5
<Project DefaultTargets="Build;NCrunchOutputDataQuery" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectAssetsFile>C:\NCrunch\8516\221\src\Brage.TestSchemas\obj\project.assets.json</ProjectAssetsFile>
</PropertyGroup>
<ItemGroup>
[h] <Reference Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Client.dll" />
<Reference Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.ContentSchema.dll" />
<Reference Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Schema.dll" />
<Reference Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\SWGLive.Schema.SourceGenerator.dll" />[/h]
<Reference Include="C:\NCrunch\8516\143\src\Brage.Core\bin\Debug\net6.0\Brage.Core.dll" />
<Reference Include="C:\NCrunch\8516\145\src\Brage.Capabilities\bin\Debug\net6.0\Brage.Capabilities.dll" />
<Reference Include="C:\NCrunch\8516\146\src\Brage.Schema\bin\Debug\net6.0\Brage.Schema.dll" />
<Reference Include="C:\NCrunch\8516\155\src\Brage.Compilation\bin\Debug\net6.0\Brage.Compilation.dll" />
<Reference Include="C:\NCrunch\8516\213\src\Brage.Evaluation\bin\Debug\net6.0\Brage.Evaluation.dll" />
<Reference Include="C:\NCrunch\8516\156\src\SWGLive.Schema\bin\Debug\net6.0\SWGLive.Schema.dll" />
<Reference Include="C:\NCrunch\Engine\engine_1f21f60d-2065-461c-9210-075519711c3f\nCrunch.TestRuntime.DotNetCore.dll" />
</ItemGroup>
<ItemGroup>
[h] <Analyzer Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Client.dll" />
<Analyzer Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.ContentSchema.dll" />
<Analyzer Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\Fast.Yggdrasil.Schema.dll" />
<Analyzer Include="C:\NCrunch\8516\141\src\SWGLive.Schema.SourceGenerator\bin\Debug\netstandard2.0\SWGLive.Schema.SourceGenerator.dll" />[/h]
<Analyzer Include="C:\NCrunch\Engine\engine_1f21f60d-2065-461c-9210-075519711c3f\nCrunch.TestRuntime.DotNetCore.dll" />
</ItemGroup>
</Project>
Hi, thanks for sharing this issue.

From what I remember, we had a few changes go out in some of the later v4 releases that contained fixes specific to analyzers. I believe one of the changes was to try and deal with issues where people had analyzers that were both project references and analyzers.

Which version are you upgrading from? Can you tell me more about the structure of your projects (in regards to analyzers) and what kind of downstream problems this is causing for you?

Also .. is there any chance you can produce a test solution that can surface any of these problems?
Thanks for the quick response!

Our license server doesn't have licenses past 4.14.0.7, so that is the version I'm using day to day. I'm hoping that RDI will sway management to update the licenses though :)

The error message I'm getting is the following:
https://www.ncrunch.net/documentation/troubleshooting_project-build-issues
TestSchemas.cs (898, 21): The type 'DataDomain' exists in both 'Brage.Schema, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'SWGLive.Schema.SourceGenerator, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

The SWGLive.Schema.SourceGenerator is a generator to create a schema in our APIs expected format from other schemas defined by our partners. Due to our dependency graph, there is no easy way to reference the DataDomain in the Generator, so its duplicated there, with the original namespace etc. This is fine when the SourceGenerator is included as an analyzer only, like in NCrunch 4, but causes issues when included as a dll reference as in NCrunch 5. The effect of the TestSchema project failing to build breaks around half our test suite as it's a dependency on all tests that involves the schema in some form.

I can see if I can't create a test solution that reproduces this, but it might take some days as I'm typically pretty busy and it's a complex project setup.

Edit: It's not duplicated in the SourceGenerator as such, it's directly linked with a relative reference:
<Compile Include="..\Brage.Schema\DataDomain.cs" Link="DataDomain.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>

Thanks,
Ronny

Edited

Thanks Ronny. I think I'm starting to understand what's happening here with this analyzer reference. Would it be possible for you to give me the XML in your project containing the reference to the analyzer? I might be able to use this to recreate the problem myself.
Thanks Remco,

by XML in my project that contains the reference, you mean how it's referenced in the csproj?

If so, it was included in the original post:
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\src\Brage.Schema\Brage.Schema.csproj" />
[h]<ProjectReference Include="..\..\src\SWGLive.Schema.SourceGenerator\SWGLive.Schema.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" />[/h]
<ProjectReference Include="..\..\src\SWGLive.Schema\SWGLive.Schema.csproj" />
</ItemGroup>

</Project>

If I misunderstood, I'll be happy to dig up the correct XML for you.
Thanks! I think this contains what I need. I'll be in touch.
Could you try the build below and let me know if this solves the issue for you?

NCrunch_Console_5.4.0.2.msi
NCrunch_Console_5.4.0.2.zip
NCrunch_GridNodeServer_5.4.0.2.msi
NCrunch_GridNodeServer_5.4.0.2.zip
NCrunch_LicenseServer_5.4.0.2.zip
NCrunch_Rider_5.4.0.2.7z
NCrunch_Rider_5.4.0.2.zip
NCrunch_VS2010_5.4.0.2.msi
NCrunch_VS2010_5.4.0.2.zip
NCrunch_VS2012_5.4.0.2.msi
NCrunch_VS2012_5.4.0.2.zip
NCrunch_VS2013_5.4.0.2.msi
NCrunch_VS2013_5.4.0.2.zip
NCrunch_VS2015_5.4.0.2.msi
NCrunch_VS2015_5.4.0.2.msi.7z
NCrunch_VS2015_5.4.0.2.zip
NCrunch_VS2017_5.4.0.2.msi
NCrunch_VS2017_5.4.0.2.msi.7z
NCrunch_VS2017_5.4.0.2.zip
NCrunch_VS2019_5.4.0.2.msi
NCrunch_VS2019_5.4.0.2.msi.7z
NCrunch_VS2019_5.4.0.2.zip
NCrunch_VS2022_5.4.0.2.msi
NCrunch_VS2022_5.4.0.2.msi.7z
NCrunch_VS2022_5.4.0.2.zip
Awesome, I can confirm that this latest build does indeed fix the analyzer reference problem, and I'm now able to test the full solution again.

Thanks for the quick turnaround.

Post a reply

Log in to reply.