Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Regression in Roslyn analyzer references in NCrunch 5
grimsqueak
#1 Posted : Thursday, March 14, 2024 9:31:22 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/14/2024(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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" />
<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" />

</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>
<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" />

<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>
<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" />

<Analyzer Include="C:\NCrunch\Engine\engine_1f21f60d-2065-461c-9210-075519711c3f\nCrunch.TestRuntime.DotNetCore.dll" />
</ItemGroup>
</Project>
Remco
#2 Posted : Thursday, March 14, 2024 10:06:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,997

Thanks: 932 times
Was thanked: 1258 time(s) in 1171 post(s)
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?
grimsqueak
#3 Posted : Thursday, March 14, 2024 10:52:56 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/14/2024(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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/...ng_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
Remco
#4 Posted : Thursday, March 14, 2024 8:48:22 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,997

Thanks: 932 times
Was thanked: 1258 time(s) in 1171 post(s)
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.
grimsqueak
#5 Posted : Friday, March 15, 2024 7:17:36 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/14/2024(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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" />
<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>

If I misunderstood, I'll be happy to dig up the correct XML for you.
Remco
#6 Posted : Friday, March 15, 2024 8:51:10 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,997

Thanks: 932 times
Was thanked: 1258 time(s) in 1171 post(s)
Thanks! I think this contains what I need. I'll be in touch.
Remco
#7 Posted : Saturday, March 16, 2024 5:23:25 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,997

Thanks: 932 times
Was thanked: 1258 time(s) in 1171 post(s)
1 user thanked Remco for this useful post.
grimsqueak on 3/16/2024(UTC)
grimsqueak
#8 Posted : Saturday, March 16, 2024 8:27:50 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/14/2024(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
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.
1 user thanked grimsqueak for this useful post.
Remco on 3/16/2024(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.075 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download