public ManagedProjectReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir) : base(referencesResolver, parent) { if (xmlDefinition == null) { throw new ArgumentNullException("xmlDefinition"); } if (solution == null) { throw new ArgumentNullException("solution"); } if (tfc == null) { throw new ArgumentNullException("tfc"); } if (gacCache == null) { throw new ArgumentNullException("gacCache"); } XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"]; if (privateAttribute != null) { _isPrivateSpecified = true; _isPrivate = bool.Parse(privateAttribute.Value); } // determine path of project file string projectFile = solution.GetProjectFileFromGuid( xmlDefinition.GetAttribute("Project")); // load referenced project _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile); }
private string[] GetAllReferencedModules(string module) { string fullPathToModule = FileUtils.GetFullPath(module); string moduleDirectory = Path.GetDirectoryName(fullPathToModule); Hashtable allReferences = new Hashtable(); Hashtable unresolvedReferences = new Hashtable(); try { allReferences.Add(fullPathToModule, null); unresolvedReferences.Add(fullPathToModule, null); while (unresolvedReferences.Count > 0) { IDictionaryEnumerator unresolvedEnumerator = unresolvedReferences.GetEnumerator(); unresolvedEnumerator.MoveNext(); string referenceToResolve = (string)unresolvedEnumerator.Key; unresolvedReferences.Remove(referenceToResolve); ReferencesResolver.AppendReferencedModulesLocatedInGivenDirectory( moduleDirectory, referenceToResolve, ref allReferences, ref unresolvedReferences); } } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Error resolving module references of '{0}'.", fullPathToModule), Location.UnknownLocation, ex); } string[] result = new string[allReferences.Keys.Count]; allReferences.Keys.CopyTo(result, 0); return(result); }
public VcWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { string typeLibrary = GetTypeLibrary(); // determine name of type library _name = GetTypeLibraryName(GetTypeLibrary()); // determine wrapper tool XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"]; if (toolAttribute == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Wrapper tool for reference \"{0}\" in project \"{1}\" could" + " not be determined.", Name, Parent.Name), Location.UnknownLocation); } _wrapperTool = toolAttribute.Value; // determine if there's a primary interop assembly for the typelib _primaryInteropAssembly = GetPrimaryInteropAssembly(); // determine filename of wrapper assembly _wrapperAssembly = ResolveWrapperAssembly(); }
public ManagedWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache, ProjectSettings projectSettings) : base(xmlDefinition, referencesResolver, parent, gacCache) { if (projectSettings == null) { throw new ArgumentNullException("projectSettings"); } _projectSettings = projectSettings; // determine name of wrapper reference XmlAttribute wrapperNameAttribute = XmlDefinition.Attributes["Name"]; if (wrapperNameAttribute != null) { _name = wrapperNameAttribute.Value; } // determine wrapper tool XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"]; if (toolAttribute == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Wrapper tool for reference \"{0}\" in project \"{1}\" could" + " not be determined.", Name, Parent.Name), Location.UnknownLocation); } _wrapperTool = toolAttribute.Value; // determine if there's a primary interop assembly for the typelib _primaryInteropAssembly = GetPrimaryInteropAssembly(); // determine filename of wrapper assembly _wrapperAssembly = ResolveWrapperAssembly(); }
/// <summary> /// Initializes a new instance of the <see cref="ProjectBase" /> class. /// </summary> protected ProjectBase(XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection temporaryFiles, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir) { if (xmlDefinition == null) { throw new ArgumentNullException("xmlDefinition"); } if (solutionTask == null) { throw new ArgumentNullException("solutionTask"); } if (temporaryFiles == null) { throw new ArgumentNullException("temporaryFiles"); } if (gacCache == null) { throw new ArgumentNullException("gacCache"); } if (referencesResolver == null) { throw new ArgumentNullException("referencesResolver"); } _projectConfigurations = new ConfigurationDictionary(); _buildConfigurations = new ConfigurationDictionary(); _extraOutputFiles = CollectionsUtil.CreateCaseInsensitiveHashtable(); // ensure the specified project is actually supported by this project VerifyProjectXml(xmlDefinition); _solutionTask = solutionTask; _temporaryFiles = temporaryFiles; _outputDir = outputDir; _gacCache = gacCache; _refResolver = referencesResolver; _productVersion = DetermineProductVersion(xmlDefinition); }
public MSBuildProjectReference( ReferencesResolver referencesResolver, ProjectBase parent, ProjectBase project, bool isPrivateSpecified, bool isPrivate) :base(referencesResolver, parent) { _helper = new MSBuildReferenceHelper(isPrivateSpecified, isPrivate); _project = project; }
protected SolutionBase(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : this(tfc, solutionTask) { if (solutionTask.SolutionFile != null) { _file = solutionTask.SolutionFile; } else { LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false); LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true); LoadProjects(gacCache, refResolver, CollectionsUtil.CreateCaseInsensitiveHashtable()); } }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new Microsoft.Build.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); SetPlatform (platform); if (outputDir != null) _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration (cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } }
protected FileReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(referencesResolver, parent) { if (xmlDefinition == null) { throw new ArgumentNullException("xmlDefinition"); } if (gacCache == null) { throw new ArgumentNullException("gacCache"); } _xmlDefinition = xmlDefinition; _gacCache = gacCache; }
public MSBuildProjectReference( ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir, string pguid, string pname, string rpath, string priv) : base(referencesResolver, parent) { _helper = new MSBuildReferenceHelper(priv, true); string projectFile = solution.GetProjectFileFromGuid(pguid); _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile); }
public MSBuildAssemblyReference(XmlElement xe, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache, string name, string priv, string hintpath) : base(new DummyXmlElement(xe.OwnerDocument), referencesResolver, parent, gacCache) { if (name.Contains(",")) { //fully specified reference. Hmmm - just ignore it for now. name = name.Split(',')[0]; if (hintpath.Length == 0) //hintpath workaround hintpath = "." + Path.DirectorySeparatorChar + name + ".dll"; } _name = name; _helper = new MSBuildReferenceHelper(priv, false); _hintpath = hintpath; _assemblyFile = ResolveAssemblyReference(); }
public ManagedAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"]; if (privateAttribute != null) { _isPrivateSpecified = true; _isPrivate = bool.Parse(privateAttribute.Value); } // determine name of reference XmlAttribute assemblyNameAttribute = XmlDefinition.Attributes["AssemblyName"]; if (assemblyNameAttribute != null) { _name = assemblyNameAttribute.Value; } _assemblyFile = ResolveAssemblyReference(); }
public VcAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { XmlAttribute privateAttribute = xmlDefinition.Attributes["CopyLocal"]; if (privateAttribute != null) { _isPrivateSpecified = true; _isPrivate = bool.Parse(privateAttribute.Value); } // determine name of reference by taking filename part of relative // path, without extension XmlAttribute relativePathAttribute = XmlDefinition.Attributes["RelativePath"]; if (relativePathAttribute != null) { _name = Path.GetFileNameWithoutExtension(relativePathAttribute.Value); } _assemblyFile = ResolveAssemblyReference(); }
/// <summary> /// Initializes a new instance of the <see cref="VBProject"/> class. /// </summary> /// <param name="solution">The solution.</param> /// <param name="projectPath">The project path.</param> /// <param name="xmlDefinition">The XML definition.</param> /// <param name="solutionTask">The solution task.</param> /// <param name="tfc">The TFC.</param> /// <param name="gacCache">The gac cache.</param> /// <param name="refResolver">The reference resolver.</param> /// <param name="outputDir">The output dir.</param> public VBProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { _imports = new NamespaceImportCollection(); // process namespace imports XmlNodeList imports = xmlDefinition.SelectNodes("//Imports/Import"); foreach (XmlElement import in imports) { XmlAttribute nsAttribute = import.Attributes["Namespace"]; if (nsAttribute != null) { string nameSpace = nsAttribute.Value.ToString( CultureInfo.InvariantCulture); _imports.Add(new NamespaceImport(nameSpace)); } } }
public VcWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { // determine name of type library _name = GetTypeLibraryName(GetTypeLibrary()); // determine wrapper tool XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"]; if (toolAttribute == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Wrapper tool for reference \"{0}\" in project \"{1}\" could" + " not be determined.", Name, Parent.Name), Location.UnknownLocation); } _wrapperTool = toolAttribute.Value; // determine if there's a primary interop assembly for the typelib _primaryInteropAssembly = GetPrimaryInteropAssembly(); // determine filename of wrapper assembly _wrapperAssembly = ResolveWrapperAssembly(); }
public SolutionBase LoadSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { if (solutionTask.SolutionFile == null) { return new GenericSolution(solutionTask, tfc, gacCache, refResolver); } else { // determine the solution file format version // will hold the content of the solution file string fileContents; using (StreamReader sr = new StreamReader(solutionTask.SolutionFile.FullName, Encoding.Default, true)) { fileContents = sr.ReadToEnd(); } ISolutionBuildProvider provider = FindProvider(fileContents); if (provider != null) { return provider.GetInstance(fileContents, solutionTask, tfc, gacCache, refResolver); } throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Solution format of file '{0}' is not supported.", solutionTask.SolutionFile), Location.UnknownLocation); } }
protected string GetPrimaryInteropAssembly() { string typeLibVersionKey = string.Format(CultureInfo.InvariantCulture, @"TYPELIB\{0}\{1}", TypeLibGuid, TypeLibVersion); string assemblyFile = null; using (RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(typeLibVersionKey)) { if (registryKey != null && registryKey.GetValue("PrimaryInteropAssemblyName") != null) { string primaryInteropAssemblyName = (string)registryKey.GetValue("PrimaryInteropAssemblyName"); try { // get filename of primary interop assembly assemblyFile = ReferencesResolver.GetAssemblyFileName( primaryInteropAssemblyName); } catch (Exception ex) { // only have build fail if we're actually dealing with a // reference to a primary interop assembly // // certain tools (such as Office) register the name of // the primary interop assembly of the typelib, but the // actual primary interop assembly is not always installed if (WrapperTool == "primary") { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Primary Interop Assembly \"{0}\", referenced by project" + " \"{1}\", could not be loaded.", primaryInteropAssemblyName, Parent.Name), Location.UnknownLocation, ex); } } } } return(assemblyFile); }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new NAnt.MSBuild.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); if (platform.Length > 0) { _msproj.GlobalProperties.SetProperty("Platform", platform.Replace(" ", string.Empty)); } if (outputDir != null) { _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); } bool generateDoc = false; //bool targwarnings = true; foreach (NAnt.Core.Tasks.PropertyTask property in solutionTask.CustomProperties) { string val; // expand properties in context of current project for non-dynamic properties if (!property.Dynamic) { val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.GetLocation() ); } else { val = property.Value; } switch (property.PropertyName) { //if (property.PropertyName == "TargetWarnings") targwarnings = Boolean.Parse(val); case "GenerateDocumentation": generateDoc = Boolean.Parse(val); break; default: _msproj.GlobalProperties.SetProperty(property.PropertyName, val); break; } } //set tools version to the msbuild version we got loaded _msproj.ToolsVersion = SolutionTask.Project.TargetFramework.Version.ToString(); //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly _msproj.GlobalProperties.SetProperty("TargetFrameworkVersion", "v" + SolutionTask.Project.TargetFramework.Version.ToString()); //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly ////check if we targeting something else and throw a warning //if (targwarnings) //{ // string verString = _msproj.GetEvaluatedProperty("TargetFrameworkVersion"); // if (verString != null) // { // if (verString.StartsWith("v")) verString = verString.Substring(1); // Version ver = new Version(verString); // if (!ver.Equals(SolutionTask.Project.TargetFramework.Version)) // { // Log(Level.Warning, "Project '{1}' targets framework {0}.", verString, Name); // } // } //} //project configuration ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration (cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); NAnt.MSBuild.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); string ext = r.GetMetadata("ExecutableExtension"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath, ext); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } if(generateDoc) { string xmlDocBuildFile = FileUtils.CombinePaths(OutputPath, this.Name + ".xml"); //// make sure the output directory for the doc file exists //if (!Directory.Exists(Path.GetDirectoryName(xmlDocBuildFile))) { // Directory.CreateDirectory(Path.GetDirectoryName(xmlDocBuildFile)); //} // add built documentation file as extra output file ExtraOutputFiles[xmlDocBuildFile] = Path.GetFileName(xmlDocBuildFile); _msproj.GlobalProperties.SetProperty("DocumentationFile", xmlDocBuildFile); } }
public JSharpProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { }
private 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); // fast-skip setup projects since the project files is not XML-based if (projectExt == ".vdproj") { return null; } // 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); } IProjectBuildProvider provider = FindProvider(projectExt, xmlDefinition); if (provider != null) { return provider.GetInstance(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 VBProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { _imports = new NamespaceImportCollection(); // process namespace imports XmlNodeList imports = xmlDefinition.SelectNodes("//Imports/Import"); foreach (XmlElement import in imports) { XmlAttribute nsAttribute = import.Attributes["Namespace"]; if (nsAttribute != null) { string nameSpace = nsAttribute.Value.ToString( CultureInfo.InvariantCulture); _imports.Add(new NamespaceImport(nameSpace)); } } }
public RosarioSolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionContent, solutionTask, tfc, gacCache, refResolver) { }
public WhidbeySolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) { Regex reProjects = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline); MatchCollection projectMatches = reProjects.Matches(solutionContent); Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable(); foreach (Match projectMatch in projectMatches) { string project = projectMatch.Groups["project"].Value; string guid = projectMatch.Groups["guid"].Value; string package = projectMatch.Groups["package"].Value; // bug #1732361: skip solution folders if (package == SolutionFolder_GUID) { continue; } // translate partial project path or URL to absolute path string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName, project); if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath)) { RecursiveLoadTemplateProject(fullProjectPath); } else { // add project entry to collection ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath)); } // set-up project dependencies Regex reDependencies = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline); MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value); foreach (Match dependencyMatch in dependencyMatches) { string dependency = dependencyMatch.Groups["dep"].Value; if (!explicitProjectDependencies.ContainsKey(guid)) { explicitProjectDependencies[guid] = CollectionsUtil.CreateCaseInsensitiveHashtable(); } ((Hashtable)explicitProjectDependencies[guid])[dependency] = null; } // set-up project configuration Regex reProjectBuildConfig = new Regex(@"^\s+" + Regex.Escape(guid) + @"\.(?<solutionConfiguration>[^|]+)\|(?<solutionPlatform>[^.]+)\.Build\.0\s*=\s*(?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline); MatchCollection projectBuildMatches = reProjectBuildConfig.Matches(solutionContent); ProjectEntry projectEntry = ProjectEntries [guid]; if (projectEntry == null) { // TODO: determine if we should report an error if a build // configuration is defined for a project that does not // exist in the solution continue; } // holds mapping between project configuration(s) and solution(s) ConfigurationMap buildConfigurations = new ConfigurationMap( projectBuildMatches.Count); for (int i = 0; i < projectBuildMatches.Count; i++) { Match projectBuildMatch = projectBuildMatches [i]; string solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value; string solutionPlatform = projectBuildMatch.Groups["solutionPlatform"].Value; string projectConfigName = projectBuildMatch.Groups["projectConfiguration"].Value; string projectPlatform = projectBuildMatch.Groups["projectPlatform"].Value; Configuration solutionConfig = new Configuration( solutionConfigName, solutionPlatform); Configuration projectConfig = new Configuration( projectConfigName, projectPlatform); buildConfigurations [solutionConfig] = projectConfig; } // add map to corresponding project entry projectEntry.BuildConfigurations = buildConfigurations; } LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false); LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true); LoadProjects(gacCache, refResolver, explicitProjectDependencies); }
public Solution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) { Regex reProjects = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline); MatchCollection projectMatches = reProjects.Matches(solutionContent); Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable(); foreach (Match projectMatch in projectMatches) { string project = projectMatch.Groups["project"].Value; string guid = projectMatch.Groups["guid"].Value; // translate partial project path or URL to absolute path string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName, project); // check if project file actually exists if (!System.IO.File.Exists(fullProjectPath)) { throw CreateProjectDoesNotExistException(fullProjectPath); } bool isEnterpriseTemplateProject = ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath); if (isEnterpriseTemplateProject) { RecursiveLoadTemplateProject(fullProjectPath); } else { // add project entry to collection ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath)); } // set-up project dependencies Regex reDependencies = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline); MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value); foreach (Match dependencyMatch in dependencyMatches) { string dependency = dependencyMatch.Groups["dep"].Value; // bug #1534864: an Enterprise Template project actually // defines dependencies for the projects it contains, and // is not added as a project itself // // Note: for non-ET projects both the "guid" and "dep" group // have the same value, which is the guid of the project // that the project containing the dependencies section // depends upon string projectGuid = isEnterpriseTemplateProject ? dependencyMatch.Groups["guid"].Value : guid; if (!explicitProjectDependencies.ContainsKey(projectGuid)) { explicitProjectDependencies[projectGuid] = CollectionsUtil.CreateCaseInsensitiveHashtable(); } ((Hashtable) explicitProjectDependencies[projectGuid])[dependency] = null; } // set-up project configuration Regex reProjectBuildConfig = new Regex(@"^\s+" + guid + @"\.(?<solutionConfiguration>[^|]+)\|?(?<solutionPlatform>[^\.]?)\.Build\.0\s*=\s* (?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline); MatchCollection projectBuildMatches = reProjectBuildConfig.Matches(solutionContent); ProjectEntry projectEntry = ProjectEntries [guid]; if (projectEntry == null) { // TODO: determine if we should report an error if a build // configuration is defined for a project that does not // exist in the solution continue; } // holds mapping between project configuration(s) and solution(s) ConfigurationMap buildConfigurations = new ConfigurationMap( projectBuildMatches.Count); for (int i = 0; i < projectBuildMatches.Count; i++) { Match projectBuildMatch = projectBuildMatches [i]; string solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value; string solutionPlatform = projectBuildMatch.Groups["solutionPlatform"].Value; string projectConfigName = projectBuildMatch.Groups["projectConfiguration"].Value; string projectPlatform = projectBuildMatch.Groups["projectPlatform"].Value; Configuration solutionConfig = new Configuration( solutionConfigName, solutionPlatform); Configuration projectConfig = new Configuration( projectConfigName, projectPlatform); buildConfigurations [solutionConfig] = projectConfig; } // add map to corresponding project entry projectEntry.BuildConfigurations = buildConfigurations; } LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false); LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true); LoadProjects(gacCache, refResolver, explicitProjectDependencies); }
/// <summary> /// Loads the projects from the file system and stores them in an /// instance variable. /// </summary> /// <param name="gacCache"><see cref="GacCache" /> instance to use to determine whether an assembly is located in the Global Assembly Cache.</param> /// <param name="refResolver"><see cref="ReferencesResolver" /> instance to use to determine location and references of assemblies.</param> /// <param name="explicitProjectDependencies">TODO</param> /// <exception cref="BuildException">A project GUID in the solution file does not match the actual GUID of the project in the project file.</exception> protected void LoadProjects(GacCache gacCache, ReferencesResolver refResolver, Hashtable explicitProjectDependencies) { Log(Level.Verbose, "Loading projects..."); FileSet excludes = _solutionTask.ExcludeProjects; foreach (ProjectEntry projectEntry in ProjectEntries) { string projectPath = projectEntry.Path; string projectGuid = projectEntry.Guid; // determine whether project is on case-sensitive filesystem, bool caseSensitive = PlatformHelper.IsVolumeCaseSensitive(projectPath); // indicates whether the project should be skipped (excluded) bool skipProject = false; // check whether project should be excluded from build foreach (string excludedProjectFile in excludes.FileNames) { if (string.Compare(excludedProjectFile, projectPath, !caseSensitive, CultureInfo.InvariantCulture) == 0) { Log(Level.Verbose, "Excluding project '{0}'.", projectPath); // do not load project skipProject = true; // we have a match, so quit looking break; } } if (skipProject) { // remove dependencies for excluded projects if (explicitProjectDependencies.ContainsKey(projectGuid)) { explicitProjectDependencies.Remove(projectGuid); } // project was excluded, move on to next project continue; } Log(Level.Verbose, "Loading project '{0}'.", projectPath); ProjectBase p = _solutionTask.ProjectFactory.LoadProject(this, _solutionTask, _tfc, gacCache, refResolver, _outputDir, projectPath); if (p == null) { Log(Level.Warning, "Project '{0}' is of unsupported type. Skipping.", projectPath); // skip the project continue; } if (p.Guid == null || p.Guid.Length == 0) { p.Guid = FindGuidFromPath(projectPath); } // add project to entry projectEntry.Project = p; // set project build configuration SetProjectBuildConfiguration(projectEntry); } // add explicit dependencies (as set in VS.NET) to individual projects foreach (DictionaryEntry dependencyEntry in explicitProjectDependencies) { string projectGuid = (string)dependencyEntry.Key; Hashtable dependencies = (Hashtable)dependencyEntry.Value; ProjectEntry projectEntry = ProjectEntries[projectGuid]; if (projectEntry == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Dependencies for project \'{0}\' could not be analyzed." + " Project is not included.", projectGuid), Location.UnknownLocation); } ProjectBase project = projectEntry.Project; // make sure project is loaded if (project == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Dependencies for project \'{0}\' could not be analyzed." + " Project is not loaded.", projectGuid), Location.UnknownLocation); } foreach (string dependentProjectGuid in dependencies.Keys) { ProjectEntry dependentEntry = ProjectEntries[dependentProjectGuid]; if (dependentEntry == null || dependentEntry.Project == null) { Log(Level.Warning, "Project \"{0}\": ignored dependency" + " on project \"{1}\", which is not included.", project.Name, dependentProjectGuid); continue; } project.ProjectDependencies.Add(dependentEntry.Project); } } }
/// <summary> /// Loads the projects from the file system and stores them in an /// instance variable. /// </summary> /// <param name="gacCache"><see cref="GacCache" /> instance to use to determine whether an assembly is located in the Global Assembly Cache.</param> /// <param name="refResolver"><see cref="ReferencesResolver" /> instance to use to determine location and references of assemblies.</param> /// <param name="explicitProjectDependencies">TODO</param> /// <exception cref="BuildException">A project GUID in the solution file does not match the actual GUID of the project in the project file.</exception> protected void LoadProjects(GacCache gacCache, ReferencesResolver refResolver, Hashtable explicitProjectDependencies) { Log(Level.Verbose, "Loading projects..."); FileSet excludes = _solutionTask.ExcludeProjects; foreach (ProjectEntry projectEntry in ProjectEntries) { string projectPath = projectEntry.Path; string projectGuid = projectEntry.Guid; // determine whether project is on case-sensitive filesystem, bool caseSensitive = PlatformHelper.IsVolumeCaseSensitive(projectPath); // indicates whether the project should be skipped (excluded) bool skipProject = false; // check whether project should be excluded from build foreach (string excludedProjectFile in excludes.FileNames) { if (string.Compare(excludedProjectFile, projectPath, !caseSensitive, CultureInfo.InvariantCulture) == 0) { Log(Level.Verbose, "Excluding project '{0}'.", projectPath); // do not load project skipProject = true; // we have a match, so quit looking break; } } if (skipProject) { // remove dependencies for excluded projects if (explicitProjectDependencies.ContainsKey(projectGuid)) { explicitProjectDependencies.Remove(projectGuid); } // project was excluded, move on to next project continue; } Log(Level.Verbose, "Loading project '{0}'.", projectPath); ProjectBase p = _solutionTask.ProjectFactory.LoadProject(this, _solutionTask, _tfc, gacCache, refResolver, _outputDir, projectPath); if (p == null) { Log(Level.Warning, "Project '{0}' is of unsupported type. Skipping.", projectPath); // skip the project continue; } if (p.Guid == null || p.Guid == string.Empty) { p.Guid = FindGuidFromPath(projectPath); } // add project to entry projectEntry.Project = p; // set project build configuration SetProjectBuildConfiguration(projectEntry); } // add explicit dependencies (as set in VS.NET) to individual projects foreach (DictionaryEntry dependencyEntry in explicitProjectDependencies) { string projectGuid = (string) dependencyEntry.Key; Hashtable dependencies = (Hashtable) dependencyEntry.Value; ProjectEntry projectEntry = ProjectEntries[projectGuid]; if (projectEntry == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Dependencies for project \'{0}\' could not be analyzed." + " Project is not included.", projectGuid), Location.UnknownLocation); } ProjectBase project = projectEntry.Project; // make sure project is loaded if (project == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Dependencies for project \'{0}\' could not be analyzed." + " Project is not loaded.", projectGuid), Location.UnknownLocation); } foreach (string dependentProjectGuid in dependencies.Keys) { ProjectEntry dependentEntry = ProjectEntries[dependentProjectGuid]; if (dependentEntry == null || dependentEntry.Project == null) { Log(Level.Warning, "Project \"{0}\": ignored dependency" + " on project \"{1}\", which is not included.", project.Name, dependentProjectGuid); continue; } project.ProjectDependencies.Add(dependentEntry.Project); } } }
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 WhidbeySolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) { Regex reProjects = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline); MatchCollection projectMatches = reProjects.Matches(solutionContent); Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable(); foreach (Match projectMatch in projectMatches) { string project = projectMatch.Groups["project"].Value; string guid = projectMatch.Groups["guid"].Value; string package = projectMatch.Groups["package"].Value; // bug #1732361: skip solution folders if (package == SolutionFolder_GUID) continue; // translate partial project path or URL to absolute path string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName, project); if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath)) { RecursiveLoadTemplateProject(fullProjectPath); } else { // add project entry to collection ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath)); } // set-up project dependencies Regex reDependencies = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline); MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value); foreach (Match dependencyMatch in dependencyMatches) { string dependency = dependencyMatch.Groups["dep"].Value; if (!explicitProjectDependencies.ContainsKey(guid)) { explicitProjectDependencies[guid] = CollectionsUtil.CreateCaseInsensitiveHashtable(); } ((Hashtable)explicitProjectDependencies[guid])[dependency] = null; } // set-up project configuration Regex reProjectBuildConfig = new Regex(@"^\s+" + Regex.Escape(guid) + @"\.(?<solutionConfiguration>[^|]+)\|(?<solutionPlatform>[^.]+)\.Build\.0\s*=\s*(?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline); MatchCollection projectBuildMatches = reProjectBuildConfig.Matches(solutionContent); ProjectEntry projectEntry = ProjectEntries [guid]; if (projectEntry == null) { // TODO: determine if we should report an error if a build // configuration is defined for a project that does not // exist in the solution continue; } // holds mapping between project configuration(s) and solution(s) ConfigurationMap buildConfigurations = new ConfigurationMap( projectBuildMatches.Count); for (int i = 0; i < projectBuildMatches.Count; i++) { Match projectBuildMatch = projectBuildMatches [i]; string solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value; string solutionPlatform = projectBuildMatch.Groups["solutionPlatform"].Value; string projectConfigName = projectBuildMatch.Groups["projectConfiguration"].Value; string projectPlatform = projectBuildMatch.Groups["projectPlatform"].Value; Configuration solutionConfig = new Configuration( solutionConfigName, solutionPlatform); Configuration projectConfig = new Configuration( projectConfigName, projectPlatform); buildConfigurations [solutionConfig] = projectConfig; } // add map to corresponding project entry projectEntry.BuildConfigurations = buildConfigurations; } LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false); LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true); LoadProjects(gacCache, refResolver, explicitProjectDependencies); }
public SolutionBase LoadSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { if (solutionTask.SolutionFile == null) { return(new GenericSolution(solutionTask, tfc, gacCache, refResolver)); } else { // determine the solution file format version // will hold the content of the solution file string fileContents; using (StreamReader sr = new StreamReader(solutionTask.SolutionFile.FullName, Encoding.Default, true)) { fileContents = sr.ReadToEnd(); } ISolutionBuildProvider provider = FindProvider(fileContents); if (provider != null) { return(provider.GetInstance(fileContents, solutionTask, tfc, gacCache, refResolver)); } throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Solution format of file '{0}' is not supported.", solutionTask.SolutionFile), Location.UnknownLocation); } }
public SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { return(new WhidbeySolution(solutionContent, solutionTask, tfc, gacCache, refResolver)); }
protected AssemblyReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { }
public VcProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { if (projectPath == null) { throw new ArgumentNullException("projectPath"); } _references = new ArrayList(); _clArgMap = VcArgumentMap.CreateCLArgumentMap(); _linkerArgMap = VcArgumentMap.CreateLinkerArgumentMap(); _midlArgMap = VcArgumentMap.CreateMidlArgumentMap(); _projectPath = FileUtils.GetFullPath(projectPath); _name = xmlDefinition.GetAttribute("Name"); _guid = xmlDefinition.GetAttribute("ProjectGUID"); XmlNodeList configurationNodes = xmlDefinition.SelectNodes("//Configurations/Configuration"); foreach (XmlElement configElem in configurationNodes) { VcProjectConfiguration config = new VcProjectConfiguration(configElem, this, OutputDir); ProjectConfigurations[new Configuration (config.Name, config.PlatformName)] = config; } XmlNodeList references = xmlDefinition.SelectNodes("//References/child::*"); foreach (XmlElement referenceElem in references) { ReferenceBase reference = CreateReference(solution, referenceElem); _references.Add(reference); } XmlNodeList fileNodes = xmlDefinition.SelectNodes("//File"); _projectFiles = new ArrayList(fileNodes.Count); foreach (XmlElement fileElem in fileNodes) { string parentName = Name; // determine name of parent if (fileElem.ParentNode != null && fileElem.ParentNode.Name == "Filter") { XmlNode filterName = fileElem.ParentNode.Attributes.GetNamedItem("Name"); if (filterName != null) { parentName = filterName.Value; } } string relPath = fileElem.GetAttribute("RelativePath"); Hashtable htFileConfigurations = null; XmlNodeList fileConfigList = fileElem.GetElementsByTagName("FileConfiguration"); if (fileConfigList.Count > 0) { htFileConfigurations = CollectionsUtil.CreateCaseInsensitiveHashtable(fileConfigList.Count); foreach (XmlElement fileConfigElem in fileConfigList) { Configuration fileConfig = Configuration.Parse ( fileConfigElem.GetAttribute("Name")); VcProjectConfiguration projectConfig = (VcProjectConfiguration) ProjectConfigurations[fileConfig]; htFileConfigurations[projectConfig.Name] = new VcFileConfiguration( relPath, parentName, fileConfigElem, projectConfig, outputDir); } } // TODO: refactor this together with the Build methods // we'll always create a file configuration for IDL and res // files as macro's in the configuration properties for these // files will always need to be expanded on the file level string ext = Path.GetExtension(relPath).ToLower(CultureInfo.InvariantCulture); switch (ext) { case ".idl": case ".odl": case ".rc": // ensure there's a file configuration for each project // configuration foreach (VcProjectConfiguration projectConfig in ProjectConfigurations.Values) { // if file configuration for project config existed // in project file, then skip this project config if (htFileConfigurations != null && htFileConfigurations.ContainsKey(projectConfig.Name)) { continue; } // lazy initialize hashtable if (htFileConfigurations == null) { htFileConfigurations = CollectionsUtil.CreateCaseInsensitiveHashtable(); } // create the file configuration htFileConfigurations[projectConfig.Name] = new VcFileConfiguration(relPath, parentName, projectConfig, outputDir); } break; } if (htFileConfigurations != null) { _projectFiles.Add(htFileConfigurations); } else { _projectFiles.Add(relPath); } } }
public SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { return new WhidbeySolution(solutionContent, solutionTask, tfc, gacCache, refResolver); }
private 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); // fast-skip setup projects since the project files is not XML-based if (projectExt == ".vdproj") { return(null); } // 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); } IProjectBuildProvider provider = FindProvider(projectExt, xmlDefinition); if (provider != null) { return(provider.GetInstance(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); }
/// <summary> /// Initializes a new instance of the <see cref="ManagedProjectBase"/> class. /// </summary> /// <param name="solution">The solution.</param> /// <param name="projectPath">The project path.</param> /// <param name="xmlDefinition">The XML definition.</param> /// <param name="solutionTask">The solution task.</param> /// <param name="tfc">The TFC.</param> /// <param name="gacCache">The gac cache.</param> /// <param name="refResolver">The reference resolver.</param> /// <param name="outputDir">The output dir.</param> /// <exception cref="System.ArgumentNullException"> /// projectPath /// or /// xmlDefinition /// </exception> protected ManagedProjectBase(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { if (projectPath == null) { throw new ArgumentNullException("projectPath"); } if (xmlDefinition == null) { throw new ArgumentNullException("xmlDefinition"); } _references = new ArrayList(); _neutralResources = new ArrayList(); _localizedResources = new ArrayList(); _sourceFiles = CollectionsUtil.CreateCaseInsensitiveHashtable(); _projectPath = projectPath; _projectLocation = DetermineProjectLocation(xmlDefinition); if (!IsWebProject) { _projectDirectory = new FileInfo(projectPath).Directory; } else { string projectDirectory = projectPath.Replace(":", "_"); projectDirectory = projectDirectory.Replace("/", "_"); projectDirectory = projectDirectory.Replace("\\", "_"); _projectDirectory = new DirectoryInfo(FileUtils.CombinePaths( TemporaryFiles.BasePath, projectDirectory)); // ensure project directory exists if (!_projectDirectory.Exists) { _projectDirectory.Create(); _projectDirectory.Refresh(); } _webProjectBaseUrl = projectPath.Substring(0, projectPath.LastIndexOf("/")); } _projectSettings = new ProjectSettings(xmlDefinition, (XmlElement) xmlDefinition.SelectSingleNode("//Build/Settings"), this); XmlNodeList nlConfigurations = xmlDefinition.SelectNodes("//Config"); foreach (XmlElement elemConfig in nlConfigurations) { ConfigurationSettings cs = new ConfigurationSettings(this, elemConfig, OutputDir); ProjectConfigurations[Configuration.Parse(cs.Name)] = cs; } XmlNodeList nlReferences = xmlDefinition.SelectNodes("//References/Reference"); foreach (XmlElement elemReference in nlReferences) { ReferenceBase reference = CreateReference(solution, elemReference); _references.Add(reference); } XmlNodeList nlFiles = xmlDefinition.SelectNodes("//Files/Include/File"); foreach (XmlElement elemFile in nlFiles) { string buildAction = StringUtils.ConvertEmptyToNull(elemFile.GetAttribute("BuildAction")); string sourceFile; if (!String.IsNullOrEmpty(elemFile.GetAttribute("Link"))) { sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths( ProjectDirectory.FullName, elemFile.GetAttribute("Link"))); } else { sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths( ProjectDirectory.FullName, elemFile.GetAttribute("RelPath"))); } if (IsWebProject) { WebDavClient wdc = new WebDavClient(new Uri(_webProjectBaseUrl)); wdc.DownloadFile(sourceFile, elemFile.Attributes["RelPath"].Value); switch (buildAction) { case "Compile": _sourceFiles[sourceFile] = null; break; case "EmbeddedResource": RegisterEmbeddedResource(sourceFile, elemFile); break; case null: if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) { _sourceFiles[sourceFile] = null; } break; } } else { switch (buildAction) { case "Compile": _sourceFiles[sourceFile] = null; break; case "EmbeddedResource": RegisterEmbeddedResource(sourceFile, elemFile); break; case null: if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) { _sourceFiles[sourceFile] = null; } break; } // check if file is "App.config" (using case-insensitive comparison) if (string.Compare("App.config", elemFile.GetAttribute("RelPath"), true, CultureInfo.InvariantCulture) == 0) { // App.config is only an output file for executable projects if (ProjectSettings.OutputType == ManagedOutputType.Executable || ProjectSettings.OutputType == ManagedOutputType.WindowsExecutable) { ExtraOutputFiles[sourceFile] = ProjectSettings.OutputFileName + ".config"; } } } } }
protected ProjectReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent) : base(referencesResolver, parent) { }
public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) { return(new VBProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)); }
public ProjectBase LoadProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string path) { // check if this a new project if (!_cachedProjects.Contains(path)) { ProjectBase project = CreateProject(solution, solutionTask, tfc, gacCache, referencesResolver, outputDir, path); _cachedProjects[path] = project; } return (ProjectBase) _cachedProjects[path]; }
public ProjectBase LoadProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string path) { // check if this a new project if (!_cachedProjects.Contains(path)) { ProjectBase project = CreateProject(solution, solutionTask, tfc, gacCache, referencesResolver, outputDir, path); _cachedProjects[path] = project; } return((ProjectBase)_cachedProjects[path]); }
public GenericSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) { }
/// <summary> /// Initializes a new instance of the <see cref="WrapperReferenceBase"/> class. /// </summary> /// <param name="xmlDefinition">The XML definition.</param> /// <param name="referencesResolver">The references resolver.</param> /// <param name="parent">The parent.</param> /// <param name="gacCache">The gac cache.</param> protected WrapperReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) { }
public static SolutionBase LoadSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { if (solutionTask.SolutionFile == null) { return new GenericSolution(solutionTask, tfc, gacCache, refResolver); } else { // determine the solution file format version // will hold the content of the solution file string fileContents; using (StreamReader sr = new StreamReader(solutionTask.SolutionFile.FullName, Encoding.Default, true)) { fileContents = sr.ReadToEnd(); } Regex reSolutionFormat = new Regex(@"^\s*Microsoft Visual Studio Solution File, Format Version\s+(?<formatVersion>[0-9]+\.[0-9]+?)", RegexOptions.Singleline); MatchCollection matches = reSolutionFormat.Matches(fileContents); if (matches.Count == 0) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "The format version of solution file '{0}' could not" + " be determined.", solutionTask.SolutionFile.FullName), Location.UnknownLocation); } else { string formatVersion = matches[0].Groups["formatVersion"].Value; switch (formatVersion) { case "7.0": return new Rainier.Solution(fileContents, solutionTask, tfc, gacCache, refResolver); case "8.0": return new Everett.Solution(fileContents, solutionTask, tfc, gacCache, refResolver); case "9.0": throw new BuildException("Microsoft Visual Studio.NET" + " 2005 solutions are not supported.", Location.UnknownLocation); default: throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Visual Studio Solution format version '{0}' is" + " not supported.", formatVersion), Location.UnknownLocation); } } } }
protected ReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent) { _referencesResolver = referencesResolver; _parent = parent; }
public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) { return new MSBuildProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir); }