public int GenerateArtifact(IArtifactLink artifactLink) { Guard.ArgumentNotNull(artifactLink, "artifactLink"); int generatedObjects = 0; try { IVsSolution vsSolution = GetService <IVsSolution, SVsSolution>(); ProjectNode projectNode = new ProjectNode(vsSolution, artifactLink.Container); try { ICodeGenerationStrategy strategy = CreateStrategy(artifactLink, projectNode); CodeGenerationResults result = strategy.Generate(artifactLink); bool hasErrors = CheckErrors(strategy); foreach (string file in result.Files) { string fullPath = Path.Combine(projectNode.ProjectDir, file); if (!this.visitedFiles.Contains(fullPath) && AddFile(projectNode, file, result[file])) { generatedObjects++; this.visitedFiles.Add(fullPath); } } if (!hasErrors && result.Count > 0) { AddProjectReferences(projectNode, strategy.ProjectReferences); AddAssemblyReferences(projectNode, strategy.AssemblyReferences); } } catch (Exception e) { // Report all errors to user as generated code output. LogException(e); if (!IsConfigFile(artifactLink.ItemPath)) { // Add the offending file with a warning in it. AddFile(projectNode, artifactLink.ItemPath, Properties.Resources.Generation_Exception); } } finally { if (projectNode != null) { projectNode.Dispose(); } } } catch (Exception e) { // Report all errors to user as generated code output. LogException(e); } return(generatedObjects); }