| 價值觀 | |
|---|---|
| 規則標識碼 | IL3002 系列 |
| 類別 | 單個檔 |
| 修正是破壞性或非破壞性 | 不間斷 |
原因
當您將應用程式發佈為單一檔案時(例如,在專案中將PublishSingleFile屬性設為true),呼叫使用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』 屬性訊息中所述的建議時,就適合隱藏警告。