donttellya
donttellya

Reputation: 450

GENERATEFAKES of MS Fakes fails with CS1705 sporadically

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]
3>  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:

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]

Upvotes: 1

Views: 242

Answers (1)

donttellya
donttellya

Reputation: 450

As stated in my comment above, I have found a workround for our situation:

Within the project that should be faked we have introduced last week a c# tuple in an interface method signature. I have changed the tuple to a class so now the interface does not need the c# tuple anymore. The build succeeds but the three warnings I mentioned in the OP at the end of the post are still there.

Upvotes: 0

Related Questions