无法删除文件 SQLite.Interop.dll,尝试清理多目标(net472 和 netstandard2.0)项目时拒绝访问路径 ''

问题描述 投票:0回答:1

我们有一个多目标(net472 和 netstandard2.0)类库,引用最新的 linq2db.SQLite 5.4.1 nuget。该库在 net472 WPF 应用程序和 net6.0 控制台应用程序中引用。

linq2db.SQLite nuget 依赖于 System.Data.SQLite.Core 1.0.118 nuget,该 nuget 依赖于具有 Stub.System.Data.SQLite.Core.NetFramework 的 Stub.System.Data.SQLite.Core.NetFramework 1.0.118 nuget。目标文件。

我的本地构建工作正常,而 TeamCity 上的相同构建在清理过程中出现偶发错误,因为文件 \x86\SQLite.Interop.dll 和 \x64\SQLite.Interop.dll 正在被另一个进程使用。该目标文件中定义的干净操作失败:

  <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>

根据this,这是因为多目标项目是由 Visual Studio 并行构建的。 我已遵循 this 建议并将以下属性添加到我的库 .csproj 中:

<PropertyGroup> 
    <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
    <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
    <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
    <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>

\x86\SQLite.Interop.dll 和 \x64\SQLite.Interop.dll 现在作为内容文件列在我的解决方案资源管理器中 enter image description here

但是 TeamCity 上的零星错误仍然存在,看起来像 CleanSQLiteInteropFiles 目标仍在执行。

我的设置有什么问题?

sqlite nuget teamcity system.data.sqlite linq2db
1个回答
0
投票

msbuild MySolution.sln /t:Clean -fl -flp:logfile=d:\clean.log;verbosity=diagnostic
的帮助下,我发现 CleanSQLiteInteropFiles 目标在清理两个应用程序时也被执行,具体取决于我的库。为 linq2db.SQLite nuget 设置
PrivateAssets=all
后,该目标开始仅针对我的库执行。所以最终的解决方案是 4 个属性的组合

<PropertyGroup> 
    <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
    <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
    <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
    <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>

PrivateAssets=all
用于 linq2db.SQLite nuget。

© www.soinside.com 2019 - 2024. All rights reserved.