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); }
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 Resource(ManagedProjectBase project, FileInfo resourceSourceFile, string resourceSourceFileRelativePath, string dependentFile, SolutionTask solutionTask, GacCache gacCache) { _project = project; _resourceSourceFile = resourceSourceFile; _resourceSourceFileRelativePath = resourceSourceFileRelativePath; _dependentFile = dependentFile; _solutionTask = solutionTask; _culture = CompilerBase.GetResourceCulture(resourceSourceFile.FullName, dependentFile); }
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); } }
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); }
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 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); } }
public RosarioSolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionContent, solutionTask, tfc, gacCache, refResolver) { }
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); } if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath)) { RecursiveLoadTemplateProject(fullProjectPath); } else { // add project path to collection ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath)); } // set-up project dependencies Regex reDependencies = new Regex(@"^\s+" + guid + @"\.[0-9]+ = (?<dep>\{\S*\}?)\s*$", RegexOptions.Multiline); MatchCollection dependencyMatches = reDependencies.Matches(solutionContent); 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+" + 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); }
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 GenericSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) { }
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 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) { }
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 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 SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) { return new WhidbeySolution(solutionContent, solutionTask, tfc, gacCache, refResolver); }
/// <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 ProjectBase LoadProject(SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir, string projectFile) { if (ProjectStack.Contains(projectFile)) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Circular reference to \"{0}\" detected in project \"{1}\".", Path.GetFileNameWithoutExtension(projectFile), Parent.Name), Location.UnknownLocation); } try { ProjectStack.Push(projectFile); Log(Level.Verbose, "Loading referenced project '{0}'.", projectFile); return SolutionTask.ProjectFactory.LoadProject(solution, SolutionTask, tfc, gacCache, ReferencesResolver, outputDir, projectFile); } finally { ProjectStack.Pop(); } }
/// <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); } } }
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); }
protected override void ExecuteTask() { Log(Level.Info, "Starting solution build."); if (SolutionFile != null) { if (!SolutionFile.Exists) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Couldn't find solution file '{0}'.", SolutionFile.FullName), Location); } } if (Projects.FileNames.Count > 0) { Log(Level.Verbose, "Included projects:" ); foreach (string projectFile in Projects.FileNames) { Log(Level.Verbose, " - " + projectFile); } } if (ReferenceProjects.FileNames.Count > 0) { Log(Level.Verbose, "Reference projects:"); foreach (string projectFile in ReferenceProjects.FileNames) { Log(Level.Verbose, " - " + projectFile); } } string basePath = null; try { using (TempFileCollection tfc = new TempFileCollection()) { // store the temp dir so we can clean it up later basePath = tfc.BasePath; // ensure temp directory exists if (!LongPathDirectory.Exists(tfc.BasePath)) { LongPathDirectory.Create(tfc.BasePath); } // create temporary domain PermissionSet tempDomainPermSet = new PermissionSet(PermissionState.Unrestricted); AppDomain temporaryDomain = AppDomain.CreateDomain("temporaryDomain", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation, tempDomainPermSet); try { ReferencesResolver referencesResolver = ((ReferencesResolver) temporaryDomain.CreateInstanceFrom(Assembly.GetExecutingAssembly().Location, typeof(ReferencesResolver).FullName).Unwrap()); using (GacCache gacCache = new GacCache(this.Project)) { SolutionBase sln = SolutionFactory.LoadSolution(this, tfc, gacCache, referencesResolver); if (!sln.Compile(_configuration)) { throw new BuildException("Project build failed.", Location); } } } finally { // unload temporary domain AppDomain.Unload(temporaryDomain); } } } finally { if (basePath != null && LongPathDirectory.Exists(basePath)) { Log(Level.Debug, "Cleaning up temp folder '{0}'.", basePath); // delete temporary directory and all files in it DeleteTask deleteTask = new DeleteTask(); deleteTask.Project = Project; deleteTask.Parent = this; deleteTask.InitializeTaskConfiguration(); deleteTask.Directory = new DirectoryInfo(basePath); deleteTask.Threshold = Level.None; // no output in build log deleteTask.Execute(); } } }
/// <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) { }