gpt4 book ai didi

microsoft-fakes - 错误 CS0430 : The extern alias 'snh' was not specified in a/reference option [Up. UnitTests\obj\x64\Debug\Fakes\wsc\f.csproj]

转载 作者:行者123 更新时间:2023-12-02 04:27:44 27 4
gpt4 key购买 nike

单元测试项目 Up.UnitTests 在构建期间失败,并出现此构建错误

错误 CS0430:未在/reference 选项中指定外部别名“snh”错误 CS0234:命名空间“snh”中不存在类型或命名空间名称“System”(是否缺少程序集引用?)

命名空间“snh”中不存在类型或命名空间名称“System”

我猜测上述错误是由于 System.Net.Http 引起的。跟版本不同有关系吗?如何解决这个问题。任何帮助将不胜感激。

最佳答案

我也遇到了这个 CS0430 错误。在我的场景中,问题是由于更新 NSubstitute 引起的依赖性引起的。我像下面这样更新了我的 *.fakes 文件以添加诊断,并看到问题是 System.Net.Http 就像您观察到的那样。

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="ClassLibrary1"/>
</Fakes>

在此之后,我试图通过慢慢删除新的依赖项来找到问题的根本原因,并发现当 System.Threading.Tasks.Extensions Nuget 引用存在时,我会得到构建错误。在升级过程中,NSubstitute 添加了 System.Threading.Tasks.Extensions。在你的场景中,它可能是一个类似的依赖问题,它与 System.Net.Http 没有直接关系。

更新:我找到了this issue on the dotnet/sdk repo解决了这个问题。在您的测试项目中,添加以下 Directory.Build.targets。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="PrivateFakesAfterFacadesSwitch"
Condition="'$(ImplicitlyExpandNETStandardFacades)' == 'true' and $(AssemblyName.EndsWith('.Fakes'))"
AfterTargets="ImplicitlyExpandNETStandardFacades" DependsOnTargets="ImplicitlyExpandNETStandardFacades">

<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>

</Target>

</Project>

关于microsoft-fakes - 错误 CS0430 : The extern alias 'snh' was not specified in a/reference option [Up. UnitTests\obj\x64\Debug\Fakes\wsc\f.csproj],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52267170/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com