MrPurpleStreak
MrPurpleStreak

Reputation: 1557

Have visual studio copy x64 DLL or x86 DLL when building a C# project

We're building a C# app that uses an external DLL for Sqlite.NET. This is a .NET dll but it embeds a C dll inside it and so it comes in x86 and x64 flavours.

We add a reference to the x86 version in the project so when we build and run on x86 it's fine. Visual studio copies the dll to the bin folder and runs.

On x64 it still copies the x86 version of course and then when it runs it fails to load it. We get round this by temporarily setting our project to be x86 only, but ideally we'd like to tell visual studio to copy the correct version depending on which flavour of machine it is.

Any ideas how?

Upvotes: 2

Views: 2660

Answers (1)

Richard
Richard

Reputation: 109140

This can be done in MSBuild (i.e. you need to unload the project and edit the .csproj file).

Essentially add a property in the property groups that are conditional on the platform to identifier the path of the appropriate assembly, and then use that property in the references item group.

The answer is here: Conditional references in .NET project, possible to get rid of warning?

Upvotes: 2

Related Questions