How to redirect probing for assemblies in .NET Core?

I have an ASP.NET Core MVC application that is located in App folder. And I'm not using Kestrel or IIS Express to run it. Rather we have an infrastructure that hosts that App folder directly in IIS and does more things to make our development environment very similar to our production environment (DevOps).

Things work just fine. When I build, the output goes into bin\Debug\netcoreapp2.0 folder and we have a Web.config file in which we have configured our AspNetCoreModule to load the entry DLL from that path.

Now I want to use ClosedXML, which has a dependency upon System.Drawing.Common library.

When I build and test my application, I have this error:

An assembly specified in the application dependencies manifest (App.deps.json) was not found:
package: 'System.Drawing.Common', version: '4.5.0-preview1-25914-04'
path: 'runtimes/win/lib/netcoreapp2.0/System.Drawing.Common.dll'

The point is, I have a bin\Debug\netcoreapp2.0 folder that hosts the application, and I can confirm that System.Drawing.Common is already copied there. Yet seems that MSBuild doesn't copy it to the intended bin\Debug\netcoreapp2.0\runtimes\win\lib\netcoreapp2.0 folder.

I can copy the requested library to the given folder, that is runtime/win/lib/netcoreapp2.0, and the app will work just fine.

I can add additional probing paths to my App.runtimeconfig.json.

I can change the searching path for this library in my App.deps.json to the same directory.

But these are all done manually.

How can I make the build process copy the dependencies to their correct locations?

Upvotes: 2

Views: 2408

Answers (1)

Eric Erhardt
Eric Erhardt

Reputation: 2476

You can use the Publish command to create your output directory. Either using dotnet publish from the command line, or in Visual Studio's Solution Explorer, right click your project -> Publish.

When you just Build your app, the dependent assemblies that come from NuGet packages stay in the NuGet cache folder. And when you F5/dotnet run your app they are loaded from the NuGet cache folder. But if you want your application folder to be ready to run in a different environment outside of VS/dotnet run, then you should be publishing your app.

Upvotes: 2

Related Questions