public ProjectContentContainer(MSBuildBasedProject project, IProjectContent initialProjectContent) { if (project == null) throw new ArgumentNullException("project"); this.project = project; this.projectContent = initialProjectContent.SetAssemblyName(project.AssemblyName).SetLocation(project.OutputAssemblyFullPath); this.assemblyModel = (IUpdateableAssemblyModel)project.AssemblyModel; this.assemblyModel.AssemblyName = this.projectContent.AssemblyName; this.assemblyModel.FullAssemblyName = this.projectContent.FullAssemblyName; this.cacheFileName = GetCacheFileName(project.FileName); SD.ProjectService.ProjectItemAdded += OnProjectItemAdded; SD.ProjectService.ProjectItemRemoved += OnProjectItemRemoved; SD.AssemblyParserService.AssemblyRefreshed += OnAssemblyRefreshed; List<FileName> filesToParse = new List<FileName>(); foreach (var file in project.Items.OfType<FileProjectItem>()) { if (IsParseableFile(file)) { var fileName = file.FileName; parserService.AddOwnerProject(fileName, project, startAsyncParse: false, isLinkedFile: file.IsLink); filesToParse.Add(fileName); } } SD.ParserService.LoadSolutionProjectsThread.AddJob( monitor => Initialize(monitor, filesToParse), "Loading " + project.Name + "...", filesToParse.Count + LoadingReferencesWorkAmount); }
public Project(StructEx.Solution solution, string title, string fileName) : base(solution, title, fileName) { Files = new List <File>(); ProjectContent = new CSharpProjectContent(); ResolvedReferencedAssemblies = new List <IUnresolvedAssembly>(); ProjectContent = ProjectContent.SetAssemblyName(AssemblyName); ProjectContent = ProjectContent.SetProjectFileName(fileName); ProjectContent = ProjectContent.SetCompilerSettings(Utils.Convert.ToCompilerSettings(CompilerSettings)); foreach (var sourceCodeFile in MsBuildProject.GetItems("Compile")) { Files.Add(new File(this, Path.Combine(MsBuildProject.DirectoryPath, sourceCodeFile.EvaluatedInclude))); } var files = Files.Select(f => f.UnresolvedTypeSystemForFile); ProjectContent = ProjectContent.AddOrUpdateFiles(files); foreach (var projectReference in ReferencedProjects) { ProjectContent = ProjectContent.AddAssemblyReferences(new[] { new ProjectReference(projectReference) }); } ResolveAssemblies(); }
public ProjectContentContainer(MSBuildBasedProject project, IProjectContent initialProjectContent) { if (project == null) { throw new ArgumentNullException("project"); } this.project = project; this.projectContent = initialProjectContent.SetAssemblyName(project.AssemblyName).SetLocation(project.OutputAssemblyFullPath).AddAssemblyReferences(references); this.assemblyModel = (IUpdateableAssemblyModel)project.AssemblyModel; this.assemblyModel.AssemblyName = this.projectContent.AssemblyName; this.assemblyModel.FullAssemblyName = this.projectContent.FullAssemblyName; this.cacheFileName = GetCacheFileName(project.FileName); SD.ProjectService.ProjectItemAdded += OnProjectItemAdded; SD.ProjectService.ProjectItemRemoved += OnProjectItemRemoved; SD.AssemblyParserService.AssemblyRefreshed += OnAssemblyRefreshed; List <FileName> filesToParse = new List <FileName>(); foreach (var file in project.Items.OfType <FileProjectItem>()) { if (IsParseableFile(file)) { var fileName = file.FileName; parserService.AddOwnerProject(fileName, project, startAsyncParse: false, isLinkedFile: file.IsLink); filesToParse.Add(fileName); } } SD.ParserService.LoadSolutionProjectsThread.AddJob( monitor => Initialize(monitor, filesToParse), "Loading " + project.Name + "...", filesToParse.Count + LoadingReferencesWorkAmount); }
public CSharpProject( ICSharpFileFactory cSharpFileFactory, MicrosoftBuildProject msBuildProject, string title) { Title = title; AssemblyName = msBuildProject.AssemblyName; FileName = msBuildProject.FileName; CompilerSettings = #region new CompilerSettings new CompilerSettings { AllowUnsafeBlocks = msBuildProject.AllowUnsafeBlocks, CheckForOverflow = msBuildProject.CheckForOverflowUnderflow, }; CompilerSettings.ConditionalSymbols.AddRange(msBuildProject.DefineConstants); #endregion ProjectContent = new CSharpProjectContent(); ProjectContent = ProjectContent.SetAssemblyName(msBuildProject.AssemblyName); ProjectContent = ProjectContent.SetProjectFileName(msBuildProject.FileName.FullPath); ProjectContent = ProjectContent.SetCompilerSettings(CompilerSettings); Files = msBuildProject.CompiledFileNames.Select( f => cSharpFileFactory.BuildCSharpFile(this, new FilePath(f))).ToList(); ProjectContent = ProjectContent.AddOrUpdateFiles( Files.Select(f => f.UnresolvedTypeSystemForFile)); ProjectContent = ProjectContent.AddAssemblyReferences(msBuildProject.ReferencedAssemblies); }
void Init(string program) { pc = new CSharpProjectContent(); pc = pc.SetAssemblyName("MyAssembly"); unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem(); pc = pc.AddOrUpdateFiles(unresolvedFile); pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib }); compilation = pc.CreateCompilation(); }
public MemberResolver(IList <ParsedSourceFile> sourceFiles, IEnumerable <IAssemblyReference> assemblies, AssemblyDefinition assemblyDefinition) { project = null; lastFileName = null; this.sourceFiles = sourceFiles; Assemblies = assemblies; MainAssembly = assemblyDefinition; typeSystemCache = new ConcurrentDictionary <SyntaxTree, CSharpUnresolvedFile>(); project = new CSharpProjectContent(); project = project.AddAssemblyReferences(assemblies); project = project.SetAssemblyName(assemblyDefinition.FullName); AddOrUpdateFiles(); }
public void SetUp() { pc = new CSharpProjectContent(); pc = pc.SetAssemblyName("MyAssembly"); parsedFile = new CSharpParser().Parse(new StringReader(program), "program.cs").ToTypeSystem(); pc = pc.UpdateProjectContent(null, parsedFile); pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib }); compilation = pc.CreateCompilation(); baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1); nestedClass = baseClass.NestedTypes.Single(); derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2); systemClass = compilation.RootNamespace.GetChildNamespace("NS").GetTypeDefinition("System", 0); }
public void SetUp() { pc = new CSharpProjectContent(); pc = pc.SetAssemblyName("MyAssembly"); unresolvedFile = SyntaxTree.Parse(program, "program.cs").ToTypeSystem(); pc = pc.AddOrUpdateFiles(unresolvedFile); pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib }); compilation = pc.CreateCompilation(); baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1); nestedClass = baseClass.NestedTypes.Single(); derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2); systemClass = compilation.RootNamespace.GetChildNamespace("NS").GetTypeDefinition("System", 0); }
public void SetUp() { pc = new CSharpProjectContent(); pc = pc.SetAssemblyName("MyAssembly"); parsedFile = new CSharpParser().Parse(new StringReader(program), "program.cs").ToTypeSystem(); pc = pc.UpdateProjectContent(null, parsedFile); pc = pc.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib }); compilation = pc.CreateCompilation(); baseClass = compilation.RootNamespace.GetTypeDefinition("Base", 1); nestedClass = baseClass.NestedTypes.Single(); derivedClass = compilation.RootNamespace.GetTypeDefinition("Derived", 2); systemClass = compilation.FindType("NS.System, MyAssembly").GetDefinition(); }
public void SetAssemblyName(string newAssemblyName) { lock (lockObj) { if (!disposed) { if (projectContent.FullAssemblyName == newAssemblyName) { return; } projectContent = projectContent.SetAssemblyName(newAssemblyName); assemblyModel.AssemblyName = projectContent.AssemblyName; assemblyModel.FullAssemblyName = projectContent.FullAssemblyName; SD.ParserService.InvalidateCurrentSolutionSnapshot(); } } }
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) }); } }