Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "The extern alias 'snh' was not specified in a /reference option " in a C# test project using Microsoft Fakes

I have a C# test project that uses Microsoft fakes. An external library (abc.dll) that the project is referencing was recently updated to .net standard 2.0. After updating the abc.dll library reference to the latest version, the test project doesn't build any more and also doesn't generate the fake assembly for that library (dll). I see the following error in the generated .csproj file.

The external alias 'snh' was not specified in a /reference option

I looked at the generated .csproj file and the alias snh corresponds to System.Net.Http.

The test project is targeting .net 4.6.1 and I'm using latest VS 2017

Any idea how to solve this?

like image 665
MAK Avatar asked Mar 06 '18 21:03

MAK


1 Answers

This is currently an open issue with project's targeting .Net Framework 4.7.1 with a reference to netstandard libraries. It is being tracked here: https://github.com/dotnet/sdk/issues/2254.

I'll include the workaround which worked for me: For reference, the workaround posted for the Fakes issue is to put the following in Directory.Build.targets:

<ItemGroup Condition="'@(_NETStandardLibraryNETFrameworkLib)' != ''">
  <SnhReference Include = "@(_NETStandardLibraryNETFrameworkLib)" Condition="'%(_NETStandardLibraryNETFrameworkLib.FileName)' == 'System.Net.Http'" />

  <Reference Remove="%(SnhReference.FileName)" Condition="'@(SnhReference)' != ''"/>
  <Reference Include="%(SnhReference.FileName)" Condition="'@(SnhReference)' != ''">
    <HintPath>%(SnhReference.Identity)</HintPath>
    <Private>false</Private>
    <Aliases>snh</Aliases>
  </Reference>
</ItemGroup>

like image 66
Eric Grun Avatar answered Nov 07 '22 12:11

Eric Grun