public static CSharpFile AddOrUpdateProjectItemFile(this Solution solution, RawSourceFile rawSourceFile)
        {
            Ensure.ArgumentNotNull(solution, "solution");

            try
            {
                var project = solution.Projects.FirstOrDefault(
                    p => p.FileName.Equals(rawSourceFile.ProjectFileName));

                if (null == project)
                {
                    _log.ErrorFormat("Failed AddOrUpdateProjectItemFile [{0}] because could not find Project [{1}]",
                        rawSourceFile.FileName,
                        rawSourceFile.ProjectFileName);

                    //TODO: Should this throw an exception instead?
                    return null;
                }

                var csharpFile = new CSharpFile(project, rawSourceFile.FileName, rawSourceFile.FileContents);

                project.AddOrUpdateCSharpFile(csharpFile);

                solution.RecreateCompilations();

                return csharpFile;
            }
            catch (Exception e)
            {
                _log.Error("Exception in AddOrUpdateCodeGeneratorFileSource: " + e.Message, e);
                throw;
            }
        }
Example #2
0
        public void AddOrUpdateCSharpFile(CSharpFile csharpFile)
        {
            if (Files.All(f => !f.FileName.Equals(csharpFile.FileName)))
            {
                Files.Add(csharpFile);
            }

            ProjectContent = ProjectContent.AddOrUpdateFiles(csharpFile.UnresolvedTypeSystemForFile);
        }
Example #3
0
        public void AddOrUpdateCSharpFile(CSharpFile csharpFile)
        {
            if (Files.All(f => !f.FileName.Equals(csharpFile.FileName)))
                Files.Add(csharpFile);

            ProjectContent = ProjectContent.AddOrUpdateFiles(csharpFile.UnresolvedTypeSystemForFile);
        }