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

Support additional PackageReference conditions such as $(Configuration). #6226

Closed
myermian opened this issue Nov 27, 2017 · 4 comments
Closed
Labels
Functionality:Restore Resolution:Duplicate This issue appears to be a Duplicate of another issue

Comments

@myermian
Copy link

Details about Problem

  • Microsft Visual Studio Enterprise 2017 (Version 15.4.1)
  • NuGet Package Manager 4.4.0
  • Microsoft Windows 10 Enterprise

Detailed repro steps so we can see the same problem

  1. Create a new project (any will do, used console application as an example)
  2. Add a package using the PackageReference format.
  3. Modify the csproj and add a condition to only include the package if the configuration is set to Debug.

According to the Microsoft Documentation (https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files) under the Comments, someone pointed out that the condition attribute only applies to TargetFramework and not Configuration (or any other condition). The MSFT member suggested posting an issue back in July, but I don't think anyone created an issue since this still does not work and I could not find any related issues when doing a search through the issues (unless I missed it).

Kraig_Brockschmidt-MSFT Jul 17, 2017
@jakub At present, the only supported condition is TargetFramework. This is because the project.assets.json file can contain packages for multiple target frameworks but not multiple configurations or other property values.

Being able to restore packages on conditions other than TargetFramework would be helpful, especially when mixing in floating versions. My original goal was to pull in the highest version on Release and to pull in the highest prerelease (CI version) on Debug.

<PackageReference Include="Utils" Version="1.*" Condition="'$(Configuration)' == 'Release'" />
<PackageReference Include="Utils" Version="1.0.0-*" Condition="'$(Configuration)' == 'Debug'" />

Another (unrelated) item that is a bit of a letdown is that the floating versions don't support "1.-", but that's another issue (#912).

@emgarten
Copy link
Member

Duplicate of #5895

@emgarten emgarten marked this as a duplicate of #5895 Nov 28, 2017
@rohit21agrawal rohit21agrawal added Functionality:Restore Resolution:Duplicate This issue appears to be a Duplicate of another issue labels Nov 28, 2017
@rohit21agrawal rohit21agrawal removed the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Nov 28, 2017
@rohit21agrawal
Copy link
Contributor

@myermian do the workaround suggested in #5895 work for you?

@rohit21agrawal rohit21agrawal added the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Nov 28, 2017
@myermian
Copy link
Author

The Choose/When workaround actually works. I'm curious why that works and just using a standard condition does not work, strange.

@mariusingjer
Copy link

The aforementioned workaround:

  <Choose> 
    <When Condition="'$(Configuration)' == 'Debug'">
      <ItemGroup>
        <PackageReference Include="Serilog.Sinks.File" Version="3.1.1" />
      </ItemGroup>
    </When>
  </Choose>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Restore Resolution:Duplicate This issue appears to be a Duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants