-
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
Package restore broken in VS2017, works from dotnet restore
#5226
Comments
I have the same problem. |
@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. |
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
building fails as nuget restore didn't complete correctly. |
Dupe of #4307 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 |
That is not the case here. You will never be able to successfully build the project without shelling out to run |
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. CauseRestore tries to find the name of the project in the following order:
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 solutionsFor 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. WorkaroundAdding a PackageId property to src\common.props solves the issue for me and I'm able to restore xunit in VS.
The above sets the id to the project name, ignoring AssemblyName which is overriding the id. ActivityLog.xmlVS 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 'C:\src\repros\xunit\src\xunit.runner.visualstudio\xunit.runner.visualstudio.csproj'.</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
 at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetNonEvaluatedPropertyOrNull[TValue](IVsTargetFrameworks tfms, String propertyName, Func`2 valueFactory)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)
 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 'C:\src\repros\xunit\src\xunit.runner.visualstudio\xunit.runner.visualstudio.csproj'.</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
 at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetNonEvaluatedPropertyOrNull[TValue](IVsTargetFrameworks tfms, String propertyName, Func`2 valueFactory)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo)
 at NuGet.SolutionRestoreManager.VsSolutionRestoreService.NominateProjectAsync(String projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token)</description>
</entry> |
I have verified that the workaround allows restore to work again in VS2017. Thanks! |
Closing this as there is no action from NuGet. |
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. |
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):
26510.0-preview
)OS version (i.e. win10 v1607 (14393.321)):
15063.296
)Worked before? If so, with which NuGet version:
Detailed repro steps so we can see the same problem
Clone https://github.com/xunit/xunit (repros as of
bce3c19b565ad5e81ea6b87eedb44db00315d9ff
)Open
xunit.vs2017.sln
in Visual Studio 2017Right click on the solution and choose "Restore NuGet Packages". Output Windows shows:
Attempting to build also fails, mostly because down-stream dependencies of
xunit.runner.reporters
probably did not get complete package restore.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 thatnuget restore
(with4.1.0.2450
) also correctly restores, so the issue appears to be limited to the version of NuGet built into Visual Studio.The text was updated successfully, but these errors were encountered: