Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageReference ignores $Platform condition #7868

Closed
kjbartel opened this issue Mar 12, 2019 · 2 comments
Closed

PackageReference ignores $Platform condition #7868

kjbartel opened this issue Mar 12, 2019 · 2 comments
Labels

Comments

@kjbartel
Copy link

kjbartel commented Mar 12, 2019

Details about Problem

NuGet product used (VS UI | Package Manager Console | dotnet.exe):

dotnet.exe --version (if appropriate): 3.0.100-preview3-010431

VS version (if appropriate): 16.0.0 Preview 4.1 SVC1 / 15.9.8

Detailed repro steps so we can see the same problem

  1. Create new C# project:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp3.0;netcoreapp2.2;net472</TargetFrameworks>
    <Platforms>x64;x86</Platforms>
  </PropertyGroup>

  <!--<ItemGroup Condition="'$(Platform)' == 'x64'">-->
  <!--<ItemGroup Condition="'$(Platform)' == 'x64' AND ('$(TargetFramework)' == 'netcoreapp3.0' Or '$(TargetFramework)' == 'netcoreapp2.2')">-->
  <ItemGroup Condition="'$(TargetFramework)' != 'net472' AND '$(Platform)' != 'x86'">
      <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-27413-02" />
  </ItemGroup>
</Project>
  1. Try to publish x86:
    dotnet publish -c Release -f netcoreapp3.0 -r win-x86

  2. Error:
    C:\Users\Me.nuget\packages\microsoft.dotnet.ilcompiler\1.0.0-alpha-27413-02\build\Microsoft.NETCore.Native.Publish.targets(65,5): error : win-x86 not supported yet. X86 runtime build fails dotnet/corert#4589 [C:\Development\Test\Test.csproj]

The commented out conditions all don't work. Either they result in both x86 and x64 builds trying to use the referenced package or neither of them using the referenced package. Either way it seems impossible to specify a PackageReference specific to the platform. Also tried adding the condition on the PackageReference rather than ItemGroup with the same results.

@bichuga
Copy link

bichuga commented May 7, 2019

To summarize, even with the condition "false", the package will be imported.

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp3.0;netcoreapp2.2;net472</TargetFrameworks>
    <Platforms>x64;x86</Platforms>
  </PropertyGroup>
  <ItemGroup Condition="false">
      <PackageReference Include="MyPackage" Version="1.0.0" />
  </ItemGroup>
</Project>

We found that we can work around this issue by putting the packagereference in a different file, and making the import of the file conditional.

Separate file: packagerefs.targets

<Project Sdk="Microsoft.NET.Sdk">    
  <ItemGroup>
      <PackageReference Include="MyPackage" Version="1.0.0" />
  </ItemGroup>
</Project>

Project file:

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp3.0;netcoreapp2.2;net472</TargetFrameworks>
    <Platforms>x64;x86</Platforms>
  </PropertyGroup>
  <Import Project="packagerefs.targets" Condition="false" />
</Project>

@nkolev92
Copy link
Member

nkolev92 commented Aug 7, 2019

Closing this as duplicate of #5895.

TargetFramework is the only project configuration pivot support.

Platform/Architecture/Configuration and the likes are not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants