-
Notifications
You must be signed in to change notification settings - Fork 252
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
Nuget conditioning on $(Configuration) is not working #5895
Comments
To work with other conditions you will need to handle them yourself by passing the extra property values to restore, and ensuring that restore is done appropriately before each build. |
Closed as WontFix? |
The workaround is to run Any custom parameters you pass to build must also be passed to restore. If you do that conditioning on configuration works fine, it just isn't possible to run 1 restore and then N builds on N different configurations without restoring again. |
How can this be applied with the Visual Studio build and debug experience? |
Try using a Choose/When instead of a Condition to select the PackageReference. |
Works great with Choose/When! Thank you! |
@kulov - what kind of project were you needing to choose/when to make it work inside of VS?
|
It is Visual Studio 2017, v15.4.4 no other specifics other that I want to load one specific dll on one configuration and load 5 other dlls if the configuration differs from the first. |
The Choose/When workaround works, though I wonder if this is going to be the official way to do it, or will there be an update to simply utilize the Condition attribute on the element itself? It's strange that Choose/When w/ Condition works but just a Condition on ItemGroup or PackageReference does not work. |
1 similar comment
The Choose/When workaround works, though I wonder if this is going to be the official way to do it, or will there be an update to simply utilize the Condition attribute on the element itself? It's strange that Choose/When w/ Condition works but just a Condition on ItemGroup or PackageReference does not work. |
Hi Martin @kulov , can you share your csproject and packages.config I want to learn how to use choose/when to restore include different versions of the NuGet packages my project need |
Hi @egarim, Edit your csproj file and put the ItemGroup section that has your reference into Choose/When/Otherwise condition. The example below shows how to load assembly reference compiled locally on your disk vs assembly reference as a nuget package. You will need to create build configuration DebugLocal also for your project/solution in order to get it working.
|
@kulov I can't seem to get the condition to work. What version of VS are you using? |
@Hviid, the only problem so far I found was that $(Configuration) is not populated for the Choose/When clause when running Visual Studio Build step in Azure DevOps. |
I'm passing additional parameters via
|
Conditioning does not work in Azure DevOps when generating NuGets from projects with conditional references. E.g: in csproj we have package references such as When the nupkg is generated, in the .nuspec file we can always see a dependency to ProjectB, even when building with 'Debug' passed to msbuild: /p:configuration="Debug" The frustrating thing is that running the same msbuild command locally, the .nuspec is generated correctly, meaning the condition is evaluated correctly and we see a dependency to ProjectA. |
@Gabriel-Lacatus If you are building on Linux then case-sensitivity matters. Please try |
To close a loop here: There's an environment variable you can set that will apply extra msbuild args to the
You can add this as a pipeline variable in azure. Shove in See |
Here's another way of conditionally using packages
|
…er "Condition" handling for PackageReference entriers in csprojs gh-issue: NuGet/Home#5895 removing Microsoft.Data.SqlClient package
…er "Condition" handling for PackageReference entriers in csprojs gh-issue: NuGet/Home#5895 removing Microsoft.Data.SqlClient package
< PackageReference Include="Newtonsoft.json" Version="9.0.1" Condition="'$(Configuration)' == 'Debug'" / >
I am trying to keep one nuget package in my project for debug configuration, but it is still there even for release.
The text was updated successfully, but these errors were encountered: