private void SetTextTemplateCodeGenerator(EnvDTE.ProjectItem projectItem)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            projectItem.SetCustomTool(null);

            if (_solution.GetCachedProjectFiles()?.Any(file => file.RelativeFilePath.Equals(T4FileName, StringComparison.OrdinalIgnoreCase)) != true)
            {
                var fullName = Path.Combine(_solution.SolutionFolder, T4FileName);
                File.WriteAllBytes(fullName, Resources.Resources_Designer_t4);
                _solution.AddFile(fullName);
            }

            // Ensure DataAnnotations is referenced, used by TT generated code.
            const string dataAnnotations = "System.ComponentModel.DataAnnotations";

            var vsProject = projectItem.ContainingProject?.Object as VSLangProj.VSProject;

            vsProject?.References?.Add(dataAnnotations);

            var fileName = Path.ChangeExtension(FilePath, "Designer.tt");

            File.WriteAllBytes(fileName, Resources.Resources_Designer_tt);

            var item = projectItem.AddFromFile(fileName);

            if (item == null)
            {
                return;
            }

            item.SetProperty(@"BuildAction", 0);

            item.RunCustomTool();
        }
Beispiel #2
0
        private static void SetCustomToolCodeGenerator(EnvDTE.ProjectItem projectItem, CodeGenerator value)
        {
            Contract.Requires(projectItem != null);

            projectItem.Children()
            .Where(IsTextTemplate)
            .ToArray()
            .ForEach(i => i.Delete());

            projectItem.SetCustomTool(value.ToString());
        }
        private static void SetCustomToolCodeGenerator(EnvDTE.ProjectItem projectItem, CodeGenerator value)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

#pragma warning disable VSTHRD010 // Accessing ... should only be done on the main thread.
            projectItem.Children()
            .Where(IsTextTemplate)
            .ToArray()
            .ForEach(i => i.Delete());
#pragma warning restore VSTHRD010 // Accessing ... should only be done on the main thread.

            projectItem.SetCustomTool(value.ToString());
        }
Beispiel #4
0
        private void SetTextTemplateCodeGenerator(EnvDTE.ProjectItem projectItem)
        {
            Contract.Requires(projectItem != null);

            projectItem.SetCustomTool(null);

            const string t4FileName = "Resources.Designer.t4";

            if (!_solution.GetProjectFiles().Any(file => file.RelativeFilePath.Equals(t4FileName)))
            {
                var fullName = Path.Combine(_solution.SolutionFolder, t4FileName);
                File.WriteAllBytes(fullName, Resources.Resources_Designer_t4);
                _solution.AddFile(fullName);
            }

            // Ensure DataAnnotations is referenced, used by TT generated code.
            const string dataAnnotations = "System.ComponentModel.DataAnnotations";

            var vsProject = projectItem.ContainingProject?.Object as VSLangProj.VSProject;

            vsProject?.References?.Add(dataAnnotations);

            var fileName = Path.ChangeExtension(FilePath, "Designer.tt");

            File.WriteAllBytes(fileName, Resources.Resources_Designer_tt);

            var item = projectItem.AddFromFile(fileName);

            if (item == null)
            {
                return;
            }

            item.SetProperty(@"BuildAction", 0);

            Dispatcher.BeginInvoke(() => item.RunCustomTool());
        }