简体   繁体   English

MSBuild程序和NuGet程序包

[英]MSBuild process and NuGet packages

Background Information 背景资料

I am making a chat bot. 我正在做一个聊天机器人。 My solution currently contains 4 projects. 我的解决方案当前包含4个项目。 1 project is a console application (and my start up project), the other 3 are class library projects. 1个项目是控制台应用程序(也是我的启动项目),其他3个是类库项目。 The console app is intended to be extremely light (one class with a static main method that starts the bot). 控制台应用程序应非常轻巧(一类具有启动bot的静态main方法)。 I am trying to contain all the logic and dependencies inside the bot class library and some supporting libraries. 我正在尝试将所有逻辑和依赖项包含在bot类库和一些支持库中。

My Issue 我的问题

My bot is currently backed by a SQLite database. 我的漫游器当前由SQLite数据库支持。 To access this database I am using System.Data.SQLite , which I added to my solution using NuGet, when I go to run run and test my bot I get the following exception: 要访问此数据库,我使用System.Data.SQLite ,我使用NuGet将其添加到解决方案中,当我运行运行并测试我的机器人时,出现以下异常:
Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found.
After searching the Internet, I learned that the solution to this problem is to make sure the SQLite.Interop.dll is copied to the console app's output directory. 搜索Internet之后,我了解到此问题的解决方案是确保将SQLite.Interop.dll复制到控制台应用程序的输出目录。 Many have suggested that the easiest way to do this is just to add System.Data.SQLite as a dependency to that project using NuGet ( SQLite.Interop.dll is currently copied using a targets file provided by the NuGet package to the output folder of the referencing project). 许多人建议,最简单的方法就是使用NuGet将System.Data.SQLite添加为对该项目的依赖项(当前使用NuGet包提供的目标文件将SQLite.Interop.dll复制到该文件夹​​的输出文件夹中)。参考项目)。

The Question 问题

How can I go about getting the proper dll's copied to the correct location during the build process? 如何在构建过程中将正确的dll复制到正确的位置? I would like to avoid adding a reference to the System.Data.SQLite NuGet package in the console app. 我想避免在控制台应用程序中添加对System.Data.SQLite NuGet包的引用。 I am hoping there is a maintainable solution as I am thinking about releasing my code as an open source project and I don't want something like this to be a mystery like knowing that you must manually copy various dll's or anytime there is an update to the NuGet package you must make changes to build targets found in the package. 我希望有一个可维护的解决方案,因为我正在考虑将我的代码作为一个开放源代码项目发布,并且我不希望这样的事情成为一个谜,例如知道您必须手动复制各种dll或在有任何更新时NuGet软件包,您必须进行更改以构建在软件包中找到的目标。

Just make the single output directory where all of your components will be stored. 只需将所有组件存储在单个输出目录中即可。 You have only several project (assume that the all projects on the same hierarchy level), so you can 您只有几个项目(假设所有项目都在相同的层次结构级别上),因此您可以

  • go to the Project properties > Build > Output path , set it to ..\\..\\bin\\Debug\\ (depending on configuration). 转到Project properties > Build > Output path ,将其设置为..\\..\\bin\\Debug\\ (取决于配置)。 You can also set it to the ..\\..\\bin\\$(Configuration)\\ . 您也可以将其设置为..\\..\\bin\\$(Configuration)\\ That way the name of configuration will be used. 这样,将使用配置名称。
  • Also, you can manually edit the *.csproj files, modifying the <OutputPath> property the same way. 另外,您可以手动编辑* .csproj文件,以相同的方式修改<OutputPath>属性。
  • You can create Common.props file which could contain common properties for your projects: OutputPath , TargetFramework , Configuration properties , and so on (but you have to <Import Project="..\\..\\Common.props"> in all of your projects). 您可以创建Common.props文件,该文件可以包含项目的公共属性: OutputPathTargetFrameworkConfiguration properties等(但必须在所有目录中<Import Project="..\\..\\Common.props">您的项目)。

Actually you have more options, these are easier to implement. 实际上,您有更多选择,这些选择更易于实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM