Open andrekoehler opened 4 years ago
What happens if instead of using the HintPath, you use the path you want directly in the itemspec, ie:
<Reference Include="libs\x64\netstandard1.0\MyLib.dll" />
@dsplaisted
What happens if instead of using the HintPath, you use the path you want directly in the itemspec, ie:
<Reference Include="libs\x64\netstandard1.0\MyLib.dll" />
Your suggestion works perfectly, thank you!
I had no idea we could just specify the path to the assembly directly in the "Include" attribute, because when adding a reference via Visual Studio, it always adds HintPath for that.
What happens if instead of using the HintPath, you use the path you want directly in the itemspec, ie:
<Reference Include="libs\x64\netstandard1.0\MyLib.dll" />
Solved it for me too! .NET 7.0 MAUI project didn't work with HintPath
but this worked perfectly.
It takes me a day to find this solution.
The issue still persists with .NET 7.
In .NET 7, this from https://github.com/dotnet/msbuild/issues/3784 might also work:
<PropertyGroup>
<AssemblySearchPath_UseCandidateAssemblyFiles>false</AssemblySearchPath_UseCandidateAssemblyFiles>
</PropertyGroup>
Versions
Microsoft Windows [Version 10.0.18363.720] Microsoft Visual Studio Community 2019, Version 16.5.0 dotnet --version => 5.0.100-preview.1.20155.7 Also occurs with 3.1 LTS SDK
How to reproduce:
MyLib represents any assembly that only exists for x86/x64 but not for Any CPU. This is the case for some C++/CLI assemblies I got from a vendor of USB cameras. MyLib is configured to store the built assemblies inside the MyApp folder. There is no ProjectReference, only Project Build Order to build MyLib before MyApp. After building MyLib, the files look like this:
The reason for this is because the build system ignores the HintPath which points to the x86 version of the assembly and instead uses the x64 version of the assembly, probably because the string "x64" is sorted before "x86". I used ILSpy to verify that "Bug\MyApp\bin**x86\Debug\netcoreapp3.1\MyLib.dll" is indeed the x64** version.
The issue also occurs when using MSBuild from the command line, so it is no specific to Visual Studio:
Failed Workarounds
ProcessorArchitecture
to the names of the references: Before:<Reference Include="MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null>
After:<Reference Include="MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, ProcessorArchitecture=Amd64">
Successful Workarounds
<HintPath>
accordingly.