IL3002:在发布为单个文件时避免调用使用“RequiresAssemblyFilesAttribute”批注的成员

价值
规则 ID IL3002
类别 SingleFile
修复是中断或非中断 非中断性

原因

将应用发布为单个文件(例如,通过在项目中将属性设置为PublishSingleFiletrue),调用带有RequiresAssemblyFilesAttribute特性标注的成员与单文件操作不兼容。 这些调用不兼容,因为使用此属性注释的成员要求程序集文件位于磁盘上,并且嵌入在单文件应用中的程序集将加载内存。

示例:

[RequiresAssemblyFiles(Message="Use 'MethodFriendlyToSingleFile' instead", Url="http://help/assemblyfiles")]
void MethodWithAssemblyFilesUsage()
{
}
void TestMethod()
{
    // IL3002: Using member 'MethodWithAssemblyFilesUsage' which has 'RequiresAssemblyFilesAttribute'
    // can break functionality when embedded in a single-file app. Use 'MethodFriendlyToSingleFile' instead. http://help/assemblyfiles
    MethodWithAssemblyFilesUsage();
}

如何修复违规行为

使用“RequiresAssemblyFilesAttribute”属性标注的成员有一条消息,旨在提供有用的信息给以单文件形式发布软件的用户。 请考虑将现有代码调整为与属性的消息一致,或者删除违规的调用。

何时禁止显示警告

当现有代码已适应“RequiresAssemblyFilesAttribute”属性消息中概述的建议时,应禁止显示警告。