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

NuGet.exe restore: allow specifying Solution Configuration to use for .sln, for example -Properties similar to pack. #7575

Open
KirillOsenkov opened this issue Dec 1, 2018 · 11 comments
Labels
help wanted Considered good issues for community contributions. Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Style:PackageReference Style:Packages.Config Type:Feature

Comments

@KirillOsenkov
Copy link

Details about Problem

NuGet product used: NuGet.exe

NuGet version (x.x.x.xxx): 4.9.1.5694

dotnet.exe --version (if appropriate): 2.2.0-preview1-007622

VS version (if appropriate): 15.9.2

OS version (i.e. win10 v1607 (14393.321)): Win10

Worked before? If so, with which NuGet version: not a regression

Detailed repro steps so we can see the same problem

Have an .sln file with two configurations: Debug and Release.
Have a project that only fails to build in Debug.

You should be able to restore nuget packages by specifying:
nuget restore My.sln /Configuration Release

Currently restore fails because nuget chooses the default (Debug) configuration which doesn't build.

Unfortunately the workaround of using msbuild /r /p:Configuration=Release or dotnet restore doesn't work because many solutions still include projects that have no understanding of NuGet, and so the Restore target isn't there.

@nkolev92
Copy link
Member

nkolev92 commented Dec 3, 2018

You can already achieve that with an environment variable.
https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables

NUGET_RESTORE_MSBUILD_ARGS

Furthermore in PackageReference NuGet itself does not use the Configuration when evaluating Package/ProjectReferences, so not sure relying on NuGet to play well with these Configuration conditions imports is a good idea.

@nkolev92 nkolev92 added Product:NuGet.exe NuGet.exe Style:Packages.Config Style:PackageReference Type:Feature WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Dec 3, 2018
@StingyJack
Copy link
Contributor

@nkolev92 - instead of specifically for a restore, perhaps this is for installing a development or debug tool inclusion? Some additional logging or tracing that only needs to be present for debug configuration, or even something like non-minified JS for a web project. Or maybe the opposite; something that needs to only be included on a release or production build.

@mletterle
Copy link

There are cases where MSBuild properties need to be set in order to have a valid parsable project file, while the environment variable works having a generic way to specify multiple msbuild properties on the command line would be handy. Doing nuget restore -Property Configuration='Release' -Property CustomImportPath='C:\SomeDir\Imports' would be handy.

@nkolev92 nkolev92 added Triage:NeedsTriageDiscussion help wanted Considered good issues for community contributions. and removed WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Dec 31, 2019
@nkolev92 nkolev92 added this to the Backlog milestone Dec 31, 2019
@kulov
Copy link

kulov commented Apr 14, 2020

This issue is reported in 2018.
#5895 (comment)
You can have workaround with Choose/When/Otherwise msbuild constructs.
But it fails to work in Azure DevOps as NuGet defaults to Otherwise condition and there is no way to build When construct on specific project configuration.

@kulov
Copy link

kulov commented Apr 14, 2020

I managed to workaround the issue by setting NUGET_RESTORE_MSBUILD_ARGS to /p:Platform=$(BuildPlatform) /p:Configuration=$(BuildConfiguration) in my Azure DevOps pipeline. Without this NuGet parses all csproj files with no Platform value set and it defaults to Debug because of this msbuild line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

So with Choose/When/Otherwise in combination of NUGET_RESTORE_MSBUILD_ARGS I was able to run csproj files with conditional MSBuild ItemGroup elements in Visual Studio and in Azure DevOps.

It would be nice to be able to set properties via command line and also in AzDo NuGet step as @mletterle proposes.

@zkat zkat added Priority:2 Issues for the current backlog. and removed Triage:NeedsTriageDiscussion labels Apr 20, 2020
@zkat zkat removed this from the Backlog milestone Apr 20, 2020
@nkolev92 nkolev92 changed the title NuGet.exe: allow specifying Solution Configuration to use for .sln NuGet.exe restore: allow specifying Solution Configuration to use for .sln, for example -Properties similar to pack. Apr 20, 2020
@nkolev92
Copy link
Member

I think a Properties option like @mletterle suggests is the direction here instead of a configuration specific switch.

@KirillOsenkov
Copy link
Author

Yes, I'd love to have that. That would be a better and more general solution.

@nkolev92
Copy link
Member

Note that I'm not sure we'll be able to get this to this soon, but we'd be open to taking a contribution.

@kulov
Copy link

kulov commented Apr 21, 2020

One thing worth noting is that selecting configuration using NUGET_RESTORE_MSBUILD_ARGS seems to work on individual project level and does not respect the solution configuration setup.
For example:
Lets say MyApp.sln has configuration called ReleaseSetup.
It also has project MyLib1.csproj with configuration ReleaseSetup and second project MyLib2.csproj with configuration Release.
Solution level configuration ReleaseSetup as specified in the .sln file is set to build MyLib1.csproj in ReleaseSetup configuration and MyLib2.csproj in Release configuration.
It seems right now that setting configuration ReleaseSetup with NUGET_RESTORE_MSBUILD_ARGS will basically crawl all individual projects and will try to restore packages using ReleaseSetup configuration.
However the specified desired configuration is set to Release on solution level therefore nuget will incorrectly try to restore ReleaseSetup in this case.

@nkolev92
Copy link
Member

@kulov

All you do when when you specify that env variable is that NuGet passes that to msbuild when evaluating projects.
Configuration is not a supported pivot for PackageReference based projects because MSBuildProjectExtensionsPath is not configuration based.

@kulov
Copy link

kulov commented Apr 21, 2020

Please ignore - it was related to something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Considered good issues for community contributions. Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Style:PackageReference Style:Packages.Config Type:Feature
Projects
None yet
Development

No branches or pull requests

7 participants