Ian*_*son 3 .net fxcop automapper portable-class-library
我很难说服FxCop 10.0来分析引用AutoMapper的程序集.
我创建了一个简单的类库,通过NuGet引用了AutoMapper,并添加了以下代码:
using System;
namespace ClassLibrary4
{
public class Class1
{
public void Foo()
{
AutoMapper.Mapper.CreateMap<Obj1, Obj2>()
.ForMember(x => x.Name, opt => opt.Ignore());
}
}
public class Obj1
{
public string Name { get; set; }
}
public class Obj2
{
public string Name { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用FxCop 10.0通过命令行分析程序集,并收到消息:
无法加载C:\ Users\inelson\Documents\Visual Studio 2013\Projects\ClassLibrary4\ClassLibrary4\bin\Debug\ClassLibrary4.dll.
注意:找不到一个或多个引用的程序集.使用'/ directory'或'/ reference'开关指定其他程序集引用搜索路径.
未解决的参考是System.Core版本2.0.5.0.
为了隔离问题,我删除了.ForMember方法调用,将Foo()简单地删除:
public void Foo()
{
AutoMapper.Mapper.CreateMap<Obj1, Obj2>();
}
Run Code Online (Sandbox Code Playgroud)
和FxCop 10.0现在愉快地分析组装!
使用.ForMember方法导致FxCop分析失败的原因是什么?
请注意,我遇到与.NET Framework版本4.0,4.5或4.5.1以及AutoMapper 3.0.0和3.1.0相同的行为.
确保输出目录中存在AutoMapper.dll(在您的情况下,它是C:\ Users\inelson\Documents\Visual Studio 2013\Projects\ClassLibrary4\ClassLibrary4\bin\Debug)
更新: 这是Portable Libraries和FxCop的一个众所周知的问题.请看看答案:
这个问题也在AutoMapper bugtracker中讨论过.
更新2: 我很确定问题出现是因为FxCop独立版本不支持.NET 4.5和可移植类库.您可以在Visual Studio用户语音上投票给出适当的建议.
您是否尝试通过Visual Studio运行代码分析?
更新3: 我尝试运行安装了Visual Studio 2012的FxCopCmd.exe的11.0.50727.1版本(我发现它在C:\ Program Files(x86)\ Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop)和它似乎工作.
此外,我尝试在Visual Studio 2012中运行代码分析,它也有效.
归档时间: |
|
查看次数: |
2192 次 |
最近记录: |