Skip to content

Improvement: Handle platform specific assemblies (x86, x64 etc) with msbuild conditionals #8573

@sipsorcery

Description

@sipsorcery

Lots of us are having issues using nuget to package platform specific assemblies (#8435, #1221 etc). The crux of the problem is that while the platform specific artifacts can be packaged with nuget if the assembly reference(s) is platform specific there is no clean way to set it in the consuming project file.

To illustrate the problem my partial nuspec is:

<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
    <metadata>
   ....
    <references>
    <reference file="SIPSorceryMedia.dll" />
      </references>
    </metadata>
    <files>
      <file src="x86\Release\SIPSorceryMedia.dll" target="lib\net47" />
      <file src="SIPSorceryMedia.targets" target="build\SIPSorceryMedia.targets" />
      <file src="SIPSorceryMedia.props" target="build\SIPSorceryMedia.props" />
      <file src="x64\Release\*.dll" target="build\x64" />
      <file src="x86\Release\*.dll" target="build\x86" />
    </files>
</package>

The subsequent reference that ends up in a consuming project files is:

<Reference Include="SIPSorceryMedia, Version=1.1.7192.37613, Culture=neutral, processorArchitecture=x86">
  <HintPath>packages\SIPSorceryMedia.1.7.2\lib\net47\SIPSorceryMedia.dll</HintPath>
</Reference>

I have found no way to be able to override the hint path in that reference with the use of platform specific overrides in a .props or .targets file. For example if msbuild accepted an override on the hint path of the original reference it would be possible to use the example SIPSorceryMedia.props file shown below. Unfortunately it doesn't work.

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Reference Include="SIPSorceryMedia, Version=1.1.7192.37613, Culture=neutral, processorArchitecture=x64" Condition="'$(Platform)' == 'x64' or '$(Platform)' == 'AnyCPU'">
      <HintPath>packages\SIPSorceryMedia.1.7.2\build\x64\SIPSorceryMedia.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

But what does work is if the reference inserted into the project file has a platform specific condition:

<Reference Condition="'$(Platform)' == 'x86' Include="SIPSorceryMedia, Version=1.1.7192.37613, Culture=neutral, processorArchitecture=x86">
  <HintPath>packages\SIPSorceryMedia.1.7.2\lib\net47\SIPSorceryMedia.dll</HintPath>
</Reference>

Suggested Improvement

The suggestion is if nuspec file references could be specified as:

<file src="x86\Release\SIPSorceryMedia.dll" target="lib\x86\net47" />
<file src="x64\Release\SIPSorceryMedia.dll" target="lib\x64\net47" />

Then the references could be added to the consuming project as shown below and which builds correctly when the msbuild platform is specified:

<Reference Include="SIPSorceryMedia, Version=1.1.7192.37613, Culture=neutral, processorArchitecture=x86" Condition="'$(Platform)' == 'x86'">
  <HintPath>packages\SIPSorceryMedia.1.7.2\build\x86\SIPSorceryMedia.dll</HintPath>
</Reference>
<Reference Include="SIPSorceryMedia, Version=1.1.7192.37613, Culture=neutral, processorArchitecture=x64" Condition="'$(Platform)' == 'x64'">
  <HintPath>packages\SIPSorceryMedia.1.7.2\build\x64\SIPSorceryMedia.dll</HintPath>
</Reference>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution:QuestionThis issues appears to be a question, not a product defect

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions