title: ProjectGuid (.csproj), how to generate it correctly?
body: <p>I'm creating an app. to change the namespace of multiple projects (solution), I copy the content to another location, change folder names, replace text in files content (old namespaces with new namespaces), all is OK. The solution has folders(these folders only exist in the solution, in VS) and every folder contains  projects, and files...This is the structure of the original (or template) solution:</p>
  
  <pre><code>    MySolution
      |
      |---SolutionFolder1
      |           |
      |           |-- Documentation.docx
      |
      |---SolutionFolder2
      |           |
      |           |-- ThirdPartyLibrary.dll
      |
      |---SolutionFolder3
      |           |
      |           |-- MySolution.MyLibrary(**Project**)
      |                     |
      |                     |-- Class.cs
      |
      |---SolutionFolder4
      |           |
      |           |-- MySolution.MyConsoleApp(**Project**)
      |                     |
      |                     |-- Program.cs
      |
  </code></pre>
  
  <p>I only copy the whole solution to another place, changing some names even in .csproj and .sln files. If I open the new solution all appears in its place (like above structure), projects inside solution folder an the solution compiles, all is OK.
  But if I change the ProjectGuid of each project when I open the new solution i get this structure:</p>
  
  <pre><code>    MySolution
      |
      |---SolutionFolder1
      |           |
      |           |-- Documentation.docx
      |
      |---SolutionFolder2
      |           |
      |           |-- ThirdPartyLibrary.dll
      |
      |---SolutionFolder3          
      |
      |---SolutionFolder4
      |
      |
      |-- MySolution.MyLibrary(**Project**)
      |           |
      |           |-- Class.cs
      |
      |-- MySolution.MyConsoleApp(**Project**)
      |           |
      |           |-- Program.cs
      |
  </code></pre>
  
  <p>As you see, projects appear out of solution folders, althoug the others folders maintain its content and the solution compile.
  I use <strong>Guid.NewGuid()</strong> to generate the new ProjectGuid and I update the others .csproj and the .sln file.
  This is my code (this method copies the content of every file):</p>
  
  <pre><code>//the projectGuidCollection contains a collection of instances like this:
  ProjectGuid proj = new ProjectGuid()
  {
      FilePath = @"c:\newpath\to\MyLibrary.csproj",
      OldGuid = "D4BD0EB3-8B59-4A33-B8A3-D549065EEC6D", //&lt;ProjectGuid&gt;{}&lt;/ProjectGuid&gt;
      NewGuid = Guid.NewGuid().ToString()
  };
  
  public static void Replace(string filePath, string oldNamespace, string newNamespace, 
                             IEnumerable&lt;ProjectGuid&gt; projectGuidCollection)
  {
      string text = File.ReadAllText(filePath, Encoding.UTF8);
      text = text.Replace(oldNamespace, newNamespace);
  
      List&lt;ProjectGuid&gt; allProjectGuids = new List&lt;ProjectGuid&gt;(projectGuidCollection);
      if (filePath.EndsWith(".csproj"))
      {
          ProjectGuid currentProject = allProjectGuids.Find(o =&gt; { return o.FilePath.Equals(filePath); });
          if (currentProject != null)
          {
              List&lt;ProjectGuid&gt; otherProjs = allProjectGuids.FindAll(o =&gt; { return !o.FilePath.Equals(filePath); });
  
              //changes current ProjecGuid:
              text = text.Replace(currentProject.OldGuid, currentProject.NewGuid.ToUpper());
  
              //change other projectguids (references):
              foreach (var refProject in otherProjs)
              {
                  text = text.Replace(refProject.OldGuid, refProject.NewGuid);
              }
          }
      }
  
      //update new projectguids in solution file:
      if (filePath.EndsWith(".sln"))
      {
          foreach (var p in allProjectGuids)
          {
              text = text.Replace(p.OldGuid.ToUpper(), p.NewGuid.ToUpper());
          }
      }
  
      File.WriteAllText(filePath, text,Encoding.UTF8);
  }
  </code></pre>
  
  <p>I need your help.</p>