GENERATEFAKES of MS Fakes fails with CS1705 sporadically

Christian Fahrenholz 1 Reputation point
2022-08-27T13:04:08.057+00:00

I posted this already on Stackoverflow, I am not sure if you guys will notice it there so I post it also here.

On my machine the unit test project build fails since a few days but not every time. On the machine of my colleague it fails also sometimes but most of the time he just needs to rebuild and build succeeds.

Assembly 'xx' with identity '...' uses 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'System.ValueTuple' with identity 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [PathToTestDir\obj\Debug\Fakes\xx\f.csproj]
GENERATEFAKES : error : project compilation failed with exit code 1

I have checked all nuget references in our solution of all projects (also in project.assests.json and packages.lock.json) and all of them are referencing System.ValueTuple package Version 4.5.0 (assembly version 4.0.3.0).

In packages.lock.json I see the following dependency at this json path:

dependencies[".NETFramework,Version=v4.6.2"]["Microsoft.CodeAnalysis.Common"]

which is this one:

"Microsoft.CodeAnalysis.Common": {"type": "Transitive", "resolved": "2.8.0",...

and this contains a dependency to:

"System.ValueTuple": "4.3.0"

which has assembly version 4.0.2.0.

What I also see in the generated f.csproj file is this hintpath:

   <Reference Include="System.ValueTuple">  
         <HintPath>[PathToXX]\bin\Debug\System.ValueTuple.dll</HintPath>  
         <Aliases>svt</Aliases>  
         <EmbedInteropTypes>False</EmbedInteropTypes>  
       </Reference>  

But at this path the correct version 4.0.3.0 is located. The whole source and all bin output folders do not contain a version 4.0.2.0, except in the obj folder for those fakes generated assemblies.

For all other projects that we reference as fakes the MS Fakes tool is generating this hint path:

<Reference Include="System.ValueTuple">  
      <HintPath>C:\Users\myuser\.nuget\packages\system.valuetuple\4.5.0\ref\net461\System.ValueTuple.dll</HintPath>  
      <EmbedInteropTypes>False</EmbedInteropTypes>  
    </Reference>   

Our solution contains several net462 classic projects (Package Reference Style) and also some sdk style projects, some of our project do also reference Asp.net core 2.1. Our unit test project is using Microsoft Fakes and MS-Test since years. We are using VS 2022 (17.1.6).

What I have tried so far:
* Closing VS, deleting all bin and obj folders, deleting nuget cache, restarting VS, rebuilding (it worked one time for me so far, but now I am stuck again for days now)
* Setting AutoGenerateBindingRedirects and GenerateBindingRedirectsOutputTypeto in the unit test project to True
* Also in the .fakes file I tried to set these two properties (even when GenerateBindingRedirectsOutputType makes not much sense for fakes assembly).
* Tried out this SO answer

so my fakes file looks like this after these unsuccessful attempts:

   <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">  
     <Assembly Name="xx"/>  
     <StubGeneration>  
       <Clear/>  
       <Add Interfaces="true"/>  
       <Remove TypeName="xyz"/>  
     </StubGeneration>  
     <!--Shim do not make sense for interfaces-->  
     <ShimGeneration>  
       <Clear/>  
     </ShimGeneration>  
     <Compilation>  
       <Property Name="PlatformTarget">x64</Property>  
       <Property Name="AutoGenerateBindingRedirects">True</Property>  
       <Property Name="GenerateBindingRedirectsOutputType">True</Property>  
     </Compilation>  
   </Fakes>  

I would appreciate any help or hint so much, thanks!

EDIT:
I also see these warnings in the output window:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: Found conflicts between different versions of "System.ValueTuple" that could not be resolved. [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: There was a conflict between "System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: "System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not. [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,196 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
326 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,815 questions
{count} votes