Moq 库和 .NET Core 预览版 3.0

如何使 Moq 库与 .NET core Preview 3.x 一起使用?有可能吗?


具体来说,当我启用 Moq 时,与日志库发生冲突:


MyProjectTest.cs(25, 45): [CS1705] :


Assembly 'MyProject' with identity 'MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 

uses 'Microsoft.Extensions.Logging.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' 


which has a higher version than referenced assembly 


'Microsoft.Extensions.Logging.Abstractions' with identity

 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'


翻阅古今
浏览 79回答 1
1回答

江户川乱折腾

编辑:问题的更新版本与 无关Moq。您需要确保所有依赖项均已正确更新。Microsoft.Extensions.Logging.Abstractions没有被 引用Moq。Edit2:这里有一个示例。对的,这是可能的。当前版本(截至目前 4.12.0)支持 .NET-Standard 2.0。.NET-Core 3.0 完全支持这一点,因此您可以像往常一样使用它。var mock = new Mock<ISomeService>(MockBehavior.Loose); mock.Setup(someService => someService.IsValidString(it.IsAny<string>)    .Returns(true);
打开App,查看更多内容
随时随地看视频慕课网APP