0

I try to consume from nuget that contains both x86 and x64 dlls, but my project is Any CPU. The problem is that sometimes I want to take the x86 and sometimes x64. The target file looks like this:

    <PropertyGroup>
        <CasosesPlatform Condition="'$(Platform)' == 'x86'">x86</CasosesPlatform>
        <CasosesPlatform Condition="'$(Platform)' != 'x86'">x64</CasosesPlatform>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="Casoses">
            <HintPath>$(MSBuildThisFileDirectory)..\runtimes\win-$(CasosesPlatform)\lib\$(Configuration)\Casoses.dll</HintPath>
        </Reference>
        <ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\runtimes\win-$(CasosesPlatform)\lib\$(Configuration)\Casoses.dll" />
    </ItemGroup>

Now, only x86 will take x86 so Any CPU will take the x64. What am I doing wrong? is there a better way to do this?

Thanks.

Itay Biju
  • 1
  • 1
  • MSBuild is a build time evaluation, but selecting the correct runtime is a run time thing. So, there's a mismatch between what you're trying to do and how you're trying to do it. If you're using SDK style projects, then I don't think you need to define your own targets. The SDK should do the right thing if you use the correct conventions. [Here's NuGet's docs on the runtimes folder](https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders). `$(Configuration)` (debug or release) is not valid for the conventions. – zivkan Apr 28 '19 at 15:34
  • https://stackoverflow.com/q/11934570/17034 – Hans Passant Apr 28 '19 at 16:44
  • I've edited the code to be easier to understand. I saw the links you sent. I try to avoid adding codes and logics to the projects. I want to install this nuget on each project and by the .targets file the projects will take the correct Platform. – Itay Biju Apr 29 '19 at 04:59
  • 1 Thing I've tried to do is adding another conditions: if platform is Any CPU and PreferedWin32 = true. but the problem is that PreferedWin32 is only for Application types and I have libraries projects. I really want to find solution close to this one so I won't need to change the projects. – Itay Biju Apr 29 '19 at 05:01
  • **Prefer32Bit :D – Itay Biju Apr 29 '19 at 05:08
  • AnyCPU means it might run either as 32-bit or 64-bit, so technically you have to copy both native libraries and at run time detect which one you need to use. Otherwise, I suggest stop using AnyCPU and use x86 and x64 processor configurations so that your MSBuild targets work. – zivkan Apr 29 '19 at 12:46
  • Hi zivkan thanks for answering. by runtime you mean I need to add a code section for deciding which dll I should link too? – Itay Biju Apr 30 '19 at 12:59

0 Answers0