.net Core 2.1无法在startup.cs中引用自动映射器 [英] .net core 2.1 can't reference automapper in startup.cs
问题描述
我在nugent面板中安装了
In my nugent panel, I installed
AutoMapper v7.0.1AutoMapper.extensions.microsoft.dependencyinjection v5.0.1
AutoMapper v7.0.1 AutoMapper.extensions.microsoft.dependencyinjection v5.0.1
在我的Startup.cs中,
In my Startup.cs,
我添加了
Services.AddAutoMapper();
Services.AddAutoMapper();
但是编译器给出了
Severity Code Description Project File Line Suppression State
Error CS1061 'IServiceCollection' does not contain a definition for 'AddAutoMapper' and no accessible extension method 'AddAutoMapper' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?) OPEApiService J:\Projects\OPEApiService\OPEApiService\Startup.cs 58 Active
我尝试清理,重建,关闭并重新打开VS.
I tried clean, rebuild, close and reopen VS.
感谢您的帮助.
谢谢
推荐答案
这可能是两个软件包之间的兼容性问题.如果您同时安装了AutoMapper和AutoMapper.extensions.microsoft.dependencyinjection程序包,请删除它们并仅添加AutoMapper.extensions.microsoft.dependencyinjection.它依赖于AutoMapper软件包.
This could be a compatibility issue between the two packages. If you have both the AutoMapper and AutoMapper.extensions.microsoft.dependencyinjection packages installed, remove them and add only the AutoMapper.extensions.microsoft.dependencyinjection. It has a dependency on the AutoMapper package.
我遇到了同样的问题,并且能够解决.
I had this same issue and was able to resolve it.
这篇关于.net Core 2.1无法在startup.cs中引用自动映射器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!