当引用的项目需要时,SQLite.Interop.dll 文件不会复制到项目输出路径 [英] SQLite.Interop.dll files does not copy to project output path when required by referenced project

查看:101
本文介绍了当引用的项目需要时,SQLite.Interop.dll 文件不会复制到项目输出路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2015 中使用 System.Data.SQLite 核心版本: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

推荐答案

推荐的解决方案 这里 是在你的包\System.Data.SQLite.Core.1.0.98.1\build\[你的框架版本这里]文件夹包含

The recomended solution as doumented here is to create a System.Data.SQLite.Core.targets.user in your packages\System.Data.SQLite.Core.1.0.98.1\build\[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 项目样式中,在嵌套项目和包之间解决依赖项的方式发生了变化.在构建过程中,资产被解析并生成一个 obj\project.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 obj\project.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 文件不会复制到项目输出路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆