コード例 #1
0
        public void AddRequiredReferences(Project project, ProjectReference projectReference)
        {
            Argument.IsNotNull(() => project);
            Argument.IsNotNull(() => projectReference);

            Log.Info("Adding reference '{0}' to project '{1}'", projectReference, project);

            project.ProjectReferences += projectReference.ProjectReferences;
            project.FileIncludes += projectReference.FileIncludes;
        }
コード例 #2
0
        public void AddRequiredReferences(Project project)
        {
            Argument.IsNotNull(() => project);

            var coreReferences = GetCoreReferences();

            ProjectReference additionalReferences = null;

            switch (project.ProjectType)
            {
                case ProjectTypes.Console:
                    additionalReferences = GetConsoleReferences();
                    break;

                case ProjectTypes.WPF:
                    additionalReferences = GetWpfReference();
                    break;

                case ProjectTypes.WinForms:
                    additionalReferences = GetWinFormsReferences();
                    break;

                case ProjectTypes.Test:
                    additionalReferences = GetNUnitReferences();
                    break;

                case ProjectTypes.Library:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (coreReferences != null)
            {
                AddRequiredReferences(project, coreReferences);
            }

            if (additionalReferences != null)
            {
                AddRequiredReferences(project, additionalReferences);
            }
        }
コード例 #3
0
        private FileInfo CreateTestProjectFile(DirectoryInfo root, Solution solution)
        {
            string projectRoot = string.Format("{0}/{1}.Tests/", root.FullName, solution.ProjectName);
            var directoryInfo = new DirectoryInfo(projectRoot);

            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            var projectName = string.Format("{0}.Tests", solution.ProjectName);
            var project = new Project(solution.TestProjectGuid)
            {
                ProjectAssemblyName = string.Format("{0}.Tests", solution.ProjectAssemblyName),
                ProjectName = projectName,
                ProjectRootNameSpace = string.Format("{0}.Tests", solution.ProjectRootNameSpace),
                TargetFramework = solution.TargetFramework,
                ReleaseOutputPath = string.Format("../../output/Release/{0}", projectName),
                DebugOutputPath = string.Format("../../output/Debug/{0}", projectName),
                ProjectOutputType = ProjectOutputTypes.Library
            };

            if (string.Equals(solution.TargetFramework, "v4.5"))
            {
                project.ProjectType = ProjectTypes.Test;
                var packagesFile = new FileInfo(projectRoot + "packages.config");
                File.WriteAllText(packagesFile.FullName, _templateRenderer.RenderFile(PackagesTemplate, project));
            }

            _referencesService.AddRequiredReferences(project);

            var projectFile = new FileInfo(projectRoot + project.ProjectName + ".csproj");
            File.WriteAllText(projectFile.FullName, _templateRenderer.RenderFile(ProjectTemplate, project));

            return projectFile;
        }
コード例 #4
0
        private FileInfo CreateProjectFile(DirectoryInfo root, Solution solution)
        {
            Log.Info("Creating project file");

            string projectRoot = string.Format("{0}/{1}/", root.FullName, solution.ProjectName);
            var directoryInfo = new DirectoryInfo(projectRoot);
            var projectTemplate = ProjectTemplate;

            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            var project = new Project(solution.TestProjectGuid)
            {
                ProjectAssemblyName = solution.ProjectAssemblyName,
                ProjectName = solution.ProjectName,
                ProjectRootNameSpace = solution.ProjectRootNameSpace,
                TargetFramework = solution.TargetFramework,
                ReleaseOutputPath = string.Format("../../output/Release/{0}", solution.ProjectName),
                DebugOutputPath = string.Format("../../output/Debug/{0}", solution.ProjectName),
                ProjectType = solution.ProjectType
            };

            project.ProjectOutputType = _projectTypeConverterService.Convert(solution.ProjectType);
            _referencesService.AddRequiredReferences(project);

            if (string.Equals(project.ProjectOutputType, "Exe"))
            {
                File.WriteAllText(projectRoot + "Program.cs", _templateRenderer.RenderFile(ConsoleProgramClass, project));
            }
            else if (string.Equals(solution.ProjectType, "WPF"))
            {
                projectTemplate = WpfProjectTemplate;
                File.WriteAllText(projectRoot + "App.xaml", _templateRenderer.RenderFile(AppXaml, project));
                File.WriteAllText(projectRoot + "App.xaml.cs", _templateRenderer.RenderFile(AppXamlCs, project));
                File.WriteAllText(projectRoot + "MainWindow.xaml", _templateRenderer.RenderFile(MainWindowXaml, project));
                File.WriteAllText(projectRoot + "MainWindow.xaml.cs", _templateRenderer.RenderFile(MainWindowXamlCs, project));
            }
            else if (string.Equals(solution.ProjectType, "WinForms"))
            {
                File.WriteAllText(projectRoot + "Form1.cs", _templateRenderer.RenderFile(Form1Cs, project));
                File.WriteAllText(projectRoot + "Form1.Designer.cs", _templateRenderer.RenderFile(Form1DesignerCs, project));
                File.WriteAllText(projectRoot + "Program.cs", _templateRenderer.RenderFile(ProgramCs, project));
            }

            var projectFile = new FileInfo(projectRoot + project.ProjectName + ".csproj");
            File.WriteAllText(projectFile.FullName, _templateRenderer.RenderFile(ProjectTemplate, project));

            return projectFile;
        }