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

我们两清 提交于 2019-12-05 02:43:42

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>

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