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

Package restore broken in VS2017, works from dotnet restore #5226

Closed
bradwilson opened this issue May 12, 2017 · 11 comments
Closed

Package restore broken in VS2017, works from dotnet restore #5226

bradwilson opened this issue May 12, 2017 · 11 comments
Labels
Product:VS.Client Resolution:ByDesign This issue appears to be ByDesign
Milestone

Comments

@bradwilson
Copy link

Details about Problem

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

  • 4.1.0.2450

dotnet.exe --version (if appropriate):

  • 2.0.0-preview1-005977

VS version (if appropriate):

  • Visual Studio 2017 (has repro'd with every version, and still repro's as of 15.3, 26510.0-preview)

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

  • Windows 10 v1703 (15063.296)

Worked before? If so, with which NuGet version:

  • Not since converting to VS2017 and SDK-style .csproj files.

Detailed repro steps so we can see the same problem

  1. Clone https://github.com/xunit/xunit (repros as of bce3c19b565ad5e81ea6b87eedb44db00315d9ff)

  2. Open xunit.vs2017.sln in Visual Studio 2017

  3. Right click on the solution and choose "Restore NuGet Packages". Output Windows shows:

All packages are already installed and there is nothing to restore.
Time Elapsed: 00:00:00.0191460
========== Finished ==========

Error occurred while restoring NuGet packages: The operation failed as details for project xunit.runner.reporters could not be loaded.

Attempting to build also fails, mostly because down-stream dependencies of xunit.runner.reporters probably did not get complete package restore.

  1. Open a command prompt, and run dotnet restore, though, and everything restores correctly. Once this is done, you can switch back to Visual Studio also build correctly. It's worth noting that nuget restore (with 4.1.0.2450) also correctly restores, so the issue appears to be limited to the version of NuGet built into Visual Studio.
@magol
Copy link

magol commented May 13, 2017

I have the same problem.

@alpaix
Copy link

alpaix commented May 16, 2017

@bradwilson Will you be able to submit a feedback ticket via the Visual Studio Report-a-Problem tool at the top right corner? It provides a method of recording steps along with other helpful data for us to investigate.

@morrisjoe
Copy link

@rrelyea @anangaur Please triage and investigate

@clairernovotny
Copy link

I just tried this in VS 2017 15.3 preview 2 and it still fails. Clean checkout of xunit master, open in VS and I see this in the package manager output window

Error occurred while restoring NuGet packages: The operation failed as details for project xunit.runner.reporters could not be loaded.
Error occurred while restoring NuGet packages: The operation failed as details for project xunit.runner.reporters could not be loaded.

building fails as nuget restore didn't complete correctly.

@anangaur
Copy link
Member

anangaur commented Jun 8, 2017

Talked to @emgarten and it seems like a Project system issue where the nomination sequence for restore is not right. @emgarten Can you link this to the right project systems issues?

@emgarten
Copy link
Member

emgarten commented Jun 8, 2017

Dupe of #4307
Project system issue: dotnet/project-system#1600

Restore fails with The operation failed as details for project if the project system hasn't pushed the list of package references and other project metadata to NuGet. Sometimes this can be due to a project issue or because the project is unloaded.

Typically this error appears when the projects are still not loaded, in that case auto restore will try again when the project metadata is pushed, and everything will be restored correctly at that time.

edit: still not loaded

@emgarten emgarten closed this as completed Jun 8, 2017
@emgarten emgarten added the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Jun 8, 2017
@bradwilson
Copy link
Author

in that case auto restore will try again when the project metadata is pushed, and everything will be restored correctly at that time.

That is not the case here. You will never be able to successfully build the project without shelling out to run dotnet restore. Are you sure it's the same issue?

@emgarten emgarten reopened this Jun 9, 2017
@emgarten
Copy link
Member

emgarten commented Jun 9, 2017

I investigated this a bit farther, restore fails when it finds conflicting names for the same project were sent during restore nomination. It looks like this is due to having conditional assembly names.

https://github.com/xunit/xunit/blob/9740b5b94cfa382aa2aeb8ac255bbd925711cd8c/src/xunit.runner.reporters/xunit.runner.reporters.csproj#L27-L38

Cause

Restore tries to find the name of the project in the following order:

  1. PackageId
  2. AssemblyName
  3. MSBuildProjectName

Visual Studio evaluates project properties for each TargetFramework property value in TargetFrameworks. For many of the xunit projects this returns a different value of AssemblyName for each TFM. When a conflict occurs restores fails.

MSBuild evaluates the properties in the outer build (TargetFramework is not set). There it doesn't find AssemblyName, only MSBuildProjectName and uses that. Here it isn't possible to get conflicting values.

Possible solutions

For properties that can only have a single value per project such as PackageId and Version reading the values in the outer build (MSBuild behavior) seems like the best way. Both the project system and VS restore would need to be updated to pass this metadata in a project wide property bag instead of the current TargetFramework level property bag.

Additional logging to the UI would also be helpful here for when nominations fail. The current behavior requires knowing that this goes into the activity log, and looking it up in the NuGet source code to see what project inputs may have broken this.

Workaround

Adding a PackageId property to src\common.props solves the issue for me and I'm able to restore xunit in VS.

<PackageId>$(MSBuildProjectName)</PackageId>

The above sets the id to the project name, ignoring AssemblyName which is overriding the id.

ActivityLog.xml

VS log of the failure for reference

<entry>
    <record>865</record>
    <time>2017/06/09 02:13:04.146</time>
    <type>Information</type>
    <source>NuGet Package Manager</source>
    <description>The nominate API is called for &apos;C:\src\repros\xunit\src\xunit.runner.visualstudio\xunit.runner.visualstudio.csproj&apos;.</description>
  </entry>
  <entry>
    <record>866</record>
    <time>2017/06/09 02:13:04.146</time>
    <type>Error</type>
    <source>NuGet Package Manager</source>
    <description>System.InvalidOperationException: Sequence contains more than one element&#x000D;&#x000A;   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetNonEvaluatedPropertyOrNull[TValue](IVsTargetFrameworks tfms, String propertyName, Func`2 valueFactory)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.NominateProjectAsync(String projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token)</description>
  </entry>
  <entry>
    <record>867</record>
    <time>2017/06/09 02:13:04.170</time>
    <type>Information</type>
    <source>NuGet Package Manager</source>
    <description>The nominate API is called for &apos;C:\src\repros\xunit\src\xunit.runner.visualstudio\xunit.runner.visualstudio.csproj&apos;.</description>
  </entry>
  <entry>
    <record>868</record>
    <time>2017/06/09 02:13:04.170</time>
    <type>Error</type>
    <source>NuGet Package Manager</source>
    <description>System.InvalidOperationException: Sequence contains more than one element&#x000D;&#x000A;   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetNonEvaluatedPropertyOrNull[TValue](IVsTargetFrameworks tfms, String propertyName, Func`2 valueFactory)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)&#x000D;&#x000A;   at NuGet.SolutionRestoreManager.VsSolutionRestoreService.NominateProjectAsync(String projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token)</description>
  </entry>

@emgarten emgarten added Product:VS.Client and removed Resolution:Duplicate This issue appears to be a Duplicate of another issue labels Jun 9, 2017
bradwilson added a commit to xunit/xunit that referenced this issue Jun 9, 2017
@bradwilson
Copy link
Author

I have verified that the workaround allows restore to work again in VS2017. Thanks!

@mishra14 mishra14 added the Resolution:ByDesign This issue appears to be ByDesign label Nov 9, 2017
@mishra14 mishra14 added this to the 4.6 milestone Nov 9, 2017
@mishra14 mishra14 closed this as completed Nov 9, 2017
@mishra14
Copy link
Contributor

mishra14 commented Nov 9, 2017

Closing this as there is no action from NuGet.

@mattleibow
Copy link

Gonna make a comment here... This got me for a few days as I was unable to find exactly what was causing the issues.

If there is a way to have an actual error message that could effectively mean "Unable to find unique ID for project when restoring. Either use the same AssemblyName for all TFMs or add a PackageId."

Or something like that. This looks like some internal error that gets out and there is no ay to figure it out. I had to add back my project line by line and it was time consuming as I have quite a few projects and quite a few TFMs in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product:VS.Client Resolution:ByDesign This issue appears to be ByDesign
Projects
None yet
Development

No branches or pull requests

9 participants