We have a multi target (net472 and netstandard2.0) class library referencing latest linq2db.SQLite 5.4.1 nuget. That library is referenced in net472 WPF application and net6.0 console application.
linq2db.SQLite nuget depends on System.Data.SQLite.Core 1.0.118 nuget that depends on Stub.System.Data.SQLite.Core.NetFramework 1.0.118 nuget which has Stub.System.Data.SQLite.Core.NetFramework.targets file.
My local builds were working fine while same builds on TeamCity has sporadic error during a clean because the files \x86\SQLite.Interop.dll and \x64\SQLite.Interop.dll are in use by another process. It is failing on a clean operation defined in that targets file:
<Target Name="CleanSQLiteInteropFiles"
Condition="'$(CleanSQLiteInteropFiles)' != 'false' And
'$(OutDir)' != '' And
HasTrailingSlash('$(OutDir)') And
Exists('$(OutDir)')">
<!--
NOTE: Delete "SQLite.Interop.dll" and all related files, for every
architecture that we support, from the build output directory.
-->
<Delete Files="@(SQLiteInteropFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
According to this that is because multi target projects are built in parallel by Visual Studio. I've followed this recomendations and added following properties into my library .csproj:
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
\x86\SQLite.Interop.dll and \x64\SQLite.Interop.dll are now listed in my solution explorer as content files
But sporadic error on TeamCity still exists and looks like CleanSQLiteInteropFiles target still execute.
What is wrong with my setup?
With help of msbuild MySolution.sln /t:Clean -fl -flp:logfile=d:\clean.log;verbosity=diagnostic
I've found that CleanSQLiteInteropFiles target was executed also while cleaning both applications, depending on my library. After setting <PackageReference Include="linq2db.SQLite" Version="5.4.1" PrivateAssets = "all" /> that target started to execute only for my library. So the final solution is combination of 4 properties
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
and PrivateAssets=all
for linq2db.SQLite nuget.