Exemplo n.º 1
0
        public CSharpProject(Solution solution, string title, string fileName)
        {
            // Normalize the file name
            fileName = Path.GetFullPath(fileName);

            _solution = solution;
            Title = title;
            FileName = fileName;

            // Use MSBuild to open the .csproj
            var msbuildProject = GetMSBuildProject(fileName);

            // Figure out some compiler settings
            AssemblyName = msbuildProject.GetPropertyValue("AssemblyName");
            CompilerSettings.AllowUnsafeBlocks = GetBoolProperty(msbuildProject, "AllowUnsafeBlocks") ?? false;
            CompilerSettings.CheckForOverflow = GetBoolProperty(msbuildProject, "CheckForOverflowUnderflow") ?? false;
            string defineConstants = msbuildProject.GetPropertyValue("DefineConstants");
            foreach (string symbol in defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                CompilerSettings.ConditionalSymbols.Add(symbol.Trim());

            // Initialize the unresolved type system
            ProjectContent = new CSharpProjectContent();
            ProjectContent = ProjectContent.SetAssemblyName(AssemblyName);
            ProjectContent = ProjectContent.SetProjectFileName(fileName);
            ProjectContent = ProjectContent.SetCompilerSettings(CompilerSettings);
            // Parse the C# code files
            foreach (var item in msbuildProject.GetItems("Compile"))
            {
                AddCSharpFile(
                    new CSharpFile(this, Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude)));
            }

            var assemblyReferences =
                new AssemblyReferencesResolved
                {
                    References = ResolveAssemblyReferences(msbuildProject).ToList()
                };

            if (null != OnAssemblyReferencesResolved)
                OnAssemblyReferencesResolved(this, assemblyReferences);

            // Add referenced assemblies:
            foreach (string assemblyFile in assemblyReferences.References)
            {
                IUnresolvedAssembly assembly = solution.LoadAssembly(assemblyFile);
                ProjectContent = ProjectContent.AddAssemblyReferences(new IAssemblyReference[] { assembly });
            }

            // Add project references:
            foreach (var item in msbuildProject.GetItems("ProjectReference"))
            {
                string referencedFileName = Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude);
                // Normalize the path; this is required to match the name with the referenced project's file name
                referencedFileName = Path.GetFullPath(referencedFileName);
                ProjectContent = ProjectContent.AddAssemblyReferences(new IAssemblyReference[] { new ProjectReference(referencedFileName) });
            }
        }
Exemplo n.º 2
0
        public NRefactory.CSharpProject AddOrUpdateProject(string projectFilePath)
        {
            _log.InfoFormat("Looking for Project [{0}]", projectFilePath);

            var project = GetProjectByFilePath(projectFilePath);

            if (null != project)
            {
                _log.Info("Project has already been parsed.");

                Solution.Projects.Remove(project);

                var newProject = new NRefactory.CSharpProject(Solution, project.Title, project.FileName);

                Solution.Projects.Add(newProject);

                Solution.RecreateCompilations();

                return(newProject);
            }

            _log.Info("Project has not been parsed.  Adding it now.");
            //Reparse the whole solution - TODO: can probably optomize this.
            Solution = new NRefactory.Solution(Solution.FullName);

            project = GetProjectByFilePath(projectFilePath);

            if (null == project)
            {
                throw new Exception(string.Format(
                                        "Failed to load project [{0}].  Does it exist in Solution [{1}]",
                                        projectFilePath, Solution.FileName));
            }

            return(project);
        }
Exemplo n.º 3
0
        public NRefactory.CSharpProject AddOrUpdateProject(string projectFilePath)
        {
            _log.InfoFormat("Looking for Project [{0}]", projectFilePath);

            var project = GetProjectByFilePath(projectFilePath);

            if (null != project)
            {
                _log.Info("Project has already been parsed.");

                Solution.Projects.Remove(project);

                var newProject = new NRefactory.CSharpProject(Solution, project.Title, project.FileName);

                Solution.Projects.Add(newProject);

                Solution.RecreateCompilations();

                return newProject;
            }

            _log.Info("Project has not been parsed.  Adding it now.");
            //Reparse the whole solution - TODO: can probably optomize this.
            Solution = new NRefactory.Solution(Solution.FullName);

            project = GetProjectByFilePath(projectFilePath);

            if (null == project)
                throw new Exception(string.Format(
                    "Failed to load project [{0}].  Does it exist in Solution [{1}]",
                    projectFilePath, Solution.FileName));

            return project;
        }
Exemplo n.º 4
0
        public SolutionExtender(NRefactory.Solution solution)
        {
            Ensure.ArgumentNotNull(solution, "solution");

            Solution = solution;
        }
Exemplo n.º 5
0
 public SolutionManager(NRefactory.Solution solution, IVisualStudioEventProxy visualStudioEvents)
     : this(new SolutionExtender(solution), visualStudioEvents)
 {
 }