问题描述
我在 Visual Studio 2015 中使用 System.Data.SQLite Core Version: 1.0.98.1 nuget 包.当我构建引用我的 System.Data.SQLite 包的项目时,它会分别复制两个文件夹(x86 和 x64)包含 SQLite.Interop.dll 到输出目录.但是,当我构建我的测试项目或引用前面提到的项目的任何其他项目时,这些文件夹不会被复制到父项目的输出目录,并且我在 SQLite.Interop.dll 上得到一个 DllNotFoundException.
I am using the System.Data.SQLite Core Version: 1.0.98.1 nuget package with Visual Studio 2015. When I build my project that references my System.Data.SQLite package, it copies two folders (x86 and x64) each containing a SQLite.Interop.dll to the output directory. However when I build my test project or any other project that references the previously mentioned project, these folders do not get copied to the the parent project's output directory, and I get a DllNotFoundException on the SQLite.Interop.dll.
注意:特别是当引用 System.Data.SQLite 的项目被另一个项目引用时
Note: this is specifically when the project referencing System.Data.SQLite is referenced by another project
推荐答案
推荐的解决方案为 doumented here 是在你的 packagesSystem.Data.SQLite.Core.1.0.98.1uild[你的框架版本中创建一个 System.Data.SQLite.Core.targets.user这里]文件夹包含
The recomended solution as doumented here is to create a System.Data.SQLite.Core.targets.user in your packagesSystem.Data.SQLite.Core.1.0.98.1uild[your framework version here] folder containing
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
</Project>
但如果您不想将包文件夹中的任何内容添加到源代码管理中,则可以直接将以下内容添加到项目文件中
But if you don't want to add anything in your packages folder to your source control, you can just add the following directly to your project file
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
SDK 风格项目更新
在新的 SDK 项目样式中,嵌套项目和包之间解决依赖关系的方式发生了变化.在构建过程中,资产被解析并生成一个 objproject.assets.json
文件,列出来自所有各种依赖项的资产.然后使用项目资产文件来确定需要导入哪些目标以及需要将哪些文件复制到输出目录.但是,从非直接依赖项中包含资产的方式有所不同.不导入非直接依赖项的 build
文件夹中的目标文件.旧的解决方法取决于将 System.Data.SQLite.Core.targets
导入到父项目中.直接依赖 System.Data.Sqlite
的项目可以通过将 PrivateAssets="none"
添加到 PackageImport
来覆盖此行为.您还需要将此添加到依赖项链中的每个 PackageImport 或 ProjectReference 中.但是,您不需要将其与之前的解决方法结合使用.
Update for SDK style projects
In the new SDK project style, there is a change in how dependencies are resolved across nested projects and packages. In the build process, assets are resolved and a objproject.assets.json
file is generated listing the assets from all the various dependencies. The project assets file is then used to determine what targets need to be imported and what files need to be copied to the output directory.There is, however a difference in how assets are included from non-direct dependencies. Target files from the build
folder of non-direct dependencies are not imported. The old workaround depends on System.Data.SQLite.Core.targets
getting imported into the parent project. Projects that directly depend on System.Data.Sqlite
can override this behavior by adding PrivateAssets="none"
to the PackageImport
. You will also need to add this to each PackageImport or ProjectReference` in your dependency chain. However, you won't need to combine this with the prior workaround.
TLDR
在直接引用 System.Data.Sqlite 的项目中,将 PrivateAssets="none"
添加到您的 PackageImport
In the project that directly references System.Data.Sqlite add PrivateAssets="none"
to your PackageImport
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" PrivateAssets="none"/>
对于你的依赖链中的每个项目,直到你的根项目,还要添加PrivateAssets="none"
For each project in your dependency chain up to your root project also addPrivateAssets="none"
<ProjectReference Include="..MyProject.csproj" PrivateAssets="none"/>
这篇关于引用项目需要时,SQLite.Interop.dll 文件不会复制到项目输出路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!