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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With