Reputation: 241
I just started learning C# a couple hours ago, but have since run into this error.
Ctrl + Shift + P
.NET:Generate Assets for Build and Debug
But when I click it, an error pops up bottom right of the window:
Could not locate .NET Core project. Assets were not generated.
Upvotes: 23
Views: 42043
Reputation: 45
I've found just removing all other projects from the explorer and having only the project you want to generate the assets for loaded seems to work. This even works for generating multiple different assets for different projects under the same solution.
Reading through the above, I think it could be an issue with VSCode not being able to interpret which project you want to generate the assets for.
Upvotes: 0
Reputation: 56
The problem is you may not have an active solution, may be it is the solution which is opened as a folder. so the thing to do is
Upvotes: 0
Reputation: 11
I ran
dotnet new sln
and then
dotnet sln add .
in the terminal like another reply said and it fixed for me
Upvotes: 1
Reputation: 419
Had this problem on Unity too, and I finally I solved it by downgrading C# to any version lower than 2.0 this way I'm using Omnisharp instead of the C# extension. To downgrade an extension click the little arrow on the left of uninstall button. It also helped to uninstall from the package manager in Unity the visual studio code extension. Even though I still get an error asking me to upgrade C# extension. I still get intellisense and Omnisharp commands when pressing Ctrl+P
Upvotes: 0
Reputation: 11
Solved it by installing the C# Dev Kit extension
Then found this article:
https://code.visualstudio.com/docs/csharp/debugging
where the 'No launch.json' scenario helped me further creating an automatic debug configuration.
Hope it helps.
Upvotes: 1
Reputation: 221
I had this issue recently and to resolve it I installed C# Dev Kit and I switched to pre-release version v0.4.6. I couldn't generate debug files with C# extension. .NET sdk was 8 preview
Upvotes: 1
Reputation: 11
I had the same problem. Turns out I had the wrong .Net extension dowbloaded. Make sure you download the .Net Core tools extension. After I downloaded that, it worked fine for me.
Upvotes: 1
Reputation: 933
This happened when I had multiple C# projects and solutions in the directory. What I had to do was to open the command palette by pressing Ctrl+Shift+P
and execute Omnisharp: Select Project
. After choosing the right project, VS Code offered me the assets generation automatically.
Upvotes: 2
Reputation: 81
In my case I just uninstall the c# extension and reload the vscode, after I install again (The vscode will ask to install some assets and somethings that miss in the project too).
Upvotes: 0
Reputation: 1784
This same thing started happening to me on my mac on vscode. For me, it was because I didn't add my dotnet project to my solution file after I created the solution file and project.
This is essentially how I created my project:
Create empty project folder mkdir RecipeApp && cd RecipeApp
Add Solution File to Project (uses the name of containing folder) dotnet new sln
Create Backend .NET API dotnet new webapi -o API
Then this is the part I forgot to do (which actually solved a few other problems I was having, like I couldn't use the CMD + .
feature to auto import classes and assets etc, too):
dotnet sln add API
After I added the API subproject to the solution file, I could open the main top level project folder in vscode, and everything started working again.
Upvotes: 15
Reputation: 986
for me it helped to open the project with opening project_name.csproj
with vs-code instead of loading the folder
Upvotes: 0
Reputation: 1
What I recommend doing is pressing "Run" then start debugging, which should open up a launch.json. If you open it, it will have about 17 warnings and then you can delete the warnings. Then, you press f5, which will give you an option to open a tasks.json. Do that and configure all of the tasks for running your project and it should work.
Upvotes: 0
Reputation: 31
In my way helped to change the folder name to a name without spaces.
Upvotes: 3
Reputation: 1404
This issue could be because the launch.json
, which ideally should have been populated with the necessary details isn't generated in case. This issue seems to be linked to Omnisharp. If you go through the issue, you understand the root cause more clearly. You may need to perform the steps mentioned in this comment to get around the issue. These steps involve re-configuring the C# extension inside of your VS Code instance.
Alternately, ensure that all the folders which the extensions uses have appropriate access.
If the issue is also involving task.json
, take a look at this answer
Upvotes: 3