dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.58k stars 25.29k forks source link

"Could not find project" - Add NuGet packages in VSCode #32720

Open WildRyc opened 4 months ago

WildRyc commented 4 months ago

Description

[Update from wadepickett]:

I will hit this one while I am updating the MVC tutorial series for .NET 9.

We could consider just reminding the audience to verify they are still in the directory containing the project. The last time we set their current directory is in the previous tutorial in this series. Not using the package names in the commands allows folks to copy/paste the whole collection and apply it to a project by a different name easily.

Also note this is for the VS Code tab version not the visual studio as the original link below indicates. [End Update]

I had difficulty running the .NET CLI commands to add all the EF packages.

Specifically, these ones: dotnet add package Microsoft.EntityFrameworkCore.Design dotnet add package Microsoft.EntityFrameworkCore.SQLite dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design dotnet add package Microsoft.EntityFrameworkCore.SqlServer dotnet add package Microsoft.EntityFrameworkCore.Tools

Repeatedly, for each of these, it gave a "Could not find package" error. Based on the solution here working, I suspect that the commands should instead be

dotnet add MvcMovie package Microsoft.EntityFrameworkCore.Design dotnet add MvcMovie package Microsoft.EntityFrameworkCore.SQLite dotnet add MvcMovie package Microsoft.VisualStudio.Web.CodeGeneration.Design dotnet add MvcMovie package Microsoft.EntityFrameworkCore.SqlServer dotnet add MvcMovie package Microsoft.EntityFrameworkCore.Tools

I'm can't quite figure out where the [!INCLUDE] is located, so if someone could direct me I'll make a pull-request myself.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-8.0&tabs=visual-studio-code

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/tutorials/first-mvc-app/adding-model.md

Document ID

48e81b42-7c2b-afbf-71e6-d4f442a4bd1f

Article author

@wadepickett


Associated WorkItem - 286788

wadepickett commented 4 months ago

@WildRyc, Thanks very much for letting us know your experience with this tutorial series.

Based on instructions earlier in the series, it is assumed that the current directory is still the one that contains the project. If that changed, then you would receive the error, in which case indicating explicitly the project the packages were for, as you suggest, would work.

It would have been helpful if we had provided a short line of instruction just before that indicates to "Verify the current directory in the command line is still at the location of the project file". Just in case.

The benefit of going that route rather than naming the projects in the commands in the tutorial is that it makes it easy to copy/paste that collection of CLI commands to work for a project of any name that you might be working with int he future.

I will leave this issue open but change the suggested fix to add the line verifying the current directory if that is OK. Thanks again for your feedback, it was helpful!