起因
因爲需要排除某些文件不參與 SonarQube 的分析,所以需要對一些類進行特別的設置,
我是在項目的 csporj 中增加如下代碼:
之後運行,但是直接報錯了,錯誤信息如下:
Severity Code Description Project File Line Suppression State
Error NETSDK1022 Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'xxx.cs' SellerModel C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 295
從字面意思來看是重複編譯了,之所以重複是因爲 .net core 3.1 SDK 默認給我們把項目中的文件都編譯包含了
但是怎麼解決呢:
- 在
Include
之前增加Remove
,先移除再包含,這樣就可以解決,在大量類中需要修改少量類的編譯屬性時比較有用且方便
- 在
PropertyGroup
中增加<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
,這個可以關閉默認導入,這樣就需要我們手動導入所有需要編譯的類
各取所需吧,按照自己的需求來選擇怎麼處理。