Ejemplo n.º 1
0
        private void WriteProjectFile(
            string ATemplateDir,
            string ADevName,
            string ASrcPath,
            string AProjectName,
            string AProjectType,
            List <string> AProjectDependencies,
            string AProjectGUID)
        {
            ATemplateDir += Path.DirectorySeparatorChar + ADevName + Path.DirectorySeparatorChar;
            StringBuilder template = GetTemplateFile(ATemplateDir + "template.csproj");

            // replace simple variables
            template.Replace("${ProjectGuid}", AProjectGUID);
            template.Replace("${OutputType}", AProjectType);
            template.Replace("${Namespace}", AProjectName);
            template.Replace("${NETframework-version}", FNetFrameworkVersion);
            template.Replace("${dir.bin}", "../../bin");
            template.Replace("${dir.bin.backslash}", "..\\..\\bin");
            template.Replace("${dir.obj}", "../../obj");
            template.Replace("${dir.obj.backslash}", "..\\..\\obj");

            if (FDebugParameters.ContainsKey(AProjectName))
            {
                template.Replace("${DebugStartArguments}", FDebugParameters[AProjectName]);
            }
            else
            {
                template.Replace("${DebugStartArguments}", "");
            }

            StringBuilder temp;

            // Set the application icon for WinExe projects, if an icon file exists
            string replaceWith = String.Empty;

            if (String.Compare(AProjectType, "WinExe", true) == 0)
            {
                string[] iconFiles = Directory.GetFiles(ASrcPath, "*.ico", SearchOption.TopDirectoryOnly);

                if (iconFiles.Length > 0)
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.appicon");
                    string iconPath = GetRelativePath(iconFiles[0], FDirProjectFiles + "/dummy/");
                    temp.Replace("${application-Icon}", iconPath.Replace('/', Path.DirectorySeparatorChar));
                    temp.Replace("${application-Icon-backslash}", iconPath.Replace('/', '\\'));
                    replaceWith = temp.ToString();
                }
            }

            template.Replace("${ApplicationIcon}", replaceWith);

            // set the application manifest if a file app.manifest exists (needed for patch tool)
            replaceWith = String.Empty;

            if (File.Exists(ASrcPath + Path.DirectorySeparatorChar + "app.manifest"))
            {
                temp = GetTemplateFile(ATemplateDir + "template.csproj.appmanifest");
                string manifestPath = GetRelativePath(ASrcPath + Path.DirectorySeparatorChar + "app.manifest", FDirProjectFiles + "/dummy/");
                temp.Replace("${application-Manifest}", manifestPath.Replace('/', Path.DirectorySeparatorChar));
                temp.Replace("${application-Manifest-backslash}", manifestPath.Replace('/', '\\'));
                replaceWith = temp.ToString();
            }

            template.Replace("${ApplicationManifest}", replaceWith);

            // Set the Pre-build event if required by the environment and if the project is Ict.Common
            replaceWith = String.Empty;

            if ((AProjectName == "Ict.Common") && (Environment.GetEnvironmentVariable("OPDA_StopServer") != null))
            {
                string path = Environment.GetEnvironmentVariable("OPDA_PATH");

                if (path != null)
                {
                    Uri u = new Uri(path);
                    temp        = GetTemplateFile(ATemplateDir + "template.csproj.preBuildEvent");
                    temp        = temp.Replace("${opda-path}", String.Format("\"{0}\"", u.LocalPath));
                    replaceWith = temp.ToString();
                }
            }

            template.Replace("${PreBuildEvent}", replaceWith);

            // Set the Post-build event if required by the environment and if the project is PetraClient
            replaceWith = String.Empty;

            if ((AProjectName == "PetraClient") && (Environment.GetEnvironmentVariable("OPDA_StartServer") != null))
            {
                string path = Environment.GetEnvironmentVariable("OPDA_PATH");

                if (path != null)
                {
                    Uri u = new Uri(path);
                    temp        = GetTemplateFile(ATemplateDir + "template.csproj.postBuildEvent");
                    temp        = temp.Replace("${opda-path}", String.Format("\"{0}\"", u.LocalPath));
                    replaceWith = temp.ToString();
                }
            }

            template.Replace("${PostBuildEvent}", replaceWith);

            // replace references
            StringBuilder ProjectReferences = new StringBuilder();
            StringBuilder OtherReferences   = new StringBuilder();

            foreach (string referencedProject in AProjectDependencies)
            {
                string NameByPath = referencedProject;

                if (FMapOutputNameToPath.ContainsKey(referencedProject))
                {
                    NameByPath = FMapOutputNameToPath[referencedProject];
                }

                if (!FProjectDependencies.ContainsKey(NameByPath))
                {
                    if (referencedProject.Contains("${csharpStdLibs}"))
                    {
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.referencenohint");
                    }
                    else
                    {
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.reference");
                    }

                    temp.Replace("${reference-name}", Path.GetFileNameWithoutExtension(referencedProject));
                    temp.Replace("${reference-path}", referencedProject.Replace('/', Path.DirectorySeparatorChar));
                    temp.Replace("${relative-reference-path}", referencedProject);
                    OtherReferences.Append(temp.ToString());
                }
                else
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.projectreference");
                    temp.Replace("${reference-project-file-name}", referencedProject + ".csproj");
                    temp.Replace("${relative-reference-project-file}", referencedProject + ".csproj");
                    temp.Replace("${relative-reference-path}", referencedProject + ".csproj");
                    temp.Replace(
                        "${reference-project-file}",
                        FDirProjectFiles + Path.DirectorySeparatorChar + ADevName + Path.DirectorySeparatorChar + referencedProject + ".csproj");
                    temp.Replace("${reference-project-guid}", GetProjectGUID(referencedProject));
                    temp.Replace("${reference-name}", referencedProject);
                    ProjectReferences.Append(temp.ToString());
                }
            }

            template.Replace("${TemplateProjectReferences}", ProjectReferences.ToString());

            template.Replace("${TemplateReferences}", OtherReferences.ToString());

            StringBuilder CompileFile = new StringBuilder();

            List <string> ContainsFiles = new List <string>(Directory.GetFiles(ASrcPath, "*.cs", SearchOption.TopDirectoryOnly));

            foreach (string ContainedFile in ContainsFiles)
            {
                string relativeFilename          = GetRelativePath(ContainedFile, FDirProjectFiles + "/dummy/").Replace('\\', Path.DirectorySeparatorChar);
                string relativeFilenameBackslash = relativeFilename.Replace('/', '\\');

                if ((ContainedFile.EndsWith(".ManualCode.cs") && File.Exists(ContainedFile.Replace(".ManualCode.cs", "-generated.cs"))) ||
                    (ContainedFile.EndsWith(".Designer.cs") && File.Exists(ContainedFile.Replace(".Designer.cs", ".cs"))))
                {
                    // ignore and insert with the main file
                }
                else
                {
                    // Check if the filename is an extra manual class file with a format: BaseName.ExtraName.ManualCode.cs
                    string[] parts = ContainedFile.Split('.');
                    bool     isExtraManualClass = (ContainedFile.EndsWith(".ManualCode.cs")) && (parts.Length == 4);

                    if (isExtraManualClass)
                    {
                        // Extra manual file
                        string OtherFile = parts[0] + "-generated.cs";

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", ContainedFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                        temp.Replace("${relative-filename}", relativeFilename);
                        temp.Replace("${DependentUpon}", OtherFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(OtherFile));
                    }
                    else
                    {
                        // A main, top-level file.  This may have an associated .Manual.cs, a Designer.cs, a YAML file and/or resx file
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile");
                        temp.Replace("${filename}", ContainedFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                        temp.Replace("${relative-filename}", relativeFilename);
                        temp.Replace("${justfilename}", Path.GetFileName(ContainedFile));
                    }

                    CompileFile.Append(temp.ToString());

                    if (ContainsFiles.Contains(ContainedFile.Replace(".cs", ".Designer.cs")))
                    {
                        string OtherFile = ContainedFile.Replace(".cs", ".Designer.cs");

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", OtherFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash.Replace(".cs", ".Designer.cs"));
                        temp.Replace("${relative-filename}", relativeFilename.Replace(".cs", ".Designer.cs"));
                        temp.Replace("${DependentUpon}", ContainedFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                        CompileFile.Append(temp.ToString());
                    }

                    if (ContainedFile.Contains("-generated.cs") && ContainsFiles.Contains(ContainedFile.Replace("-generated.cs", ".ManualCode.cs")))
                    {
                        string OtherFile = ContainedFile.Replace("-generated.cs", ".ManualCode.cs");

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", OtherFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash.Replace("-generated.cs", ".ManualCode.cs"));
                        temp.Replace("${relative-filename}", relativeFilename.Replace("-generated.cs", ".ManualCode.cs"));
                        temp.Replace("${DependentUpon}", ContainedFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                        CompileFile.Append(temp.ToString());

                        // Add the YAML file as a dependent non-compile file
                        OtherFile = ContainedFile.Replace("-generated.cs", ".yaml");
                        string OtherFileRelativeFilename = GetRelativePath(OtherFile, FDirProjectFiles + "/dummy/");

                        if (File.Exists(OtherFile) && File.Exists(ATemplateDir + "template.csproj.none.DependentUpon"))
                        {
                            temp = GetTemplateFile(ATemplateDir + "template.csproj.none.DependentUpon");
                            temp.Replace("${filename}", OtherFile);
                            temp.Replace("${relative-filename}", OtherFileRelativeFilename);
                            temp.Replace("${relative-filename-backslash}", OtherFileRelativeFilename.Replace('/', '\\'));
                            temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                            CompileFile.Append(temp.ToString());
                        }
                    }
                }
            }

            // add AssemblyInfo file
            CompileFile.Append(AddAssemblyInfoFile(AProjectName, ATemplateDir));

            // finish Compile file section
            template.Replace("${TemplateCompile}", CompileFile.ToString());

            StringBuilder Resources = new StringBuilder();

            string[] ContainsResources = Directory.GetFiles(ASrcPath, "*.resx", SearchOption.TopDirectoryOnly);

            foreach (string ContainedFile in ContainsResources)
            {
                string relativeFilename = GetRelativePath(ContainedFile, FDirProjectFiles + "/dummy/");

                string relativeFilenameBackslash = relativeFilename.Replace('/', '\\');

                if (ContainsFiles.Contains(ContainedFile.Replace(".resx", ".cs")))
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.resource.DependentUpon");
                    temp.Replace("${filename}", ContainedFile);
                    temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                    temp.Replace("${relative-filename}", relativeFilename);
                    temp.Replace("${DependentUpon}", ContainedFile.Replace(".resx", ".cs"));
                    temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename.Replace(".resx", ".cs")));
                    Resources.Append(temp.ToString());
                }
                else
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.resource");
                    temp.Replace("${filename}", ContainedFile);
                    temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                    temp.Replace("${relative-filename}", relativeFilename);
                    Resources.Append(temp.ToString());
                }
            }

            template.Replace("${TemplateResource}", Resources.ToString());

            // Check for any miscellaneous xml files in a data subfolder
            string miscFilesPath = Path.Combine(ASrcPath, "data");

            if (Directory.Exists(miscFilesPath))
            {
                string[] dataXmlFiles = Directory.GetFiles(miscFilesPath, "*.xml");
                replaceWith = String.Empty;

                if ((dataXmlFiles.Length > 0) && File.Exists(ATemplateDir + "template.csproj.none"))
                {
                    temp        = GetTemplateFile(ATemplateDir + "template.csproj.none");
                    replaceWith = "  <ItemGroup>" + Environment.NewLine;

                    for (int i = 0; i < dataXmlFiles.Length; i++)
                    {
                        replaceWith += temp;
                        replaceWith  = replaceWith.Replace("${filename}", dataXmlFiles[i]);
                        string OtherFileRelativeFilename = GetRelativePath(dataXmlFiles[i], FDirProjectFiles + "/dummy/");
                        replaceWith = replaceWith.Replace("${relative-filename}", OtherFileRelativeFilename);
                        replaceWith = replaceWith.Replace("${relative-filename-backslash}", OtherFileRelativeFilename.Replace('/', '\\'));
                    }

                    replaceWith += ("  </ItemGroup>" + Environment.NewLine);
                }

                template.Replace("${MiscellaneousFiles}", replaceWith);
            }
            else
            {
                template.Replace("${MiscellaneousFiles}", String.Empty);
            }

            template.Replace("${dir.3rdParty}",
                             GetRelativePath(FCodeRootDir + Path.DirectorySeparatorChar + "ThirdParty", FDirProjectFiles + "\\devenv\\").Replace("/", "\\"));
            template.Replace("${csharpStdLibs}", "");

            string completedFile = template.ToString();

            string       filename = FDirProjectFiles + Path.DirectorySeparatorChar + ADevName + Path.DirectorySeparatorChar + AProjectName + ".csproj";
            StreamWriter sw       = new StreamWriter(filename);

            sw.WriteLine(completedFile);
            sw.Close();

            if (completedFile.Contains("${"))
            {
                if (File.Exists(filename + ".error"))
                {
                    File.Delete(filename + ".error");
                }

                File.Move(filename, filename + ".error");
                throw new Exception("Template has not been filled in completely yet. See " + filename + ".error");
            }
        }
Ejemplo n.º 2
0
        private void WriteProjectFile(
            string ATemplateDir,
            string ADevName,
            string ASrcPath,
            string AProjectName,
            string AProjectType,
            List <string> AProjectDependencies,
            string AProjectGUID)
        {
            ATemplateDir += Path.DirectorySeparatorChar + ADevName + Path.DirectorySeparatorChar;
            StringBuilder template = GetTemplateFile(ATemplateDir + "template.csproj");

            // replace simple variables
            template.Replace("${ProjectGuid}", AProjectGUID);
            template.Replace("${OutputType}", AProjectType);
            template.Replace("${Namespace}", AProjectName);
            template.Replace("${NETframework-version}", FNetFrameworkVersion);
            string deliveryPath = GetRelativePath(FCodeRootDir + "/../delivery", ASrcPath);

            template.Replace("${dir.bin}", deliveryPath + "/bin");
            template.Replace("${dir.bin.backslash}", (deliveryPath + "/bin").Replace("/", "\\"));
            template.Replace("${dir.obj}", deliveryPath + "/obj/");
            template.Replace("${dir.obj.backslash}", (deliveryPath + "/obj/").Replace("/", "\\"));

            if (FDebugParameters.ContainsKey(AProjectName))
            {
                template.Replace("${DebugStartArguments}", FDebugParameters[AProjectName]);
            }
            else
            {
                template.Replace("${DebugStartArguments}", "");
            }

            // Set the ApplicationIcon (not used anymore)
            string replaceWith = String.Empty;

            template.Replace("${ApplicationIcon}", replaceWith);

            // Set the ApplicationManifest (was used for PatchTool)
            replaceWith = String.Empty;

            template.Replace("${ApplicationManifest}", replaceWith);

            // Set the Pre-build event (was used for OPDA)
            replaceWith = String.Empty;

            template.Replace("${PreBuildEvent}", replaceWith);

            // Set the Post-build event (was used for PetraClient)
            replaceWith = String.Empty;

            template.Replace("${PostBuildEvent}", replaceWith);

            // replace references
            StringBuilder ProjectReferences = new StringBuilder();
            StringBuilder OtherReferences   = new StringBuilder();
            StringBuilder temp;

            foreach (string referencedProject in AProjectDependencies)
            {
                string NameByPath = referencedProject;

                if (FMapOutputNameToPath.ContainsKey(referencedProject))
                {
                    NameByPath = FMapOutputNameToPath[referencedProject];
                }

                if (!FProjectDependencies.ContainsKey(NameByPath))
                {
                    if (referencedProject.Contains("${csharpStdLibs}"))
                    {
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.referencenohint");
                    }
                    else
                    {
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.reference");
                    }

                    temp.Replace("${reference-name}", Path.GetFileNameWithoutExtension(referencedProject));
                    temp.Replace("${reference-path}", referencedProject.Replace('/', Path.DirectorySeparatorChar));
                    temp.Replace("${relative-reference-path}",
                                 GetRelativePath(CalculateSrcPathForProject(referencedProject) + Path.DirectorySeparatorChar, ASrcPath) +
                                 referencedProject + ".csproj");
                    OtherReferences.Append(temp.ToString());
                }
                else
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.projectreference");
                    temp.Replace("${reference-project-file-name}", referencedProject + ".csproj");
                    temp.Replace("${relative-reference-project-file}", referencedProject + ".csproj");
                    temp.Replace("${relative-reference-path}",
                                 GetRelativePath(CalculateSrcPathForProject(referencedProject) + Path.DirectorySeparatorChar, ASrcPath) +
                                 referencedProject + ".csproj");
                    //temp.Replace(
                    //    "${reference-project-file}",
                    //    "FDirProjectFiles" + Path.DirectorySeparatorChar + ADevName + Path.DirectorySeparatorChar + referencedProject + ".csproj");
                    temp.Replace("${reference-project-guid}", GetProjectGUID(referencedProject));
                    temp.Replace("${reference-name}", referencedProject);
                    ProjectReferences.Append(temp.ToString());
                }
            }

            template.Replace("${TemplateProjectReferences}", ProjectReferences.ToString());

            template.Replace("${TemplateReferences}", OtherReferences.ToString());

            StringBuilder CompileFile = new StringBuilder();

            // add AssemblyInfo file
            CompileFile.Append(AddAssemblyInfoFile(ASrcPath, AProjectName, ATemplateDir));

            List <string> ContainsFiles = new List <string>(Directory.GetFiles(ASrcPath, "*.cs", SearchOption.TopDirectoryOnly));

            foreach (string ContainedFile in ContainsFiles)
            {
                string relativeFilename          = Path.GetFileName(ContainedFile);
                string relativeFilenameBackslash = relativeFilename.Replace('/', '\\');

                if (ContainedFile.Contains("AssemblyInfo.cs"))
                {
                    // has been added automatically
                    continue;
                }

                if ((ContainedFile.EndsWith(".ManualCode.cs") && File.Exists(ContainedFile.Replace(".ManualCode.cs", "-generated.cs"))) ||
                    (ContainedFile.EndsWith(".Designer.cs") && File.Exists(ContainedFile.Replace(".Designer.cs", ".cs"))))
                {
                    // ignore and insert with the main file
                }
                else
                {
                    // Check if the filename is an extra manual class file with a format: BaseName.ExtraName.ManualCode.cs
                    string[] parts = ContainedFile.Split('.');
                    bool     isExtraManualClass = (ContainedFile.EndsWith(".ManualCode.cs")) && (parts.Length == 4);

                    if (isExtraManualClass)
                    {
                        // Extra manual file
                        string OtherFile = parts[0] + "-generated.cs";

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", ContainedFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                        temp.Replace("${relative-filename}", relativeFilename);
                        temp.Replace("${DependentUpon}", OtherFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(OtherFile));
                    }
                    else
                    {
                        // A main, top-level file.  This may have an associated .Manual.cs, a Designer.cs, a YAML file and/or resx file
                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile");
                        temp.Replace("${filename}", ContainedFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                        temp.Replace("${relative-filename}", relativeFilename);
                        temp.Replace("${justfilename}", Path.GetFileName(ContainedFile));
                    }

                    CompileFile.Append(temp.ToString());

                    if (ContainsFiles.Contains(ContainedFile.Replace(".cs", ".Designer.cs")))
                    {
                        string OtherFile = ContainedFile.Replace(".cs", ".Designer.cs");

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", OtherFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash.Replace(".cs", ".Designer.cs"));
                        temp.Replace("${relative-filename}", relativeFilename.Replace(".cs", ".Designer.cs"));
                        temp.Replace("${DependentUpon}", ContainedFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                        CompileFile.Append(temp.ToString());
                    }

                    if (ContainedFile.Contains("-generated.cs") && ContainsFiles.Contains(ContainedFile.Replace("-generated.cs", ".ManualCode.cs")))
                    {
                        string OtherFile = ContainedFile.Replace("-generated.cs", ".ManualCode.cs");

                        temp = GetTemplateFile(ATemplateDir + "template.csproj.compile.DependentUpon");
                        temp.Replace("${filename}", OtherFile);
                        temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash.Replace("-generated.cs", ".ManualCode.cs"));
                        temp.Replace("${relative-filename}", relativeFilename.Replace("-generated.cs", ".ManualCode.cs"));
                        temp.Replace("${DependentUpon}", ContainedFile);
                        temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                        CompileFile.Append(temp.ToString());

                        // Add the YAML file as a dependent non-compile file
                        OtherFile = ContainedFile.Replace("-generated.cs", ".yaml");
                        string OtherFileRelativeFilename = OtherFile;

                        if (File.Exists(OtherFile) && File.Exists(ATemplateDir + "template.csproj.none.DependentUpon"))
                        {
                            temp = GetTemplateFile(ATemplateDir + "template.csproj.none.DependentUpon");
                            temp.Replace("${filename}", OtherFile);
                            temp.Replace("${relative-filename}", OtherFileRelativeFilename);
                            temp.Replace("${relative-filename-backslash}", OtherFileRelativeFilename.Replace('/', '\\'));
                            temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename));
                            CompileFile.Append(temp.ToString());
                        }
                    }
                }
            }

            // finish Compile file section
            template.Replace("${TemplateCompile}", CompileFile.ToString());

            StringBuilder Resources = new StringBuilder();

            string[] ContainsResources = Directory.GetFiles(ASrcPath, "*.resx", SearchOption.TopDirectoryOnly);

            foreach (string ContainedFile in ContainsResources)
            {
                string relativeFilename = ContainedFile;

                string relativeFilenameBackslash = relativeFilename.Replace('/', '\\');

                if (ContainsFiles.Contains(ContainedFile.Replace(".resx", ".cs")))
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.resource.DependentUpon");
                    temp.Replace("${filename}", ContainedFile);
                    temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                    temp.Replace("${relative-filename}", relativeFilename);
                    temp.Replace("${DependentUpon}", ContainedFile.Replace(".resx", ".cs"));
                    temp.Replace("${relative-DependentUpon}", Path.GetFileName(relativeFilename.Replace(".resx", ".cs")));
                    Resources.Append(temp.ToString());
                }
                else
                {
                    temp = GetTemplateFile(ATemplateDir + "template.csproj.resource");
                    temp.Replace("${filename}", ContainedFile);
                    temp.Replace("${relative-filename-backslash}", relativeFilenameBackslash);
                    temp.Replace("${relative-filename}", relativeFilename);
                    Resources.Append(temp.ToString());
                }
            }

            template.Replace("${TemplateResource}", Resources.ToString());

            // Check for any miscellaneous xml files in a data subfolder
            string miscFilesPath = Path.Combine(ASrcPath, "data");

            if (Directory.Exists(miscFilesPath))
            {
                string[] dataXmlFiles = Directory.GetFiles(miscFilesPath, "*.xml");
                replaceWith = String.Empty;

                if ((dataXmlFiles.Length > 0) && File.Exists(ATemplateDir + "template.csproj.none"))
                {
                    temp        = GetTemplateFile(ATemplateDir + "template.csproj.none");
                    replaceWith = "  <ItemGroup>" + Environment.NewLine;

                    for (int i = 0; i < dataXmlFiles.Length; i++)
                    {
                        replaceWith += temp;
                        replaceWith  = replaceWith.Replace("${filename}", dataXmlFiles[i]);
                        string OtherFileRelativeFilename = dataXmlFiles[i];
                        replaceWith = replaceWith.Replace("${relative-filename}", OtherFileRelativeFilename);
                        replaceWith = replaceWith.Replace("${relative-filename-backslash}", OtherFileRelativeFilename.Replace('/', '\\'));
                    }

                    replaceWith += ("  </ItemGroup>" + Environment.NewLine);
                }

                template.Replace("${MiscellaneousFiles}", replaceWith);
            }
            else
            {
                template.Replace("${MiscellaneousFiles}", String.Empty);
            }

            template.Replace("${dir.3rdParty}",
                             GetRelativePath(FCodeRootDir + Path.DirectorySeparatorChar + "ThirdParty", ASrcPath).Replace("\\", "/"));
            template.Replace("${csharpStdLibs}", "");

            string completedFile = template.ToString();

            string       filename = ASrcPath + Path.DirectorySeparatorChar + AProjectName + ".csproj";
            StreamWriter sw       = new StreamWriter(filename);

            sw.WriteLine(completedFile);
            sw.Close();

            if (completedFile.Contains("${"))
            {
                if (File.Exists(filename + ".error"))
                {
                    File.Delete(filename + ".error");
                }

                File.Move(filename, filename + ".error");
                throw new Exception("Template has not been filled in completely yet. See " + filename + ".error");
            }
        }