我想为我的dotnet核心项目添加代码分析(FxCop,而不是StyleCop),它的目标是netcoreapp1.1框架.我知道FxCop是在MSBuild中构建的,但是当我启用它时,我不断收到错误:
1> MSBUILD:错误:CA0055:无法识别'C:\ Dev\easycube\EasyCube.Authentication\bin\Debug \netcoreapp1.1\EasyCube.Authentication.dll'的平台.1> MSBUILD:错误:CA0052:未选择任何目标.
然后我发现有针对dotnet核心分析器Microsoft.NetCore.Analyzers的Nuget包,但我不知道如何使用它.有谁知道如何在项目上进行设置?
谢谢.
msbuild code-analysis .net-core asp.net-core visual-studio-2017
我目前正在使用 Mediatr 3 中的管道行为进行请求验证。如果发生任何失败,我遇到的所有示例都会抛出 ValidationException,而不是这样做,我想返回带有错误的响应。任何人都知道如何做到这一点?
下面是验证管道的代码:
public class ValidationPipeline<TRequest, TResponse> :
IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
{
private readonly IEnumerable<IValidator<TRequest>> _validators;
public ValidationPipeline(IEnumerable<IValidator<TRequest>> validators)
{
_validators = validators;
}
public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next)
{
var failures = _validators
.Select(v => v.Validate(request))
.SelectMany(result => result.Errors)
.Where(f => f != null)
.ToList();
if (failures.Any())
{
throw new ValidationException(failures);
}
return next();
}
}
Run Code Online (Sandbox Code Playgroud)
注意:我发现这个问题使用 CQRS 处理中介管道中的错误/异常?我对答案的第一个选项感兴趣,但没有明确的例子说明如何做到这一点。
这是我的响应类:
public class ResponseBase : ValidationResult
{
public ResponseBase() : base() …Run Code Online (Sandbox Code Playgroud)