Creating a C# console application step by step will also make mistakes. You may not believe this. I encountered this once. Just now, yes, I can’t believe it. It took so many years to create a new console program. Not normal anymore. After the new creation is completed, there is nothing in it, except for a solution name.
Article directory
Original source of the article: https://blog.csdn.net/haigear/article/details/130024194
1. Problem discovery and phenomenon
1. It is found that the console program has no files
Did you find that there are no projects or files in the solution, but there is a program.cs in front of your eyes!
Could it be that the console program is sick, let's create a window program.
2. It is found that the form program has no file
Similarly, let's create a new form program according to the most standard steps! I have a sense of foreboding.
Good guy, it's exactly the same. We can see that the code file of the form is also opened normally, but we don't see our project, program.cs and other form design files under our solution.
2. Find and solve problems
1. Found that it is a dotnet problem
However, when we create a new project, we choose the form application (.net framework), which is the option under the C# form application. There are not only projects but also files in such a project, all of which are normal. It looks like the configuration of the dotnet framework is out of order. It should be a problem with the path configuration caused by installing the software.
It seems that it is not a simple case, so I opened VS2017 and VS2019 and found the same problem. It seems that this is a systemic problem, just look at what software was installed on which day caused the error, open the uninstall file list to see, we uninstalled one by one to confirm, the biggest suspicion is that Hummao removes the watermark.
Uninstalling can't eliminate this effect. It seems that we should check whether it is the case of .net, and try running it under cmd.
As expected, the problem appeared, and the dotnet command was not recognized, so there must be a problem with the path and it was lost.
2. Patch dotnet environment variables
Try adding a dotnet environment variable. We open the advanced settings in the computer properties, as shown in the figure below,
find the path in the environment variable settings, and add an item: C:\Program Files\dotnet, your dotnet should also be this path.
After configuring the path, we go to cmd and enter dotnet, and we have it! ! ! !
3. Test the repair effect
1. Test the console program
Create a new C# console program and try it. There should be no problem. Sure enough:
the long-lost project and program.cs finally appeared in the resource manager.
2. Test form program
As expected, the form program is also normal. Well, we can happily type on the keyboard! !
3. Special instructions
I am using the win10 operating system here, and installed three versions of VS. The problems are all at the same time, so I can easily think of the overall problem. Generally speaking, the dotnet framework is the common one. If you only have such a problem in a certain version, you may have to consider whether VS may be damaged by .net. Analyze specific issues! At this time, you can choose to reinstall .net mine or VS!
The article may be updated at any time, please indicate the original source of the article: https://blog.csdn.net/haigear/article/details/130024194