我有一个Visual 2015解决方案,我在该解决方案中复制和粘贴了我在Visual 2013项目中成功使用的许多PostSharp验证属性。
项目全部编译并成功运行。不幸的是,设计用来测试我的验证属性的单元测试失败了。通过调试,我发现我的任何属性都没有被运行。我已经确保了PostSharp包在项目引用和.xproj文件中的正确引用。
我的验证属性代码如下:
using System;
using PostSharp.Aspects;
using PostSharp.Reflection;
namespace Foo.Domain.Model.ValidationAttributes
{
/// <summary>
/// Validates the parameter to strictly not be null (empty and whitespace is valid). Throws a System.ArgumentNullException if assigned a null value.
/// </summary>
[Serializable]
public sealed class NotNullAttribute : LocationInterceptionAspect, ILocationValidationAspect<object>
{
public NotNullAttribute()
{
}
public override void OnSetValue(LocationInterceptionArgs args)
{
Exception ex = ValidateValue(args.Value, args.LocationName, args.Location.LocationKind);
if (ex != null)
{
throw ex;
}
args.ProceedSetValue();
}
public Exception ValidateValue(object value, string locationName, LocationKind locationKind)
{
return value == null ? new ArgumentNullException(locationName, string.Format("The parameter '{0}' may not be null.", locationName)) : null;
}
}
}我的project.json显示了添加的依赖项:
{
"version": "1.0.0-*",
"description": "MyProject Domain Class Library",
"tags": [ "MyProject" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"PostSharp": "4.1.21",
"PostSharp.Patterns.Common": "4.1.21",
"PostSharp.Patterns.Model": "4.1.21"
},
"frameworks": {
"net451": { }
}
}我的.xproj文件显示了添加的PostSharp目标(我已经检查它存在于路径中):
<Import Project="..\packages\PostSharp\4.1.21\tools\PostSharp.targets" />
从PostSharp文档来看,VS2015似乎是完全受支持的,但我似乎无法让这些方面发挥作用。在Visual 2015上启动和运行PostSharp需要做些什么吗?
发布于 2015-08-06 10:09:19
PostSharp目前不支持ASP.NET 5引入的新项目构建系统(这在兼容性页面中有提到)。当编译运行“内存中”时,就不会使用通常的MSBuild扩展点,也不会调用PostSharp。您可以尝试在VS中完全构建解决方案,并查看这些方面是否以这种方式应用。
PostSharp团队计划在即将推出的版本中为新的ASP.NET构建系统提供支持。
更新
ASP.NET 5连接器的预览已经在GitHub (https://github.com/postsharp/PostSharp.Dnx)上发布。在ASP.NET 5 RTM发布之前,这将是一个“正在进行的工作”。
https://stackoverflow.com/questions/31837047
复制相似问题