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

♀尐吖头ヾ 提交于 2020-01-02 01:36:27

问题


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?


回答1:


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>



来源:https://stackoverflow.com/questions/49140203/error-the-extern-alias-snh-was-not-specified-in-a-reference-option-in-a-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!