简体   繁体   中英

MSBuild process and NuGet packages

Background Information

I am making a chat bot. My solution currently contains 4 projects. 1 project is a console application (and my start up project), the other 3 are class library projects. The console app is intended to be extremely light (one class with a static main method that starts the bot). I am trying to contain all the logic and dependencies inside the bot class library and some supporting libraries.

My Issue

My bot is currently backed by a SQLite database. 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:
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. 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).

The Question

How can I go about getting the proper dll's copied to the correct location during the build process? I would like to avoid adding a reference to the System.Data.SQLite NuGet package in the console app. 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.

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). You can also set it to the ..\\..\\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.
  • 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).

Actually you have more options, these are easier to implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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