1

I am trying to open a project which was created on one computer but has since been moved to another one due to the computer going caput. Now when I open the project and try opening the Form1.cs file, or any of the designer files, I get the error message saying "Cannot find the file 'C:...\Form1.cs'. It may have been moved or deleted". I have omitted the full path which is a reference to the old computer.

How do I change the file path so that my project can find it?

I have found another thread on this issue: Visual Studio retrieving an incorrect path to a project from somewhere

Have tried all of the suggestions (deleting .suo files, moving the project to a new folder, etc.) Nothing has worked so far. There is however in the accepted solution a reference to "Manage Workspaces" and "Source Control Explorer", which I literally can't even find in my Visual Studio window.

Help please!

Alexander

1 Answers1

1

First: Open your sln file and see where it says your csproj file is located. It should read something like: "WindowsFormsApp1\WindowsFormsApp1.csproj"

Note: Everything in the parenthesis will be from the same directory as the sln file, so the true directory in this instance will be "sln_file_path\WindowsFormsApp1\WindowsFormsApp1.csproj"

  • As long as this is correct, then navigate to the csproj file and open it with notepad, but if this path is wrong, correct it before proceeding.

Second: Search the csproj file for the missing file, which in your case is Form1.cs

  • You should find something like: Compile Include="....\Erroneous_Directory\Form1.cs"
  • Typically all cs files will be in the same directory as the csproj file, so the line should simply read as follows: Compile Include="Form1.cs"
  • If the file is legitimately located in a separate directory, then provide the path, but if it is in the same directory, delete the path. Sometimes, when linking to a file in a different project, you will see this: (Link)Form1.cs(/Link), but if the file is in the same project and directory, this link line will need to be deleted.

Note: Chances are that this procedure will need to be repeated for two other files: Form1.Designer.cs and Form1.resx as well, so make sure the "Compile Include" lines for these two files are also correct before opening the solution

Justin Edwards
  • 310
  • 1
  • 4
  • 7