Example #1
0
        /// <summary>
        /// Если файл папке проекта <paramref name="sourceProjectDirectory"/> отсутствует, то создаёт новый файл с именем <paramref name="name"/>
        /// и содержанием <paramref name="content"/> в кодировке <paramref name="encoding"/>. Файл копируется в <paramref name="targetDirectory"/>.
        /// </summary>
        /// <param name="sourceProjectDirectory"></param>
        /// <param name="targetDirectory"></param>
        /// <param name="name"></param>
        /// <param name="content"></param>
        /// <param name="encoding"></param>
        private void EnsureFile(ProjectItem sourceProjectDirectory, DirectoryInfo targetDirectory, string name, string content, Encoding encoding)
        {
            if (sourceProjectDirectory == null)
            {
                throw new ArgumentNullException(nameof(sourceProjectDirectory));
            }
            if (targetDirectory == null)
            {
                throw new ArgumentNullException(nameof(targetDirectory));
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (String.IsNullOrEmpty(content))
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            ProjectItem projectFile = sourceProjectDirectory.GetChildItem(name);

            if (projectFile == null)
            {
                File.WriteAllText(Path.Combine(targetDirectory.FullName, name), content, encoding);
            }
            else
            {
                this.CopyAndOverwrite(projectFile.GetFullPath(), Path.Combine(targetDirectory.FullName, projectFile.Name));
            }
        }
Example #2
0
        /// <summary>
        /// Сохраняет изменения в файле и возвращает его в качестве файла для добавления в Deploy\Manifest.
        /// </summary>
        /// <param name="deployFolder"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private ProjectItem GetDeployFile(ProjectItem deployFolder, string fileName)
        {
            if (deployFolder == null)
            {
                throw new ArgumentNullException(nameof(deployFolder));
            }
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            ProjectItem item = deployFolder.GetChildItem(fileName, true);

            this.DTE.CheckOutItem(item);
            if (item.IsOpen)
            {
                item.Save();
                item.Document?.Close(vsSaveChanges.vsSaveChangesYes);
            }

            return(item);
        }