问题描述
我的项目结构
- A.dll,它通过NuGet安装了PostSharp并使用它.
- B.exe,它引用A并且不使用PostSharp.
我创建了一个测试解决方案,以查看是否可以重现该问题,并且错误消失了,因此它似乎是原始项目中的其他一些构建时过程.我还不知道.
I created a test solution to see if I could recreate the issue, and the error went away, so it appears to be some other build-time process in the original project. I don't know yet what.
我的问题
当前,这会导致B的编译错误.
Currently this causes a compilation error for B.
将PostSharp安装到B会引起新的警告.
Installing PostSharp to B causes a new warning.
如果我在项目属性中禁用PostSharp,现在会出现此错误.
If I disable PostSharp in the project properties, I now get this error.
这来自RequiresPostSharp.cs,该文件安装在每个PostSharp项目中.
This comes from RequiresPostSharp.cs, which is installed in every PostSharp project.
我的目标
我需要消除所有错误和警告.
I need to eliminate all errors and warnings.
我建议的解决方案
我认为,如果我可以消除第一个错误,并且不需要将PostSharp添加到B,一切都会好起来的.我不知道如何解决它.
I think if I can eliminate the first error and the need to add PostSharp to B, everything will be fine. I don't know how to fix it though.
我的问题
- 不是正确的/推荐的解决方案,不是将PostSharp安装到B,并修复第一个错误?
- 如果是这样,我该怎么做?如果没有,我将如何寻求适当的解决方案?
- Is the correct/recommended solution to not install PostSharp to B, and fix the first error?
- If so, how do I do this? If not, how would I go about the proper solution?
推荐答案
当项目 B 是 WPF应用程序时,可以重现所描述的生成错误.在这种情况下,问题将由XAML编译器引起-它试图加载依赖项( A )引用的程序集,但如果失败则失败.
The described build error can be reproduced when the project B is WPF application. In this case the problem will be caused by the XAML compiler - it tries to load assemblies referenced by your dependencies (A) and fails if not successful.
为避免生成错误,您还需要向 B 项目中添加PostSharp引用.您当然会收到上述警告消息.
To avoid the build error you need to add PostSharp reference to your B project as well. You will, of course, get the mentioned warning message then.
从版本 3.1 开始,PostSharp不再将 RequiresPostSharp.cs 文件添加到您的项目中,而是在msbuild脚本中执行验证.因此,您可以在项目 B 属性中安全地禁用PostSharp.这样,您将避免出现错误和警告消息.
Starting with version 3.1, PostSharp does not add RequiresPostSharp.cs file to your project anymore, and performs validation inside msbuild script instead. Thus, you can safely disable PostSharp in the project B properties. This way you will avoid both error and warning messages.
这篇关于无法解析对程序集"PostSharp"的依赖关系,因为该程序集尚未预加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!