Home: msbuild /restore works with Packages.Config

Created on 28 Aug 2019  路  14Comments  路  Source: NuGet/Home

Spec: Backporting PC to msbuild /restore

Details about Problem

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

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

Tracking issues

  • [x] Get the code working in usual scenarios #8676
  • [x] Write E2E tests: #8677
  • [x] Refactor into shared code #8678

Detailed repro steps so we can see the same problem

  1. Create a P.C project

  2. Try to restore using msbuild /restore

MSBuild Packages.Config Feature

All 14 comments

Dup of https://github.com/NuGet/Home/issues/6410 maybe.

I think that's the original ask and we should probably dup this one out for that one, or least make sure they're both closed when this is fixed.

@jeffkl Where is this documented?

I鈥檓 not sure, did you document this @zkat?

tracked as a doc issue linked on the bottom of this page: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets?source=docs#feedback

Whats the option though?

it is in the title of the issue:

image

馃憤 I should have clicked on the link! 馃槄

@zkat @rrelyea is there a way to specify the file if I want it to be different than packages.config? In my case I have to support a project in two different "modes"/"configurations" that rely on separate nuget packages.

@asklar
Not really.
packages.config discovery only works by convention, so either packages.config next to the project file or packages.$(MSBuildProjectName).config next to the project.

I always forget packages.$(MSBuildProjectName).config. Is this documented somewhere?

i searched our docs a bit...but didn't find it. you would think it could be listed here: https://docs.microsoft.com/en-us/nuget/reference/packages-config

@nkolev92 @rrelyea I was trying to stick myself in the middle to redirect to a different file and I can see the value of the itemgroups are getting updated successfully but the Restore task seems to ignore it, any idea how I may be able to work around it?

  <Target Name="FixUpPackagesConfigPath" DependsOnTargets="_GenerateRestoreProjectSpec" BeforeTargets="Restore" Returns="@(_RestoreGraphEntry)" >
    <ItemGroup>
      <_RestoreGraphEntry 
        Condition="'%(_RestoreGraphEntry.PackagesConfigPath)' != ''">
        <PackagesConfigPath>$([System.String]::Copy('%(_RestoreGraphEntry.PackagesConfigPath)').Replace('packages.config','packages.WinUI3.config'))</PackagesConfigPath>
      </_RestoreGraphEntry>
    </ItemGroup>
  </Target>

@nkolev92 @rrelyea hmm is this code it?
Why is the nuget task not respecting whatever it gets from msbuild? it'd be great if this could be fixed :)

Gen 1 of nuget uses Packages.Config.
It likely didn't use msbuild to find the config file...so the options are limited.
Can you solve in a more mainline way? (something that works with this code from 2015 and before?)

Was this page helpful?
0 / 5 - 0 ratings