/// <summary>
        /// Adds the text template.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="projectFolder">The project folder.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="textOutput">The text output.</param>
        /// <param name="outputTextTemplateContentToTraceFile">if set to <c>true</c> [output text template content to trace file].</param>
        /// <returns></returns>
        public static string AddTextTemplate(
            this Project instance,
            string projectFolder,
            string fileName,
            string textOutput,
            bool outputTextTemplateContentToTraceFile)
        {
            TraceService.WriteLine("ProjectExtensions::AddTextTemplate projectFolder=" + projectFolder + " fileName=" + fileName);

            if (outputTextTemplateContentToTraceFile)
            {
                TraceService.WriteLine("textOutput=" + textOutput);
            }

            string projectPath = instance.GetProjectPath();

            TraceService.WriteLine("projectPath=" + projectPath);

            string directory = projectPath;

            if (string.IsNullOrEmpty(projectFolder) == false)
            {
                if (directory.EndsWith(@"\") == false)
                {
                    directory += @"\";
                }

                directory += projectFolder;
            }

            TraceService.WriteLine("directory=" + directory);

            if (Directory.Exists(directory) == false)
            {
                TraceService.WriteLine("creating directory=" + directory);
                Directory.CreateDirectory(directory);
            }

            string path = directory + "\\" + fileName;

            TraceService.WriteLine("path=" + path);

            //// save to a file
            File.WriteAllText(path, textOutput);

            TraceService.WriteLine("addToFolderFromFile");

            //// this will actually fail if the file already exists in the project - so swallow the exception.
            try
            {
                instance.AddToFolderFromFile(projectFolder, path);
            }
            catch (Exception)
            {
                // ignored
            }

            return fileName + " added to project " + instance.Name;
        }
        /// <summary>
        /// Adds the reference.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="destinationFolder">The destination folder.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="source">The source.</param>
        /// <param name="addFileToFolder">if set to <c>true</c> [add file to folder].</param>
        /// <param name="copyAssembly">if set to <c>true</c> [copy assembly].</param>
        /// <returns>The Reference.</returns>
        public static Reference AddReference(
            this Project instance,
            string destinationFolder,
            string destination,
            string source,
            bool addFileToFolder,
            bool copyAssembly)
        {
            TraceService.WriteLine("ProjectExtensions::AddReference project=" + instance.Name);
            TraceService.WriteLine("Source=" + source);

            Reference reference = null;

            if (destination.EndsWith(";"))
            {
                destination = destination.TrimEnd(';');
            }

            if (destination.EndsWith(".dll") == false)
            {
                destination += ".dll";
            }

            if (source.EndsWith(";"))
            {
                source = source.TrimEnd(';');
            }

            if (source.EndsWith(".dll") == false)
            {
                source += ".dll";
            }

            //// only do if destination file doesn't exist
            if (File.Exists(destination) == false)
            {
                //// the directory may not exist - if so create it!
                string directory = Path.GetDirectoryName(destination);

                if (directory != null)
                {
                    if (Directory.Exists(directory) == false)
                    {
                        Directory.CreateDirectory(directory);
                    }
                }

                //// copy the assembly to the lib folder!
                if (copyAssembly)
                {
                    File.Copy(source, destination, true);
                    reference = instance.AddReference(destination);
                }
                else
                {
                    //// reference the source and dont copy the file!
                    reference = instance.AddReference(source);
                }

                //// add the lib folder to the project!
                if (addFileToFolder)
                {
                    instance.AddToFolderFromFile(destinationFolder, destination);
                }
            }

            return reference;
        }