Reputation: 2673
I have a .net core library project and another Asp.net core project referencing this library project.
The library project references an assembly that has x64 and x86 versions and I want to reference the version according to the PlatformTarget property value.
I've seen this question and already used their solution except that I'm using PlatformTarget instead of creating a custom property, here is project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="STPadLibNet, Version=8.4.3.0, Culture=neutral, PublicKeyToken=a0c5b3c72d40bbc6">
<HintPath>$(PlatformTarget)\STPadLibNet.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
The assembly I'm trying to reference is called STPadLibNet, 64bit version is located in x64 folder in Project directory and 32bit version is located in x86 folder.
For some reason dotnet build
always resolves to x64 folder even if the platform is set to x86 resulting in BadImageFormatException at application startup.
I've read about assembly probing and I now understand that when assembly resolver finds the assembly under Project directory or its subdirectories it ignores the HintPath, I tried using different file name for dll like STPadLibNetx64.dll for the 64-bit version and STPadLibNetx86.dll for the 32-bit version and reference the correct version like this:
<HintPath>STPadLibNet$(PlatformTarget).dll</HintPath>
For some reason the dll file is copied to my library project output directory but it's not copied to the asp.net core project output directory resulting in Assembly not found exception at startup, Also Rider(the IDE I use) shows that the assembly is not resolved by MSBuild.
So how to tell dotnet build to use HintPath ? or how to reference the correct version of the assembly according to PlatformTarget?
Notes:
Upvotes: 1
Views: 1080
Reputation: 2673
In The End, I moved x86 and x64 folders containing STPadLibNet.dll outside the Project Directory to the Solution Directory, this way HintPath is respected again.
Upvotes: 1