public int IsSupported(string projectExt, XmlElement xmlDefinition) { if (projectExt == ".vcproj") { return(5); } if (VcProject.IsSupported(xmlDefinition)) { return(10); } return(0); }
public static ProjectConfiguration Show(string filename) { var ext = Path.GetExtension(filename); BaseVsProject vsProject = null; switch (ext.ToLower()) { case ".vcproj": vsProject = VcProject.Parse(filename); break; case ".csproj": vsProject = CSharpProject.Parse(filename); break; case ".dsp": vsProject = VisualCpp6Project.Parse(filename); break; default: MessageBox.Show("Project file not recognized"); return(null); } var f = new ProjectConfigurationsForm(); foreach (var cfg in vsProject.Configurations) { var item = f.listView.Items.Add(cfg.Name); item.SubItems.Add(cfg.Platform); item.Tag = cfg; } if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { return(f.listView.SelectedItems[0].Tag as ProjectConfiguration); } return(null); }
public static string LoadGuid(string fileName) { // check if a project with specified file is already cached if (_cachedProjects.ContainsKey(fileName)) { // return the guid of the cached project return(((ProjectBase)_cachedProjects[fileName]).Guid); } string projectFileName = ProjectFactory.GetProjectFileName(fileName); string projectExt = Path.GetExtension(projectFileName).ToLower( CultureInfo.InvariantCulture); // check if GUID of project is already cached if (!_cachedProjectGuids.Contains(fileName)) { if (projectExt == ".vbproj" || projectExt == ".csproj" || projectExt == ".vjsproj") { // add project GUID to cache _cachedProjectGuids[fileName] = ManagedProjectBase.LoadGuid(fileName); } else if (projectExt == ".vcproj") { // add project GUID to cache _cachedProjectGuids[fileName] = VcProject.LoadGuid(fileName); } else { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Unknown project file extension '{0}'.", projectExt, Location.UnknownLocation)); } } // return project GUID from cache return((string)_cachedProjectGuids[fileName]); }
private void Initialize() { VcProject vcProject = (VcProject)Project; // determine directory for storing intermediate build output for // current project build configuration string intermediateDir = FileUtils.CombinePaths(vcProject.ProjectDirectory.FullName, IntermediateDir); foreach (object projectFile in vcProject.ProjectFiles) { string fileName = null; VcConfigurationBase fileConfig = null; // the array list contains either strings or hashtables if (projectFile is string) { fileName = (string)projectFile; } else { Hashtable fileConfigurations = (Hashtable)projectFile; // obtain file configuration for current build configuration VcFileConfiguration configuration = (VcFileConfiguration) fileConfigurations[Name]; if (configuration != null && configuration.ExcludeFromBuild) { continue; } fileConfig = configuration; // determine relative path if (configuration == null) { // obtain relative path for other build configuration // as the relative is the same anyway foreach (DictionaryEntry de in fileConfigurations) { configuration = (VcFileConfiguration)de.Value; break; } } fileName = configuration.RelativePath; } string ext = Path.GetExtension(fileName).ToLower(CultureInfo.InvariantCulture); // if there's no specific file configuration (for the current // build configuration), then use the project configuration if (fileConfig == null) { fileConfig = this; } switch (ext) { case ".cpp": case ".c": if (!_sourceConfigs.ContainsKey(fileConfig)) { _sourceConfigs[fileConfig] = new ArrayList(1); } // add file to list of sources to build with this config ((ArrayList)_sourceConfigs[fileConfig]).Add(fileName); // register output file for linking _objFiles.Add(vcProject.GetObjOutputFile(fileName, fileConfig, intermediateDir)); break; case ".rc": if (!_rcConfigs.ContainsKey(fileConfig)) { _rcConfigs[fileConfig] = new ArrayList(1); } // add file to list of resources to build with this config ((ArrayList)_rcConfigs[fileConfig]).Add(fileName); // register output file for linking _objFiles.Add(vcProject.GetResourceOutputFile(fileName, fileConfig)); break; case ".idl": case ".odl": // ODL is used for old OLE objects if (!_idlConfigs.ContainsKey(fileConfig)) { _idlConfigs[fileConfig] = new ArrayList(1); } // add file to list of idl's to build with this config ((ArrayList)_idlConfigs[fileConfig]).Add(fileName); break; } } switch (Type) { case ConfigurationType.StaticLibrary: _outputPath = GetLibrarianOutputFile(intermediateDir); break; case ConfigurationType.Application: case ConfigurationType.DynamicLibrary: _outputPath = GetLinkerOutputFile(); break; case ConfigurationType.Makefile: string nmakeOutput = GetToolSetting(VcConfigurationBase.NMakeTool, "Output"); if (!String.IsNullOrEmpty(nmakeOutput)) { _outputPath = FileUtils.CombinePaths(Project.ProjectDirectory.FullName, nmakeOutput); } break; } // mark initialization complete _initialized = true; }
internal VcProjectConfiguration(XmlElement elem, VcProject parentProject, DirectoryInfo outputDir) : base(elem, parentProject, outputDir) { // determine relative output directory (outdir) XmlAttribute outputDirAttribute = elem.Attributes["OutputDirectory"]; if (outputDirAttribute != null) { _rawRelativeOutputDir = outputDirAttribute.Value; } // get intermediate directory and expand macros XmlAttribute intermidiateDirAttribute = elem.Attributes["IntermediateDirectory"]; if (intermidiateDirAttribute != null) { _rawIntermediateDir = intermidiateDirAttribute.Value; } // get referencespath directory and expand macros XmlAttribute referencesPathAttribute = elem.Attributes["ReferencesPath"]; if (referencesPathAttribute != null) { _rawReferencesPath = StringUtils.ConvertEmptyToNull(referencesPathAttribute.Value); } string managedExtentions = GetXmlAttributeValue(elem, "ManagedExtensions"); if (managedExtentions != null) { switch (managedExtentions.ToLower()) { case "false": case "0": _managedExtensions = false; break; case "true": case "1": _managedExtensions = true; break; default: throw new BuildException(String.Format("ManagedExtensions '{0}' is not supported yet.", managedExtentions)); } } // get configuration type string type = GetXmlAttributeValue(elem, "ConfigurationType"); if (type != null) { _type = (ConfigurationType)Enum.ToObject(typeof(ConfigurationType), int.Parse(type, CultureInfo.InvariantCulture)); } string wholeProgramOptimization = GetXmlAttributeValue(elem, "WholeProgramOptimization"); if (wholeProgramOptimization != null) { _wholeProgramOptimization = string.Compare(wholeProgramOptimization.Trim(), "true", true, CultureInfo.InvariantCulture) == 0; } string characterSet = GetXmlAttributeValue(elem, "CharacterSet"); if (characterSet != null) { _characterSet = (CharacterSet)Enum.ToObject(typeof(CharacterSet), int.Parse(characterSet, CultureInfo.InvariantCulture)); } // get MFC settings string useOfMFC = GetXmlAttributeValue(elem, "UseOfMFC"); if (useOfMFC != null) { _useOfMFC = (UseOfMFC)Enum.ToObject(typeof(UseOfMFC), int.Parse(useOfMFC, CultureInfo.InvariantCulture)); } // get ATL settings string useOfATL = GetXmlAttributeValue(elem, "UseOfATL"); if (useOfATL != null) { _useOfATL = (UseOfATL)Enum.ToObject(typeof(UseOfATL), int.Parse(useOfATL, CultureInfo.InvariantCulture)); } _linkerConfiguration = new LinkerConfig(this); }
public string LoadGuid(XmlElement xmlDefinition) { return(VcProject.LoadGuid(xmlDefinition)); }
private static ProjectBase CreateProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string projectPath) { // determine the filename of the project string projectFileName = ProjectFactory.GetProjectFileName(projectPath); // determine the extension of the project file string projectExt = Path.GetExtension(projectFileName).ToLower( CultureInfo.InvariantCulture); // holds the XML definition of the project XmlElement xmlDefinition; try { XmlDocument doc = LoadProjectXml(projectPath); xmlDefinition = doc.DocumentElement; } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Error loading project '{0}'.", projectPath), Location.UnknownLocation, ex); } // first identify project based on known file extensions switch (projectExt) { case ".vbproj": return(new VBProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); case ".csproj": return(new CSharpProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); case ".vjsproj": return(new JSharpProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); case ".vcproj": return(new VcProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); } // next, identify project based on XML definition if (VBProject.IsSupported(xmlDefinition)) { return(new VBProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); } else if (CSharpProject.IsSupported(xmlDefinition)) { return(new CSharpProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); } else if (JSharpProject.IsSupported(xmlDefinition)) { return(new JSharpProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); } else if (VcProject.IsSupported(xmlDefinition)) { return(new VcProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, referencesResolver, outputDir)); } // either the project file is invalid or we don't support it throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Project '{0}' is invalid or not supported (at this time).", projectPath), Location.UnknownLocation); }
public ProjectAdapter ImportProject(string fileName, string sccRoot) { var filename = fileName; var ext = Path.GetExtension(filename); BaseVsProject vsProject = null; switch (ext.ToLower()) { case ".vcproj": vsProject = VcProject.Parse(filename); break; case ".csproj": vsProject = CSharpProject.Parse(filename); break; case ".dsp": vsProject = VisualCpp6Project.Parse(filename); break; default: return(null); } if (vsProject == null) { return(null); } if (!sccRoot.EndsWith("/")) { sccRoot = sccRoot + "/"; } var project = new ProjectAdapter(new Project(), false) { BuildFile = this, Name = vsProject.Name, Path = GetPathRootedAtBuildsFile(vsProject.Filepath), SccPath = sccRoot + GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)).Replace("\\", "/") }; // check if project path is relative to mproj file switch (vsProject.Framework) { case ProjectFramework.VisualCpp2003: project.Framework = "vc71"; break; case ProjectFramework.VisualCpp2005: project.Framework = "vc8"; break; case ProjectFramework.VisualCpp6: project.Framework = "vc6"; break; case ProjectFramework.VisualCs2005: project.Framework = "cs"; break; case ProjectFramework.VisualCs2003: project.Framework = "vc71"; break; } bool bConfigurationFound = false; var projectOutput = new ProjectOutputAdapter(); foreach (var conf in vsProject.Configurations) { if (conf.Name.ToLower().Contains("release")) { project.BuildOpt = "\"" + conf.Name + "\" " + conf.Platform; projectOutput.PathList.Add(Path.Combine(GetPathRootedAtBuildsFile(conf.OutputPath), "*.*")); bConfigurationFound = true; project.Target.PlatformName = conf.Platform; project.Target.ConfigurationName = conf.Name; break; } } if (!bConfigurationFound) { if (vsProject.Framework == ProjectFramework.VisualCpp6) { projectOutput.PathList.Add( Path.Combine(GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)), @"release\*.*")); } else { projectOutput.PathList.Add( Path.Combine(GetPathRootedAtBuildsFile(Path.GetDirectoryName(vsProject.Filepath)), "*.*")); } } project.OutputInformation.Add(projectOutput); return(project); }