Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover a corrupt .csproj file in Visual Studio 2010?

My PC
Windows 8 Preview Release
Visual Studio 2010 Express for Windows Phone

My App is in
Solution A
Project B

Story
The screen is freezing when I type codes
I power off the PC then restart
When I load the sln in VS2010 for wp
VS2010 said

"Solution A (0 projects)
Project B (unavailable)
The project file cannot be loaded

So I tried to "Edit B.csproj" in VS2010, it shows error

B.csproj : error : Unable to read the project file 'B.csproj'.
B.csproj: The project file could not be loaded. Root element is missing.

Help
How can I open my solution correctly? :(

like image 908
Albert Gao Avatar asked Jun 23 '12 16:06

Albert Gao


People also ask

How do I open a .csproj file in Visual Studio 2010?

sln extension. Double-click the . csproj file to open it in Visual Studio.

How do I fix Csproj?

First you have to navigate to the project's node in Solution Explorer. Then you have to right-click > Unload the project. Then you have to right-click > Edit the csproj file. Then you have to find the offending line in the csproj file and modify or delete it.

How do you open the .csproj file?

CSPROJ files are are meant to be opened and edited in Microsoft Visual Studio (Windows, Mac) as part of Visual Studio projects. However, because CSPROJ files are XML files, you can open and edit them in any text or source code editor.

What is Csproj file in Visual Studio?

When you create and build solutions in Visual Studio, Visual Studio uses MSBuild to build each project in your solution. Every Visual Studio project includes an MSBuild project file, with a file extension that reflects the type of project—for example, a C# project (. csproj), a Visual Basic.NET project (.


1 Answers

The easiest thing to do is probably to create a new project file. The simplest way to do this would be to:

  1. Open a fresh copy of Visual Studio
  2. Create a project in a different location of the same type as B, with the same name.
  3. Close that copy of Visual Studio
  4. Copy the newly created B.csproj file to the directory where all your source for B is, overwriting the existing B.csproj file (but take a copy of it, just incase you need it!).
  5. Load Visual Studio and open Solution A.

You'll note that the project doesn't contain any of the files / references you'd expect and will probably contain a "broken" reference to Class1.cs or any other files that were added to the new project file when Visual Studio created it. Now:

  1. Make sure Project B is selected in Solution Explorer and click the "Show All Files" icon. It's the one that has a picture of 3 files overlaying each other in it, to the left of the Refresh icon.
  2. You'll be able to see all the content of your project but "greyed out". Select each file/folder you want to add back, right click and choose "Include In Project".

Assuming there's nothing too complicated about your project, you should only now need to re-add any References and it should compile and run. Any further things you can probably work out by using a tool like Beyond Compare to compare the new project file and the original project file to look for things you've missed.

Most important of all: Start using Source Control!

If you were, you'd be able to recover a previous version of your project file and not have to go through this hassle. Pretty much any source control solution you can think of can be run on a PC without requiring a dedicated server. One of the easiest to setup is VisualSVN Server, which is free for personal and commercial use.

like image 189
Rob Avatar answered Oct 06 '22 03:10

Rob