private IProjectContent CreateCSharpProjectContent(string fileName) { IProjectContent pc = new CSharpProjectContent(); pc = pc.SetAssemblyName(AssemblyName); pc = pc.SetProjectFileName(fileName); pc = pc.SetCompilerSettings(CompilerSettings); return(pc); }
public CSharpProject(Solution solution, string title, string fileName) { // Normalize the file name fileName = Path.GetFullPath(fileName); this.Solution = solution; this.Title = title; this.FileName = fileName; // Use MSBuild to open the .csproj var msbuildProject = new Microsoft.Build.Evaluation.Project(fileName); // Figure out some compiler settings this.AssemblyName = msbuildProject.GetPropertyValue("AssemblyName"); this.CompilerSettings.AllowUnsafeBlocks = GetBoolProperty(msbuildProject, "AllowUnsafeBlocks") ?? false; this.CompilerSettings.CheckForOverflow = GetBoolProperty(msbuildProject, "CheckForOverflowUnderflow") ?? false; string defineConstants = msbuildProject.GetPropertyValue("DefineConstants"); foreach (string symbol in defineConstants.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { this.CompilerSettings.ConditionalSymbols.Add(symbol.Trim()); } // Initialize the unresolved type system IProjectContent pc = new CSharpProjectContent(); pc = pc.SetAssemblyName(this.AssemblyName); pc = pc.SetProjectFileName(fileName); pc = pc.SetCompilerSettings(this.CompilerSettings); // Parse the C# code files foreach (var item in msbuildProject.GetItems("Compile")) { var file = new CSharpFile(this, Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude)); Files.Add(file); } // Add parsed files to the type system pc = pc.AddOrUpdateFiles(Files.Select(f => f.UnresolvedTypeSystemForFile)); // Add referenced assemblies: foreach (string assemblyFile in ResolveAssemblyReferences(msbuildProject)) { IUnresolvedAssembly assembly = solution.LoadAssembly(assemblyFile); pc = pc.AddAssemblyReferences(new [] { 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); pc = pc.AddAssemblyReferences(new[] { new ProjectReference(referencedFileName) }); } this.ProjectContent = pc; }
// Token: 0x06000021 RID: 33 RVA: 0x0000291C File Offset: 0x00000B1C private IProjectContent GetCSharpProjectContent(VSProject vsproject) { IProjectContent projectContent = new CSharpProjectContent(); Properties properties = vsproject.Project.ConfigurationManager.ActiveConfiguration.Properties; string fullName = vsproject.Project.FullName; projectContent = projectContent.SetAssemblyName(vsproject.Project.Properties.Item("AssemblyName").Value.ToString()); projectContent = projectContent.SetProjectFileName(Path.GetFileName(fullName)); projectContent = projectContent.SetLocation(fullName); return(projectContent.SetCompilerSettings(this.GetCompilerSettingsFromVSProject(vsproject))); }
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 Project msbuildProject = new Project(fileName, null, "14.0"); // 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 IProjectContent pc = new CSharpProjectContent(); pc = pc.SetAssemblyName(AssemblyName); pc = pc.SetProjectFileName(fileName); pc = pc.SetCompilerSettings(CompilerSettings); // Parse the C# code files foreach (CSharpFile file in msbuildProject.GetItems("Compile").Select(item => new CSharpFile(this, Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude)))) { Files.Add(file); } // Add parsed files to the type system pc = pc.AddOrUpdateFiles(Files.Select(f => f.UnresolvedTypeSystemForFile)); // Add referenced assemblies: pc = ResolveAssemblyReferences(msbuildProject).Select(solution.LoadAssembly).Aggregate(pc, (current, assembly) => current.AddAssemblyReferences(assembly)); // Add project references: pc = msbuildProject.GetItems("ProjectReference").Select(item => Path.Combine(msbuildProject.DirectoryPath, item.EvaluatedInclude)).Select(Path.GetFullPath).Aggregate(pc, (current, referencedFileName) => current.AddAssemblyReferences(new ProjectReference(referencedFileName))); ProjectContent = pc; }